For those unaware of Perl's autobox
, it is a module that gives you methods on built in primitives, and lets you even override them.
# primitives
'a string'->toupper();
10->to(1); # returns [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
# Arrays, array refs
[qw(A B C D E)]->for_each( sub { ... } );
@array->length()
# Hashes, hash refs
{ key => 'value', key2 => 'value2' }->values()
%hash->keys()
# Even specify your own base class...
use autobox SCALAR => 'Foo';
It overall makes methods on built in types feel more like objects, simplifying some tasks and making others seem more obvious.
However...
the autobox
docs say that there's performance penalties, some more than simply calling the method on the object, much more than the standard syntax. And then, there's a few caveats about its use in eval
s (specifically, string evals) that might, in some circumstances, cause issues. It also looks like it doesn't come standard with many Perl distros.
Is it ever really worth it to use autobox?