X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMooseX%2FAttributeHelpers%2FCollection%2FArray.pm;h=ec8c750f4ba06a0d31ba9a30643e5ec26ad811a1;hb=457dc4fbcdbffb359481532bdb4d4f17d0fd20be;hp=043b035618d07e4b2664daf9baf2356e1c148c08;hpb=d26633fcee47dfa1bc7349c67f7a586febf50f7a;p=gitmo%2FMooseX-AttributeHelpers.git diff --git a/lib/MooseX/AttributeHelpers/Collection/Array.pm b/lib/MooseX/AttributeHelpers/Collection/Array.pm index 043b035..ec8c750 100644 --- a/lib/MooseX/AttributeHelpers/Collection/Array.pm +++ b/lib/MooseX/AttributeHelpers/Collection/Array.pm @@ -5,61 +5,15 @@ use Moose; our $VERSION = '0.01'; our $AUTHORITY = 'cpan:STEVAN'; -extends 'MooseX::AttributeHelpers::Base'; - -has '+method_constructors' => ( - default => sub { - return +{ - 'push' => sub { - my $attr = shift; - return sub { - my $instance = shift; - push @{$attr->get_value($instance)} => @_; - }; - }, - 'pop' => sub { - my $attr = shift; - return sub { pop @{$attr->get_value($_[0])} }; - }, - 'unshift' => sub { - my $attr = shift; - return sub { - my $instance = shift; - unshift @{$attr->get_value($instance)} => @_; - }; - }, - 'shift' => sub { - my $attr = shift; - return sub { shift @{$attr->get_value($_[0])} }; - }, - 'get' => sub { - my $attr = shift; - return sub { $attr->get_value($_[0])->[$_[1]] }; - }, - 'set' => sub { - my $attr = shift; - return sub { $attr->get_value($_[0])->[$_[1]] = $_[2] }; - }, - 'count' => sub { - my $attr = shift; - return sub { scalar @{$attr->get_value($_[0])} }; - }, - 'empty' => sub { - my $attr = shift; - return sub { scalar @{$attr->get_value($_[0])} ? 1 : 0 }; - } - } - } +use MooseX::AttributeHelpers::MethodProvider::Array; + +extends 'MooseX::AttributeHelpers::Collection'; + +has '+method_provider' => ( + default => 'MooseX::AttributeHelpers::MethodProvider::Array' ); -sub _process_options_for_provides { - my ($self, $options) = @_; - (exists $options->{isa}) - || confess "You must define a type with the Array metaclass"; - - (find_type_constraint($options->{isa})->is_subtype_of('ArrayRef')) - || confess "The type constraint for a Array must be a subtype of ArrayRef"; -} +sub helper_type { 'ArrayRef' } no Moose; @@ -76,15 +30,18 @@ __END__ =head1 NAME +MooseX::AttributeHelpers::Collection::Array + =head1 SYNOPSIS package Stuff; use Moose; + use MooseX::AttributeHelpers; has 'options' => ( - metaclass => 'Collection', + metaclass => 'Collection::Array', is => 'ro', - isa => 'ArrayRef', + isa => 'ArrayRef[Int]', default => sub { [] }, provides => { 'push' => 'add_options', @@ -94,8 +51,22 @@ __END__ =head1 DESCRIPTION +This module provides an Array attribute which provides a number of +array operations. See L +for more details. + =head1 METHODS +=over 4 + +=item B + +=item B + +=item B + +=back + =head1 BUGS All complex software has bugs lurking in it, and this module is no @@ -115,4 +86,4 @@ L This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. -=cut \ No newline at end of file +=cut