In the documentation for the CPAN module DateTime I found the following:
Once you set the formatter, the
overloaded stringification method will
use the formatter.
It seems there is some Perl concept called “stringification” that I somehow missed. Googling has not clarified it much. What is this “stringification”?
“stringification” happens any time that perl needs to convert a value into a string. This could be to print it, to concatenate it with another string, to apply a regex to it, or to use any of the other string manipulation functions in Perl.
Normally, objects will stringify to something like
Some::Package=HASH(0x467fbc)where perl is printing the package it is blessed into, and the type and address of the reference.Some modules choose to override this behavior. In Perl, this is done with the overload pragma. Here is an example of an object that when stringified produces its sum:
There are several other ifications that
overloadlets you define:Objects can even behave as different types: