More Badger::Class Hooks
use Badger::Class overload => { '""' => \&my_text_method, bool => sub { 1 }, fallback => 1, }; use Badger::Class as_text => \&my_text_method, is_true => 1;
Thus Spake Andy:
There's an overload
hook which works just like use overload
. However,
every time I use it I have to look up the right magical incantation (all
three parts) required to make my objects with auto-stringification methods
work correctly. So we have the as_text
and is_true
shortcuts. The
boolean "always true" fallback is so that an object containing an empty
string or 0
value still yields a true value in boolean comparisons.
Otherwise my $object = make_me_a_texty_object("0") die 'Oh crap!'
will crap on you (which may be what you want).