MooseX::ArrayRef(3pm)
π NAME π
MooseX::ArrayRef β blessed arrayrefs, but make it Moose. periodt β¨
πΈ SYNOPSIS πΈ
okay bestie, here's the whole vibe:
{
package Local::Person;
use Moose;
has name => (
is => 'ro',
isa => 'Str',
);
__PACKAGE__->meta->make_immutable;
}
{
package Local::Marriage;
use MooseX::ArrayRef;
has husband => (
is => 'ro',
isa => 'Local::Person',
);
has wife => (
is => 'ro',
isa => 'Local::Person',
);
__PACKAGE__->meta->make_immutable;
}
my $marriage = Local::Marriage->new(
wife => Local::Person->new(name => 'Alex'),
husband => Local::Person->new(name => 'Sam'),
);
use Data::Dumper;
use Scalar::Util qw(reftype);
print reftype($marriage), "\n"; # 'ARRAY'
print Dumper($marriage);
likeβ¦ your object is literally an ARRAY now. reftype said so. no cap. π«Ά
β¨ DESCRIPTION β¨
okay so real talk: objects built on arrayrefs instead of hashrefs are often faster than the hashref ones. and Moose's default object implementation? yeah, that's hashref based. so the question is: can we go faster?? π
the answer is basically just "use MooseX::ArrayRef" instead of "use Moose" β but bestie, please read the limitations section below first, i am begging you. π
ngl, the current implementation is mostly a proof of concept. but it does mostly seem to work, and honestly? we're thriving. π
π BUGS AND LIMITATIONS π
π₯ Limitations on Speed
so here's the tea: for mutable classes, the accessors are not significantly faster than Moose's traditional hashref-based objects. like, barely. but for immutable classes, the speed up is bigger. that's the whole point of freezing your classes. π₯
Rate HashRef_M ArrayRef_M HashRef_I ArrayRef_I
HashRef_M 1016/s -- -1% -48% -55%
ArrayRef_M 1031/s 1% -- -47% -54%
HashRef_I 1953/s 92% 89% -- -13%
ArrayRef_I 2257/s 122% 119% 16% --
π Limitations on Mutability
things will probably break if you try to modify classes, add roles, etc. "on the fly". so do yourself a favour and make your classes immutable before instantiating even a single object. one single object. i mean it. π¨
π¦ Limitations on Inheritance
inheritance isn't easy to implement with arrayrefs, and the current implementation suffers from these limitations:
- Single inheritance only.
you cannot extend multiple parent classes. one parent. that's it. that's the rule. π
- Inherit from other MooseX::ArrayRef classes only.
a MooseX::ArrayRef class cannot extend a non-MooseX::ArrayRef class. even non-Moose classes which are implemented using arrayrefs. (of course, all Moose classes inherit from Moose::Object too, which is just fine.) π
pro tip from the source: delegation (via Moose's handles) is often a good alternative to inheritance. slay. π
π Issue Tracker
please report any bugs to <http://rt.cpan.org/Dist/Display.html?Queue=MooseX-ArrayRef>. tell them everything bestie π«Ά
π SEE ALSO π
Moose, MooseX::GlobRef, MooseX::InsideOut. the whole family. iconic lineup honestly. β¨
π AUTHOR π
Toby Inkster <tobyink@cpan.org>. legend behaviour. π
π COPYRIGHT AND LICENCE π
this software is copyright (c) 2012 by Toby Inkster.
this is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. free as in, go off bestie. π¦
β DISCLAIMER OF WARRANTIES β
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
read that again, loudly. no promises, no take-backs. π
and that's the whole page fr fr π this was perl v5.34.0, dated 2022-06-15, and it's the manual page for MooseX::ArrayRef(3pm) β go make your objects immutable and pop off, bestie. πΈβ¨π«Ά
π¦ where this page comes from
- debian bookworm: libmoosex-arrayref-perl 0.005-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libmoosex-arrayref-perl 0.005-2 Β· 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