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. πŸ’œ


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