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 (find_type_constraint($options->{isa})->is_a_type_of('ArrayRef'))
62 || confess "The type constraint for a Array ($options->{isa}) must be a subtype of ArrayRef";
66 no Moose::Util::TypeConstraints;;
68 # register the alias ...
69 package Moose::Meta::Attribute::Custom::Collection::Array;
70 sub register_implementation { 'MooseX::AttributeHelpers::Collection::Array' }
87 metaclass => 'Collection',
90 default => sub { [] },
92 'push' => 'add_options',
93 'pop' => 'remove_last_option',
103 All complex software has bugs lurking in it, and this module is no
104 exception. If you find a bug please either email me, or add the bug
109 Stevan Little E<lt>stevan@iinteractive.comE<gt>
111 =head1 COPYRIGHT AND LICENSE
113 Copyright 2007 by Infinity Interactive, Inc.
115 L<http://www.iinteractive.com>
117 This library is free software; you can redistribute it and/or modify
118 it under the same terms as Perl itself.