1MooseX::ArrayRef(3)   User Contributed Perl Documentation  MooseX::ArrayRef(3)
2
3
4

NAME

6       MooseX::ArrayRef - blessed arrayrefs with Moose
7

SYNOPSIS

9         {
10           package Local::Person;
11           use Moose;
12           has name => (
13             is    => 'ro',
14             isa   => 'Str',
15           );
16           __PACKAGE__->meta->make_immutable;
17         }
18
19         {
20           package Local::Marriage;
21           use MooseX::ArrayRef;
22           has husband => (
23             is    => 'ro',
24             isa   => 'Local::Person',
25           );
26           has wife => (
27             is    => 'ro',
28             isa   => 'Local::Person',
29           );
30           __PACKAGE__->meta->make_immutable;
31         }
32
33         my $marriage = Local::Marriage->new(
34           wife      => Local::Person->new(name => 'Alex'),
35           husband   => Local::Person->new(name => 'Sam'),
36         );
37
38         use Data::Dumper;
39         use Scalar::Util qw(reftype);
40         print reftype($marriage), "\n";   # 'ARRAY'
41         print Dumper($marriage);
42

DESCRIPTION

44       Objects implemented with arrayrefs rather than hashrefs are often
45       faster than those implemented with hashrefs. Moose's default object
46       implementation is hashref based. Can we go faster?
47
48       Simply "use MooseX::ArrayRef" instead of "use Moose", but note the
49       limitations in the section below.
50
51       The current implementation is mostly a proof of concept, but it does
52       mostly seem to work.
53

BUGS AND LIMITATIONS

55   Limitations on Speed
56       The accessors for mutable classes not significantly faster than Moose's
57       traditional hashref-based objects. For immutable classes, the speed up
58       is bigger
59
60                      Rate  HashRef_M ArrayRef_M  HashRef_I ArrayRef_I
61         HashRef_M  1016/s         --        -1%       -48%       -55%
62         ArrayRef_M 1031/s         1%         --       -47%       -54%
63         HashRef_I  1953/s        92%        89%         --       -13%
64         ArrayRef_I 2257/s       122%       119%        16%         --
65
66   Limitations on Mutability
67       Things will probably break if you try to modify classes, add roles, etc
68       "on the fly". Make your classes immutable before instantiating even a
69       single object.
70
71   Limitations on Inheritance
72       Inheritance isn't easy to implement with arrayrefs. The current
73       implementation suffers from the following limitations:
74
75       •   Single inheritance only.
76
77           You cannot extend multiple parent classes.
78
79       •   Inherit from other MooseX::ArrayRef classes only.
80
81           A MooseX::ArrayRef class cannot extend a non-MooseX::ArrayRef
82           class.  Even non-Moose classes which are implemented using
83           arrayrefs. (Of course, all Moose classes inherit from Moose::Object
84           too, which is just fine.)
85
86       Note that delegation (via Moose's "handles") is often a good
87       alternative to inheritance.
88
89   Issue Tracker
90       Please report any bugs to
91       <http://rt.cpan.org/Dist/Display.html?Queue=MooseX-ArrayRef>.
92

SEE ALSO

94       Moose, MooseX::GlobRef, MooseX::InsideOut.
95

AUTHOR

97       Toby Inkster <tobyink@cpan.org>.
98
100       This software is copyright (c) 2012 by Toby Inkster.
101
102       This is free software; you can redistribute it and/or modify it under
103       the same terms as the Perl 5 programming language system itself.
104

DISCLAIMER OF WARRANTIES

106       THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
107       WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
108       MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
109
110
111
112perl v5.32.1                      2021-01-27               MooseX::ArrayRef(3)
Impressum