1 package MooseX::AttributeHelpers::MethodProvider::Array;
4 our $VERSION = '0.12_01';
5 $VERSION = eval $VERSION;
6 our $AUTHORITY = 'cpan:STEVAN';
8 with 'MooseX::AttributeHelpers::MethodProvider::List';
11 my ($attr, $reader, $writer) = @_;
13 if ($attr->has_type_constraint && $attr->type_constraint->isa('Moose::Meta::TypeConstraint::Parameterized')) {
14 my $container_type_constraint = $attr->type_constraint->type_parameter;
16 my $instance = CORE::shift;
17 $container_type_constraint->check($_)
18 || confess "Value " . ($_||'undef') . " did not pass container type constraint"
20 CORE::push @{$reader->($instance)} => @_;
25 my $instance = CORE::shift;
26 CORE::push @{$reader->($instance)} => @_;
32 my ($attr, $reader, $writer) = @_;
34 CORE::pop @{$reader->($_[0])}
38 sub unshift : method {
39 my ($attr, $reader, $writer) = @_;
40 if ($attr->has_type_constraint && $attr->type_constraint->isa('Moose::Meta::TypeConstraint::Parameterized')) {
41 my $container_type_constraint = $attr->type_constraint->type_parameter;
43 my $instance = CORE::shift;
44 $container_type_constraint->check($_)
45 || confess "Value " . ($_||'undef') . " did not pass container type constraint"
47 CORE::unshift @{$reader->($instance)} => @_;
52 my $instance = CORE::shift;
53 CORE::unshift @{$reader->($instance)} => @_;
59 my ($attr, $reader, $writer) = @_;
61 CORE::shift @{$reader->($_[0])}
66 my ($attr, $reader, $writer) = @_;
68 $reader->($_[0])->[$_[1]]
73 my ($attr, $reader, $writer) = @_;
74 if ($attr->has_type_constraint && $attr->type_constraint->isa('Moose::Meta::TypeConstraint::Parameterized')) {
75 my $container_type_constraint = $attr->type_constraint->type_parameter;
77 ($container_type_constraint->check($_[2]))
78 || confess "Value " . ($_[2]||'undef') . " did not pass container type constraint";
79 $reader->($_[0])->[$_[1]] = $_[2]
84 $reader->($_[0])->[$_[1]] = $_[2]
90 my ($attr, $reader, $writer) = @_;
92 @{$reader->($_[0])} = ()
97 my ($attr, $reader, $writer) = @_;
99 CORE::splice @{$reader->($_[0])}, $_[1], 1;
103 sub insert : method {
104 my ($attr, $reader, $writer) = @_;
105 if ($attr->has_type_constraint && $attr->type_constraint->isa('Moose::Meta::TypeConstraint::Parameterized')) {
106 my $container_type_constraint = $attr->type_constraint->type_parameter;
108 ($container_type_constraint->check($_[2]))
109 || confess "Value " . ($_[2]||'undef') . " did not pass container type constraint";
110 CORE::splice @{$reader->($_[0])}, $_[1], 0, $_[2];
115 CORE::splice @{$reader->($_[0])}, $_[1], 0, $_[2];
120 sub splice : method {
121 my ($attr, $reader, $writer) = @_;
122 if ($attr->has_type_constraint && $attr->type_constraint->isa('Moose::Meta::TypeConstraint::Parameterized')) {
123 my $container_type_constraint = $attr->type_constraint->type_parameter;
125 my ( $self, $i, $j, @elems ) = @_;
126 ($container_type_constraint->check($_))
127 || confess "Value " . (defined($_) ? $_ : 'undef') . " did not pass container type constraint" for @elems;
128 CORE::splice @{$self->$reader()}, $i, $j, @elems;
133 my ( $self, $i, $j, @elems ) = @_;
134 CORE::splice @{$self->$reader()}, $i, $j, @elems;
147 MooseX::AttributeHelpers::MethodProvider::Array
151 This is a role which provides the method generators for
152 L<MooseX::AttributeHelpers::Collection::Array>.
162 =head1 PROVIDED METHODS
164 This module also consumes the B<List> method providers, to
165 see those provied methods, refer to that documentation.
193 All complex software has bugs lurking in it, and this module is no
194 exception. If you find a bug please either email me, or add the bug
199 Stevan Little E<lt>stevan@iinteractive.comE<gt>
201 =head1 COPYRIGHT AND LICENSE
203 Copyright 2007-2008 by Infinity Interactive, Inc.
205 L<http://www.iinteractive.com>
207 This library is free software; you can redistribute it and/or modify
208 it under the same terms as Perl itself.