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