X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMooseX%2FAttributeHelpers.pm;h=26216f06f3cb6ca4c48c963fc3060cd3535f015e;hb=refs%2Ftags%2F0.18_01;hp=7815223523089d3d1e0bd2fefb823f2185bf9830;hpb=3656a0d769a430ae48626e24b560d2987a0ddc88;p=gitmo%2FMooseX-AttributeHelpers.git diff --git a/lib/MooseX/AttributeHelpers.pm b/lib/MooseX/AttributeHelpers.pm index 7815223..26216f0 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.18_01'; +$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; @@ -49,6 +62,7 @@ MooseX::AttributeHelpers - Extend your attribute interfaces } ); + # ... 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); @@ -83,8 +98,30 @@ 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 @@ -98,7 +135,7 @@ Common numerical operations. Methods for incrementing and decrementing a counter attribute. -=item L +=item L Common methods for boolean values. @@ -159,9 +196,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