X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMooseX%2FAttributeHelpers.pm;h=488b648c613dc452e6791d6d608d0d044422f4ef;hb=9486abfa30692ac19a9140b04a5a5e8d60c5d95d;hp=ad9e9be2c127b77679033983a9e978cdb95b7f74;hpb=e295d072cf24071b83f12c60933e5620b84a0853;p=gitmo%2FMooseX-AttributeHelpers.git diff --git a/lib/MooseX/AttributeHelpers.pm b/lib/MooseX/AttributeHelpers.pm index ad9e9be..488b648 100644 --- a/lib/MooseX/AttributeHelpers.pm +++ b/lib/MooseX/AttributeHelpers.pm @@ -1,15 +1,34 @@ package MooseX::AttributeHelpers; -our $VERSION = '0.01'; +our $VERSION = '0.23'; +$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; +use MooseX::AttributeHelpers::Bool; +use MooseX::AttributeHelpers::Collection::List; use MooseX::AttributeHelpers::Collection::Array; use MooseX::AttributeHelpers::Collection::Hash; +use MooseX::AttributeHelpers::Collection::ImmutableHash; +use MooseX::AttributeHelpers::Collection::Bag; 1; @@ -19,17 +38,18 @@ __END__ =head1 NAME -MooseX::AttributeHelpers - Extend your attribute interfaces +MooseX::AttributeHelpers - Extend your attribute interfaces (deprecated) =head1 SYNOPSIS package MyClass; use Moose; + use MooseX::AttributeHelpers; - has mapping => ( + has 'mapping' => ( metaclass => 'Collection::Hash', is => 'rw', - isa => 'HashRef', + isa => 'HashRef[Str]', default => sub { {} }, provides => { exists => 'exists_in_mapping', @@ -37,14 +57,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); @@ -54,6 +80,10 @@ MooseX::AttributeHelpers - Extend your attribute interfaces =head1 DESCRIPTION +B. This distribution +should not be used by any new code.> + While L attributes provide you with a way to name your accessors, readers, writers, clearers and predicates, this library provides commonly used attribute helper methods for more specific types of data. @@ -61,26 +91,95 @@ used attribute helper methods for more specific types of data. As seen in the L, you specify the extension via the C parameter. Available meta classes are: +=head1 PARAMETERS + +=head2 provides + +This points to a hashref that uses C for the keys and +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 +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 Common numerical operations. +=item L + +Common methods for string operations. + =item L Methods for incrementing and decrementing a counter attribute. +=item L + +Common methods for boolean values. + =item L Common methods for hash references. +=item L + +Common methods for inspecting hash references. + =item L Common methods for array references. +=item L + +Common list methods for array references. + =back +=head1 CAVEAT + +This is an early release of this module. Right now it is in great need +of documentation and tests in the test suite. However, we have used this +module to great success at C<$work> where it has been tested very thoroughly +and deployed into a major production site. + +I plan on getting better docs and tests in the next few releases, but until +then please refer to the few tests we do have and feel free email and/or +message me on irc.perl.org if you have any questions. + +=head1 TODO + +We need tests and docs badly. + =head1 BUGS All complex software has bugs lurking in it, and this module is no @@ -91,9 +190,35 @@ to cpan-RT. Stevan Little Estevan@iinteractive.comE +B + +Robert (rlb3) Boone + +Paul (frodwith) Driver + +Shawn (Sartak) Moore + +Chris (perigrin) Prather + +Robert (phaylon) Sedlacek + +Tom (dec) Lanyon + +Yuval Kogman + +Jason May + +Cory (gphat) Watson + +Florian (rafl) Ragwitz + +Evan Carroll + +Jesse (doy) Luehrs + =head1 COPYRIGHT AND LICENSE -Copyright 2007 by Infinity Interactive, Inc. +Copyright 2007-2009 by Infinity Interactive, Inc. L