1NAME
2    MooseX::ArrayRef - blessed arrayrefs with Moose
3
4SYNOPSIS
5      {
6        package Local::Person;
7        use Moose;
8        has name => (
9          is    => 'ro',
10          isa   => 'Str',
11        );
12        __PACKAGE__->meta->make_immutable;
13      }
14
15      {
16        package Local::Marriage;
17        use MooseX::ArrayRef;
18        has husband => (
19          is    => 'ro',
20          isa   => 'Local::Person',
21        );
22        has wife => (
23          is    => 'ro',
24          isa   => 'Local::Person',
25        );
26        __PACKAGE__->meta->make_immutable;
27      }
28
29      my $marriage = Local::Marriage->new(
30        wife      => Local::Person->new(name => 'Alex'),
31        husband   => Local::Person->new(name => 'Sam'),
32      );
33
34      use Data::Dumper;
35      use Scalar::Util qw(reftype);
36      print reftype($marriage), "\n";   # 'ARRAY'
37      print Dumper($marriage);
38
39DESCRIPTION
40    Objects implemented with arrayrefs rather than hashrefs are often faster
41    than those implemented with hashrefs. Moose's default object
42    implementation is hashref based. Can we go faster?
43
44    Simply `use MooseX::ArrayRef` instead of `use Moose`, but note the
45    limitations in the section below.
46
47    The current implementation is mostly a proof of concept, but it does
48    mostly seem to work.
49
50BUGS AND LIMITATIONS
51  Limitations on Speed
52    The accessors for mutable classes not significantly faster than Moose's
53    traditional hashref-based objects. For immutable classes, the speed up is
54    bigger
55
56                   Rate  HashRef_M ArrayRef_M  HashRef_I ArrayRef_I
57      HashRef_M  1016/s         --        -1%       -48%       -55%
58      ArrayRef_M 1031/s         1%         --       -47%       -54%
59      HashRef_I  1953/s        92%        89%         --       -13%
60      ArrayRef_I 2257/s       122%       119%        16%         --
61
62  Limitations on Mutability
63    Things will probably break if you try to modify classes, add roles, etc
64    "on the fly". Make your classes immutable before instantiating even a
65    single object.
66
67  Limitations on Inheritance
68    Inheritance isn't easy to implement with arrayrefs. The current
69    implementation suffers from the following limitations:
70
71    *   Single inheritance only.
72
73        You cannot extend multiple parent classes.
74
75    *   Inherit from other MooseX::ArrayRef classes only.
76
77        A MooseX::ArrayRef class cannot extend a non-MooseX::ArrayRef class.
78        Even non-Moose classes which are implemented using arrayrefs. (Of
79        course, all Moose classes inherit from Moose::Object too, which is
80        just fine.)
81
82    Note that delegation (via Moose's `handles`) is often a good alternative
83    to inheritance.
84
85  Issue Tracker
86    Please report any bugs to
87    <http://rt.cpan.org/Dist/Display.html?Queue=MooseX-ArrayRef>.
88
89SEE ALSO
90    Moose, MooseX::GlobRef, MooseX::InsideOut.
91
92AUTHOR
93    Toby Inkster <tobyink@cpan.org>.
94
95COPYRIGHT AND LICENCE
96    This software is copyright (c) 2012 by Toby Inkster.
97
98    This is free software; you can redistribute it and/or modify it under the
99    same terms as the Perl 5 programming language system itself.
100
101DISCLAIMER OF WARRANTIES
102    THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
103    WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
104    MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
105
106