List::...Autobox(3pm)
π List::...Autobox(3pm) π
okay bestie, so this is List::Objects::WithUtils::Autobox from the User Contributed Perl Documentation, and it's genuinely one of those little modules that changes your whole Perl vibe. let's get into it π
β¨ NAME β¨
List::Objects::WithUtils::Autobox β Native data types WithUtils. yes that's the whole name. iconic. no notes. π
πΈ SYNOPSIS πΈ
look at this. LOOK at it. no imports, no blessing, no ceremony β just vibes:
use List::Objects::WithUtils 'autobox';
my @upper = [ qw/foo bar baz/ ]->map(sub { uc })->all;
my @sorted_keys = { foo => 'bar', baz => 'quux' }->keys->sort->all;
# See List::Objects::WithUtils::Role::Array
# and List::Objects::WithUtils::Role::Hash
like, [ qw/foo bar baz/ ]->map(sub { uc })->all?? a plain arrayref just knowing how to map? that's main character energy fr fr πβ¨
π¦ DESCRIPTION π¦
so here's the tea: this module is a subclass of autobox that hands List::Objects::WithUtils methods to your native ARRAY and HASH types. translation? you can treat native Perl list references like they were straight-up List::Objects::WithUtils::Array or List::Objects::WithUtils::Hash instances. no cap. π₯
and just like autobox itself, the effect is lexical in scope β so you can turn it off whenever you want:
use List::Objects::WithUtils::Autobox;
my $foo = [3,2,1]->sort;
no List::Objects::WithUtils::Autobox;
[3,2,1]->sort; # dies
see that last line? # dies. the magic is scoped, and once you no it, it's gone gone. π
π CAVEATS π
okay so the important stuff, don't skip this part bestie:
- you can't call
newon autoboxed refs β but honestly that would be a silly thing to do anyway. and if you're really determined,[]->copyhas the exact same effect. you're welcome. π - also worth noting (ngl this one matters): methods that create new lists will return blessed objects, not native data types. why is that good? because it lets you keep passing your result collections around to other pieces of Perl that wouldn't otherwise know how to call the autoboxed methods. it's giving β¨compatibilityβ¨. (some methods do return the object they were originally operating on β in which case the original reference is indeed returned, as expected. no surprise plot twists.) π
π AUTHOR π
Jon Portnoy <avenj@cobaltirc.org>
and that's the whole page, bestie! π«Ά this one shipped with perl v5.38.2 and is dated 2024-03-07 β so go forth and autobox responsibly. mwah ππΈπ¦
π¦ where this page comes from
- debian trixie: liblist-objects-withutils-perl 2.028003-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: liblist-objects-withutils-perl 2.028003-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: liblist-objects-withutils-perl 2.028003-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms