X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMooseX%2FAttributeHelpers.pm;h=6e365ecee296f66c217078deb17726a12e1e0a8a;hb=3ebd23e61a6d6f3c4dbda39e3b9d90c0b34d52c5;hp=691e9ae345b47b38de19199756daa441fb4eb834;hpb=c43a23178f5d27354f669a5a68b5ea1f93640868;p=gitmo%2FMooseX-AttributeHelpers.git diff --git a/lib/MooseX/AttributeHelpers.pm b/lib/MooseX/AttributeHelpers.pm index 691e9ae..6e365ec 100644 --- a/lib/MooseX/AttributeHelpers.pm +++ b/lib/MooseX/AttributeHelpers.pm @@ -1,12 +1,25 @@ package MooseX::AttributeHelpers; -our $VERSION = '0.09'; +our $VERSION = '0.22'; +$VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; +use Moose 0.56 (); + use MooseX::AttributeHelpers::Meta::Method::Provided; use MooseX::AttributeHelpers::Meta::Method::Curried; +use MooseX::AttributeHelpers::Trait::Bool; +use MooseX::AttributeHelpers::Trait::Counter; +use MooseX::AttributeHelpers::Trait::Number; +use MooseX::AttributeHelpers::Trait::String; +use MooseX::AttributeHelpers::Trait::Collection::List; +use MooseX::AttributeHelpers::Trait::Collection::Array; +use MooseX::AttributeHelpers::Trait::Collection::Hash; +use MooseX::AttributeHelpers::Trait::Collection::ImmutableHash; +use MooseX::AttributeHelpers::Trait::Collection::Bag; + use MooseX::AttributeHelpers::Counter; use MooseX::AttributeHelpers::Number; use MooseX::AttributeHelpers::String; @@ -45,10 +58,11 @@ MooseX::AttributeHelpers - Extend your attribute interfaces set => 'set_mapping', }, curries => { - set => [ set_quantity => 'quantity' ] + set => { set_quantity => [ 'quantity' ] } } ); + # ... my $obj = MyClass->new; @@ -57,6 +71,7 @@ MooseX::AttributeHelpers - Extend your attribute interfaces $obj->set_mapping(5, 'bar'); # 5 => 'bar' $obj->set_mapping(6, 'baz'); # 6 => 'baz' + # prints 'bar' print $obj->get_mapping(5) if $obj->exists_in_mapping(5); @@ -77,14 +92,36 @@ C parameter. Available meta classes are: =head2 provides This points to a hashref that uses C for the keys and -C<['method', @args]> for the values. The method will be added to +C for the values. The method will be added to the object itself and do what you want. =head2 curries This points to a hashref that uses C for the keys and -C<['method', @args]> for the values. The method will be added to -the object itself (always using C<@args> as the beginning arguments). +has two choices for the value: + +You can supply C<< {method => [ @args ]} >> for the values. The method will be +added to the object itself (always using C<@args> as the beginning arguments). + +Another approach to curry a method provider is to supply a coderef instead of an +arrayref. The code ref takes C<$self>, C<$body>, and any additional arguments +passed to the final method. + + # ... + + curries => { + grep => { + times_with_day => sub { + my ($self, $body, $datetime) = @_; + $body->($self, sub { $_->ymd eq $datetime->ymd }); + } + } + } + + # ... + + $obj->times_with_day(DateTime->now); # takes datetime argument, checks day + =head1 METHOD PROVIDERS @@ -94,11 +131,15 @@ the object itself (always using C<@args> as the beginning arguments). Common numerical operations. +=item L + +Common methods for string operations. + =item L Methods for incrementing and decrementing a counter attribute. -=item L +=item L Common methods for boolean values. @@ -106,6 +147,10 @@ Common methods for boolean values. Common methods for hash references. +=item L + +Common methods for inspecting hash references. + =item L Common methods for array references. @@ -159,9 +204,17 @@ Yuval Kogman Jason May +Cory (gphat) Watson + +Florian (rafl) Ragwitz + +Evan Carroll + +Jesse (doy) Luehrs + =head1 COPYRIGHT AND LICENSE -Copyright 2007, 2008 by Infinity Interactive, Inc. +Copyright 2007-2009 by Infinity Interactive, Inc. L