Merge branch 'master' into traits
[gitmo/MooseX-AttributeHelpers.git] / lib / MooseX / AttributeHelpers.pm
index 4a73b89..69331b0 100644 (file)
@@ -1,10 +1,14 @@
 
 package MooseX::AttributeHelpers;
 
-our $VERSION   = '0.08';
+our $VERSION   = '0.17';
+$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::Counter;
 use MooseX::AttributeHelpers::Trait::Number;
@@ -18,6 +22,7 @@ use MooseX::AttributeHelpers::Trait::Collection::Bag;
 use MooseX::AttributeHelpers::Counter;
 use MooseX::AttributeHelpers::Number;
 use MooseX::AttributeHelpers::String;
+use MooseX::AttributeHelpers::Bool;
 use MooseX::AttributeHelpers::Collection::List;
 use MooseX::AttributeHelpers::Collection::Array;
 use MooseX::AttributeHelpers::Collection::Hash;
@@ -51,14 +56,20 @@ MooseX::AttributeHelpers - Extend your attribute interfaces
           get       => 'get_mapping',
           set       => 'set_mapping',
       },
+      curries  => {
+          set       => { set_quantity => [ 'quantity' ] }
+      }
   );
 
+
   # ...
 
   my $obj = MyClass->new;
-  $obj->set_mapping(4, 'foo');
-  $obj->set_mapping(5, 'bar');
-  $obj->set_mapping(6, 'baz');
+  $obj->set_quantity(10);      # quantity => 10
+  $obj->set_mapping(4, 'foo'); # 4 => 'foo'
+  $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);
@@ -75,6 +86,44 @@ used attribute helper methods for more specific types of data.
 As seen in the L</SYNOPSIS>, you specify the extension via the 
 C<metaclass> parameter. Available meta classes are:
 
+=head1 PARAMETERS
+
+=head2 provides
+
+This points to a hashref that uses C<provider> for the keys and
+C<method> 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<provider> for the keys and
+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
+
 =over
 
 =item L<Number|MooseX::AttributeHelpers::Number>
@@ -85,6 +134,10 @@ Common numerical operations.
 
 Methods for incrementing and decrementing a counter attribute.
 
+=item L<Bool|MooseX::AttributeHelpers::Bool>
+
+Common methods for boolean values.
+
 =item L<Collection::Hash|MooseX::AttributeHelpers::Collection::Hash>
 
 Common methods for hash references.
@@ -128,6 +181,10 @@ B<with contributions from:>
 
 Robert (rlb3) Boone
 
+Paul (frodwith) Driver
+
+Shawn (Sartak) Moore
+
 Chris (perigrin) Prather
 
 Robert (phaylon) Sedlacek
@@ -136,6 +193,14 @@ Tom (dec) Lanyon
 
 Yuval Kogman
 
+Jason May
+
+Cory (gphat) Watson
+
+Florian (rafl) Ragwitz
+
+Evan Carroll
+
 =head1 COPYRIGHT AND LICENSE
 
 Copyright 2007, 2008 by Infinity Interactive, Inc.