1 package MooseX::AttributeHelpers::MethodProvider::Collection::Array;
2 use MooseX::AttributeHelpers::MethodProvider;
3 use MooseX::AttributeHelpers::MethodProvider::Util qw(type_check);
4 use MooseX::AttributeHelpers::MethodProvider::Collection::List;
7 our $AUTHORITY = 'cpan:STEVAN';
9 add_method_provider 'Collection::Array' => (
11 consumes => { 'Collection::List' => ':all' },
14 my ($attr, $reader, $writer) = @_;
15 return type_check($attr, sub {@_[1,$#_]}, sub {
17 CORE::push(@{ $reader->($self) }, @_);
22 my ($attr, $reader, $writer) = @_;
23 return sub { CORE::pop(@{ $reader->($_[0]) }) };
27 my ($attr, $reader, $writer) = @_;
28 return type_check($attr, sub {@_[1,$#_]}, sub {
30 CORE::unshift(@{ $reader->($self) }, @_);
35 my ($attr, $reader, $writer) = @_;
37 CORE::shift(@{ $reader->($_[0]) });
42 my ($attr, $reader, $writer) = @_;
45 return @{ $reader->($self) }[@_];
50 my ($attr, $reader, $writer) = @_;
51 return type_check($attr, sub {@_[2,$#_]}, sub {
52 my ($self, $index, @values) = @_;
53 my @indexes = (ref $index eq 'ARRAY' ? @$index : ($index));
54 @{ $reader->($self) }[@indexes] = @values;
59 my ($attr, $reader, $writer) = @_;
60 return sub { @{ $reader->($_[0]) } = () };
64 my ($attr, $reader, $writer) = @_;
66 CORE::splice(@{ $reader->($_[0]) }, $_[1], $_[2] || 1);
71 my ($attr, $reader, $writer) = @_;
72 return type_contraint($attr, sub {@_[2,$#_]}, sub {
73 my ($self, $index, @values) = @_;
74 CORE::splice(@{ $reader->($self) }, $index, 0, @values);
88 MooseX::AttributeHelpers::MethodProvider::Collection::Array
92 This module provides the method factories for
93 L<MooseX::AttributeHelpers::Collection::Array>. It also consumes
94 L<MooseX::AttributeHelpers::MethodProvider::Collection::List>, and thus
95 provides all its methods as well.
97 =head1 PROVIDED METHODS
99 This module consumes L<MooseX::AttributeHelpers::MethodProvider::List>, and so
100 provides all of its methods as well. All methods work when multiple indexes
101 are supplied - special cases are noted.
105 =item B<get(@indexes)>
107 Behaves just like indexing an arrayref: returns the items indexed by the
108 supplied arguments (i.e. C<$self->get_my_stuff(1,2,3)> means
111 =item B<set($index, $value)>
113 =item B<set([$indexes], @values)>
115 This is just like assigning to an arrayref, except that an arrayref lets you
116 assign multiple indexes at once with no strange syntax. You can do that with
117 this set as well, but the first argument should be an arrayref of the keys you
118 want to assign to. (e.g. C<$self->set_aref([1,2,3], qw(foo bar baz))>)
132 =item B<unshift($item)>
138 Deletes all items from the array.
140 =item B<delete($index, $length)>
142 Deletes $length (default: 1) items from the array at $index.
144 =item B<insert($index, @items)>
146 Inserts @items into list at $index.
152 All complex software has bugs lurking in it, and this module is no
153 exception. If you find a bug please either email me, or add the bug
158 Stevan Little E<lt>stevan@iinteractive.comE<gt>
160 =head1 COPYRIGHT AND LICENSE
162 Copyright 2007-2008 by Infinity Interactive, Inc.
164 L<http://www.iinteractive.com>
166 This library is free software; you can redistribute it and/or modify
167 it under the same terms as Perl itself.