2 package MooseX::AttributeHelpers::Collection::Array;
4 use Moose::Util::TypeConstraints;
7 our $AUTHORITY = 'cpan:STEVAN';
9 extends 'MooseX::AttributeHelpers::Base';
11 has '+method_constructors' => (
18 push @{$attr->get_value($instance)} => @_;
23 return sub { pop @{$attr->get_value($_[0])} };
29 unshift @{$attr->get_value($instance)} => @_;
34 return sub { shift @{$attr->get_value($_[0])} };
38 return sub { $attr->get_value($_[0])->[$_[1]] };
42 return sub { $attr->get_value($_[0])->[$_[1]] = $_[2] };
46 return sub { scalar @{$attr->get_value($_[0])} };
50 return sub { scalar @{$attr->get_value($_[0])} ? 1 : 0 };
56 sub _process_options_for_provides {
57 my ($self, $options) = @_;
58 (exists $options->{isa})
59 || confess "You must define a type with the Array metaclass";
61 my $c = find_type_constraint($options->{isa}) || $options->{isa};
62 ( $c && blessed($c) && $c->is_a_type_of('ArrayRef'))
63 || confess "The type constraint for a Array ($options->{isa}) must be a subtype of ArrayRef";
67 no Moose::Util::TypeConstraints;;
69 # register the alias ...
70 package Moose::Meta::Attribute::Custom::Collection::Array;
71 sub register_implementation { 'MooseX::AttributeHelpers::Collection::Array' }
88 metaclass => 'Collection',
91 default => sub { [] },
93 'push' => 'add_options',
94 'pop' => 'remove_last_option',
104 All complex software has bugs lurking in it, and this module is no
105 exception. If you find a bug please either email me, or add the bug
110 Stevan Little E<lt>stevan@iinteractive.comE<gt>
112 =head1 COPYRIGHT AND LICENSE
114 Copyright 2007 by Infinity Interactive, Inc.
116 L<http://www.iinteractive.com>
118 This library is free software; you can redistribute it and/or modify
119 it under the same terms as Perl itself.