1 package MooseX::AttributeHelpers::MethodProvider::Array;
3 use MooseX::AttributeHelpers::Collection::TypeCheck;
6 our $AUTHORITY = 'cpan:STEVAN';
8 with 'MooseX::AttributeHelpers::MethodProvider::List';
11 my ($attr, $reader, $writer) = @_;
12 return type_check($attr, sub {@_[1,$#_]}, sub {
14 CORE::push(@{ $reader->($self) }, @_);
19 my ($attr, $reader, $writer) = @_;
20 return sub { CORE::pop(@{ $reader->($_[0]) }) };
23 sub unshift : method {
24 my ($attr, $reader, $writer) = @_;
25 return type_check($attr, sub {@_[1,$#_]}, sub {
27 CORE::unshift(@{ $reader->($self) }, @_);
32 my ($attr, $reader, $writer) = @_;
34 CORE::shift(@{ $reader->($_[0]) });
39 my ($attr, $reader, $writer) = @_;
42 return @{ $reader->($self) }[@_];
47 my ($attr, $reader, $writer) = @_;
48 return type_check($attr, sub {@_[2,$#_]}, sub {
49 my ($self, $index, @values) = @_;
50 my @indexes = (ref $index eq 'ARRAY' ? @$index : ($index));
51 @{ $reader->($self) }[@indexes] = @values;
56 my ($attr, $reader, $writer) = @_;
57 return sub { @{ $reader->($_[0]) } = () };
61 my ($attr, $reader, $writer) = @_;
63 CORE::splice(@{ $reader->($_[0]) }, $_[1], $_[2] || 1);
68 my ($attr, $reader, $writer) = @_;
69 return type_contraint($attr, sub {@_[2,$#_]}, sub {
70 my ($self, $index, @values) = @_;
71 CORE::splice(@{ $reader->($self) }, $index, 0, @values);
83 MooseX::AttributeHelpers::MethodProvider::Array
87 This is a role which provides the method generators for
88 L<MooseX::AttributeHelpers::Collection::Array>.
90 =head1 PROVIDED METHODS
92 This module consumes L<MooseX::AttributeHelpers::MethodProvider::List>, and so
93 provides all of its methods as well. All methods work when multiple indexes
94 are supplied - special cases are noted.
98 =item B<get(@indexes)>
100 Behaves just like indexing an arrayref: returns the items indexed by the
101 supplied arguments (i.e. C<$self->get_my_stuff(1,2,3)> means
104 =item B<set($index, $value)>
106 =item B<set([$indexes], @values)>
108 This is just like assigning to an arrayref, except that an arrayref lets you
109 assign multiple indexes at once with no strange syntax. You can do that with
110 this set as well, but the first argument should be an arrayref of the keys you
111 want to assign to. (e.g. C<$self->set_aref([1,2,3], qw(foo bar baz))>)
125 =item B<unshift($item)>
131 Deletes all items from the array.
133 =item B<delete($index, $length)>
135 Deletes $length (default: 1) items from the array at $index.
137 =item B<insert($index, @items)>
139 Inserts @items into list at $index.
145 All complex software has bugs lurking in it, and this module is no
146 exception. If you find a bug please either email me, or add the bug
151 Stevan Little E<lt>stevan@iinteractive.comE<gt>
153 =head1 COPYRIGHT AND LICENSE
155 Copyright 2007-2008 by Infinity Interactive, Inc.
157 L<http://www.iinteractive.com>
159 This library is free software; you can redistribute it and/or modify
160 it under the same terms as Perl itself.