1 package MooseX::AttributeHelpers::MethodProvider::Array;
5 our $AUTHORITY = 'cpan:STEVAN';
7 with 'MooseX::AttributeHelpers::MethodProvider::List';
10 my ($attr, $reader, $writer) = @_;
12 if ($attr->has_type_constraint && $attr->type_constraint->isa('Moose::Meta::TypeConstraint::Parameterized')) {
13 my $container_type_constraint = $attr->type_constraint->type_parameter;
15 my $instance = CORE::shift;
16 $container_type_constraint->check($_)
17 || confess "Value " . ($_||'undef') . " did not pass container type constraint"
19 CORE::push @{$reader->($instance)} => @_;
24 my $instance = CORE::shift;
25 CORE::push @{$reader->($instance)} => @_;
31 my ($attr, $reader, $writer) = @_;
33 CORE::pop @{$reader->($_[0])}
37 sub unshift : method {
38 my ($attr, $reader, $writer) = @_;
39 if ($attr->has_type_constraint && $attr->type_constraint->isa('Moose::Meta::TypeConstraint::Parameterized')) {
40 my $container_type_constraint = $attr->type_constraint->type_parameter;
42 my $instance = CORE::shift;
43 $container_type_constraint->check($_)
44 || confess "Value " . ($_||'undef') . " did not pass container type constraint"
46 CORE::unshift @{$reader->($instance)} => @_;
51 my $instance = CORE::shift;
52 CORE::unshift @{$reader->($instance)} => @_;
58 my ($attr, $reader, $writer) = @_;
60 CORE::shift @{$reader->($_[0])}
65 my ($attr, $reader, $writer) = @_;
67 $reader->($_[0])->[$_[1]]
72 my ($attr, $reader, $writer) = @_;
73 if ($attr->has_type_constraint && $attr->type_constraint->isa('Moose::Meta::TypeConstraint::Parameterized')) {
74 my $container_type_constraint = $attr->type_constraint->type_parameter;
76 ($container_type_constraint->check($_[2]))
77 || confess "Value " . ($_[2]||'undef') . " did not pass container type constraint";
78 $reader->($_[0])->[$_[1]] = $_[2]
83 $reader->($_[0])->[$_[1]] = $_[2]
89 my ($attr, $reader, $writer) = @_;
91 @{$reader->($_[0])} = ()
96 my ($attr, $reader, $writer) = @_;
98 CORE::splice @{$reader->($_[0])}, $_[1], 1;
102 sub insert : method {
103 my ($attr, $reader, $writer) = @_;
104 if ($attr->has_type_constraint && $attr->type_constraint->isa('Moose::Meta::TypeConstraint::Parameterized')) {
105 my $container_type_constraint = $attr->type_constraint->type_parameter;
107 ($container_type_constraint->check($_[2]))
108 || confess "Value " . ($_[2]||'undef') . " did not pass container type constraint";
109 CORE::splice @{$reader->($_[0])}, $_[1], 0, $_[2];
114 CORE::splice @{$reader->($_[0])}, $_[1], 0, $_[2];
119 sub splice : method {
120 my ($attr, $reader, $writer) = @_;
121 if ($attr->has_type_constraint && $attr->type_constraint->isa('Moose::Meta::TypeConstraint::Parameterized')) {
122 my $container_type_constraint = $attr->type_constraint->type_parameter;
124 my ( $self, $i, $j, @elems ) = @_;
125 ($container_type_constraint->check($_))
126 || confess "Value " . (defined($_) ? $_ : 'undef') . " did not pass container type constraint" for @elems;
127 CORE::splice @{$self->$reader()}, $i, $j, @elems;
132 my ( $self, $i, $j, @elems ) = @_;
133 CORE::splice @{$self->$reader()}, $i, $j, @elems;
146 MooseX::AttributeHelpers::MethodProvider::Array
150 This is a role which provides the method generators for
151 L<MooseX::AttributeHelpers::Collection::Array>.
161 =head1 PROVIDED METHODS
163 This module also consumes the B<List> method providers, to
164 see those provied methods, refer to that documentation.
192 All complex software has bugs lurking in it, and this module is no
193 exception. If you find a bug please either email me, or add the bug
198 Stevan Little E<lt>stevan@iinteractive.comE<gt>
200 =head1 COPYRIGHT AND LICENSE
202 Copyright 2007-2008 by Infinity Interactive, Inc.
204 L<http://www.iinteractive.com>
206 This library is free software; you can redistribute it and/or modify
207 it under the same terms as Perl itself.