2 package MooseX::AttributeHelpers::Collection::Array;
4 use Moose::Util::TypeConstraints;
7 our $AUTHORITY = 'cpan:STEVAN';
9 extends 'MooseX::AttributeHelpers::Collection';
11 sub helper_type { 'ArrayRef' }
13 has '+method_constructors' => (
18 if ($attr->has_container_type) {
19 my $container_type_constraint = $attr->container_type_constraint;
22 $container_type_constraint->check($_)
23 || confess "Value " . ($_||'undef') . " did not pass container type constraint"
25 push @{$attr->get_value($instance)} => @_;
31 push @{$attr->get_value($instance)} => @_;
37 return sub { pop @{$attr->get_value($_[0])} };
41 if ($attr->has_container_type) {
42 my $container_type_constraint = $attr->container_type_constraint;
45 $container_type_constraint->check($_)
46 || confess "Value " . ($_||'undef') . " did not pass container type constraint"
48 unshift @{$attr->get_value($instance)} => @_;
54 unshift @{$attr->get_value($instance)} => @_;
60 return sub { shift @{$attr->get_value($_[0])} };
64 return sub { $attr->get_value($_[0])->[$_[1]] };
68 if ($attr->has_container_type) {
69 my $container_type_constraint = $attr->container_type_constraint;
71 ($container_type_constraint->check($_[2]))
72 || confess "Value " . ($_[2]||'undef') . " did not pass container type constraint";
73 $attr->get_value($_[0])->[$_[1]] = $_[2]
77 return sub { $attr->get_value($_[0])->[$_[1]] = $_[2] };
82 return sub { scalar @{$attr->get_value($_[0])} };
86 return sub { scalar @{$attr->get_value($_[0])} ? 1 : 0 };
94 # register the alias ...
95 package Moose::Meta::Attribute::Custom::Collection::Array;
96 sub register_implementation { 'MooseX::AttributeHelpers::Collection::Array' }
113 metaclass => 'Collection',
115 isa => 'ArrayRef[Int]',
116 default => sub { [] },
118 'push' => 'add_options',
119 'pop' => 'remove_last_option',
129 All complex software has bugs lurking in it, and this module is no
130 exception. If you find a bug please either email me, or add the bug
135 Stevan Little E<lt>stevan@iinteractive.comE<gt>
137 =head1 COPYRIGHT AND LICENSE
139 Copyright 2007 by Infinity Interactive, Inc.
141 L<http://www.iinteractive.com>
143 This library is free software; you can redistribute it and/or modify
144 it under the same terms as Perl itself.