X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMooseX%2FAttributeHelpers%2FCollection%2FArray.pm;h=7b4efedf8e81f6bcf0815186a302399899394ded;hb=e0d340ca0cd12125cabbd39e9799e4fc77c2a703;hp=fbc3b1ae64f6bd49050e2270e3827abeade6c14c;hpb=69dde336792f25d5ed7d0a47d237a5382b4593a9;p=gitmo%2FMooseX-AttributeHelpers.git diff --git a/lib/MooseX/AttributeHelpers/Collection/Array.pm b/lib/MooseX/AttributeHelpers/Collection/Array.pm index fbc3b1a..7b4efed 100644 --- a/lib/MooseX/AttributeHelpers/Collection/Array.pm +++ b/lib/MooseX/AttributeHelpers/Collection/Array.pm @@ -1,98 +1,19 @@ package MooseX::AttributeHelpers::Collection::Array; use Moose; -use Moose::Util::TypeConstraints; -our $VERSION = '0.01'; +our $VERSION = '0.22'; +$VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -extends 'MooseX::AttributeHelpers::Collection'; - -sub helper_type { 'ArrayRef' } - -has '+method_constructors' => ( - default => sub { - return +{ - 'push' => sub { - my $attr = shift; - if ($attr->has_container_type) { - my $container_type_constraint = $attr->container_type_constraint; - return sub { - my $instance = shift; - $container_type_constraint->check($_) - || confess "Value " . ($_||'undef') . " did not pass container type constraint" - foreach @_; - push @{$attr->get_value($instance)} => @_; - }; - } - else { - 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; - if ($attr->has_container_type) { - my $container_type_constraint = $attr->container_type_constraint; - return sub { - my $instance = shift; - $container_type_constraint->check($_) - || confess "Value " . ($_||'undef') . " did not pass container type constraint" - foreach @_; - unshift @{$attr->get_value($instance)} => @_; - }; - } - else { - 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; - if ($attr->has_container_type) { - my $container_type_constraint = $attr->container_type_constraint; - return sub { - ($container_type_constraint->check($_[2])) - || confess "Value " . ($_[2]||'undef') . " did not pass container type constraint"; - $attr->get_value($_[0])->[$_[1]] = $_[2] - }; - } - else { - 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 }; - } - } - } -); +extends 'Moose::Meta::Attribute'; +with 'MooseX::AttributeHelpers::Trait::Collection::Array'; no Moose; # register the alias ... -package Moose::Meta::Attribute::Custom::Collection::Array; +package # hide me from search.cpan.org + Moose::Meta::Attribute::Custom::Collection::Array; sub register_implementation { 'MooseX::AttributeHelpers::Collection::Array' } @@ -104,13 +25,16 @@ __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[Int]', default => sub { [] }, @@ -122,8 +46,24 @@ __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 + +=item B + +=back + =head1 BUGS All complex software has bugs lurking in it, and this module is no @@ -136,7 +76,7 @@ Stevan Little Estevan@iinteractive.comE =head1 COPYRIGHT AND LICENSE -Copyright 2007 by Infinity Interactive, Inc. +Copyright 2007-2009 by Infinity Interactive, Inc. L