From: Hans Dieter Pearcey Date: Fri, 26 Jun 2009 01:15:35 +0000 (-0700) Subject: fix all examples to use handles; fix links to be to traits X-Git-Tag: 0.89_02~116 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=5f3663b2046a9099296bc50ecf7e79bde2163eaa;p=gitmo%2FMoose.git fix all examples to use handles; fix links to be to traits --- diff --git a/lib/Moose/AttributeHelpers.pm b/lib/Moose/AttributeHelpers.pm index 82ce7b5..7bb7cf9 100644 --- a/lib/Moose/AttributeHelpers.pm +++ b/lib/Moose/AttributeHelpers.pm @@ -80,77 +80,49 @@ readers, writers, clearers and predicates, this library provides commonly 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: +C parameter. Available meta classes are below; see L. =head1 PARAMETERS =head2 handles -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 - +This is like C<< handles >> in L, but only HASH references are +allowed. Keys are method names that you want installed locally, and values are +methods from the method providers (below). Currying with delegated methods works normally for C<< handles >>. =head1 METHOD PROVIDERS =over -=item L +=item L Common numerical operations. -=item L +=item L Common methods for string operations. -=item L +=item L Methods for incrementing and decrementing a counter attribute. -=item L +=item L Common methods for boolean values. -=item L +=item L Common methods for hash references. -=item L +=item L Common methods for inspecting hash references. -=item L +=item L Common methods for array references. -=item L +=item L Common list methods for array references. diff --git a/lib/Moose/AttributeHelpers/Collection/Array.pm b/lib/Moose/AttributeHelpers/Collection/Array.pm index 29997e8..b700348 100644 --- a/lib/Moose/AttributeHelpers/Collection/Array.pm +++ b/lib/Moose/AttributeHelpers/Collection/Array.pm @@ -38,9 +38,9 @@ Moose::AttributeHelpers::Collection::Array is => 'ro', isa => 'ArrayRef[Int]', default => sub { [] }, - provides => { - 'push' => 'add_options', - 'pop' => 'remove_last_option', + handles => { + add_options => 'push', + remove_last_option => 'pop', } ); diff --git a/lib/Moose/AttributeHelpers/Collection/Bag.pm b/lib/Moose/AttributeHelpers/Collection/Bag.pm index d0fb263..f510260 100644 --- a/lib/Moose/AttributeHelpers/Collection/Bag.pm +++ b/lib/Moose/AttributeHelpers/Collection/Bag.pm @@ -36,12 +36,12 @@ Moose::AttributeHelpers::Collection::Bag metaclass => 'Collection::Bag', is => 'ro', isa => 'Bag', # optional ... as is defalt - provides => { - 'add' => 'add_word', - 'get' => 'get_count_for', - 'empty' => 'has_any_words', - 'count' => 'num_words', - 'delete' => 'delete_word', + handles => { + add_word => 'add', + get_count_for => 'get', + has_any_words => 'empty', + num_words => 'count', + delete_word => 'delete', } ); diff --git a/lib/Moose/AttributeHelpers/Collection/Hash.pm b/lib/Moose/AttributeHelpers/Collection/Hash.pm index 8230050..cf707bc 100644 --- a/lib/Moose/AttributeHelpers/Collection/Hash.pm +++ b/lib/Moose/AttributeHelpers/Collection/Hash.pm @@ -38,12 +38,12 @@ Moose::AttributeHelpers::Collection::Hash is => 'ro', isa => 'HashRef[Str]', default => sub { {} }, - provides => { - 'set' => 'set_option', - 'get' => 'get_option', - 'empty' => 'has_options', - 'count' => 'num_options', - 'delete' => 'delete_option', + handles => { + set_option => 'set', + get_option => 'get', + has_options => 'empty', + num_options => 'count', + delete_option => 'delete', } ); diff --git a/lib/Moose/AttributeHelpers/Collection/ImmutableHash.pm b/lib/Moose/AttributeHelpers/Collection/ImmutableHash.pm index 22fb5dd..56a7532 100644 --- a/lib/Moose/AttributeHelpers/Collection/ImmutableHash.pm +++ b/lib/Moose/AttributeHelpers/Collection/ImmutableHash.pm @@ -38,10 +38,10 @@ Moose::AttributeHelpers::Collection::ImmutableHash is => 'ro', isa => 'HashRef[Str]', default => sub { {} }, - provides => { - 'get' => 'get_option', - 'empty' => 'has_options', - 'keys' => 'get_option_list', + handles => { + get_option => 'get', + has_options => 'empty', + get_option_list => 'keys', } ); diff --git a/lib/Moose/AttributeHelpers/Collection/List.pm b/lib/Moose/AttributeHelpers/Collection/List.pm index ef17502..53b3ca6 100644 --- a/lib/Moose/AttributeHelpers/Collection/List.pm +++ b/lib/Moose/AttributeHelpers/Collection/List.pm @@ -38,9 +38,9 @@ Moose::AttributeHelpers::Collection::List is => 'ro', isa => 'ArrayRef[Int]', default => sub { [] }, - provides => { - map => 'map_options', - grep => 'filter_options', + handles => { + map_options => 'map', + filter_options => 'grep', } ); diff --git a/lib/Moose/AttributeHelpers/MethodProvider/List.pm b/lib/Moose/AttributeHelpers/MethodProvider/List.pm index 6e011c6..c1d425c 100644 --- a/lib/Moose/AttributeHelpers/MethodProvider/List.pm +++ b/lib/Moose/AttributeHelpers/MethodProvider/List.pm @@ -121,18 +121,18 @@ Moose::AttributeHelpers::MethodProvider::List isa => 'ArrayRef[Str]', default => sub { [] }, auto_deref => 1, - provides => { - elements => 'all_options', - map => 'map_options', - grep => 'filter_options', - find => 'find_option', - first => 'first_option', - last => 'last_option', - get => 'get_option', - join => 'join_options', - count => 'count_options', - empty => 'do_i_have_options', - sort => 'sorted_options', + handles => { + all_options => 'elements', + map_options => 'map', + filter_options => 'grep', + find_option => 'find', + first_option => 'first', + last_option => 'last', + get_option => 'get', + join_options => 'join', + count_options => 'count', + do_i_have_options => 'empty', + sorted_options => 'sort', } ); diff --git a/lib/Moose/AttributeHelpers/Number.pm b/lib/Moose/AttributeHelpers/Number.pm index 04225db..0205760 100644 --- a/lib/Moose/AttributeHelpers/Number.pm +++ b/lib/Moose/AttributeHelpers/Number.pm @@ -34,7 +34,7 @@ Moose::AttributeHelpers::Number is => 'ro', isa => 'Int', default => sub { 5 }, - provides => { + handles => { set => 'set', add => 'add', sub => 'sub', diff --git a/lib/Moose/AttributeHelpers/String.pm b/lib/Moose/AttributeHelpers/String.pm index 7564f43..f36a20a 100644 --- a/lib/Moose/AttributeHelpers/String.pm +++ b/lib/Moose/AttributeHelpers/String.pm @@ -37,9 +37,9 @@ Moose::AttributeHelpers::String is => 'rw', isa => 'Str', default => sub { '' }, - provides => { - append => "add_text", - replace => "replace_text", + handles => { + "add_text" => "append", + "replace_text" => "replace", } ); @@ -53,10 +53,10 @@ operations can be applied more easily (no need to make an lvalue attribute metaclass or use temporary variables). Additional methods are provided for completion. -If your attribute definition does not include any of I, I, -I or I but does use the C metaclass, -then this module applies defaults as in the L -above. This allows for a very basic counter definition: +If your attribute definition does not include any of I, I, I +or I but does use the C metaclass, then this module applies +defaults as in the L above. This allows for a very basic counter +definition: has 'foo' => (metaclass => 'String'); $obj->append_foo; diff --git a/lib/Moose/AttributeHelpers/Trait/Bool.pm b/lib/Moose/AttributeHelpers/Trait/Bool.pm index f3da980..b41d734 100644 --- a/lib/Moose/AttributeHelpers/Trait/Bool.pm +++ b/lib/Moose/AttributeHelpers/Trait/Bool.pm @@ -58,11 +58,11 @@ Moose::AttributeHelpers::Bool is => 'rw', isa => 'Bool', default => sub { 0 }, - provides => { - set => 'illuminate', - unset => 'darken', - toggle => 'flip_switch', - not => 'is_dark' + handles => { + illuminate => 'set', + darken => 'unset', + flip_switch => 'toggle', + is_dark => 'not', } ); diff --git a/lib/Moose/AttributeHelpers/Trait/Collection/Array.pm b/lib/Moose/AttributeHelpers/Trait/Collection/Array.pm index d59c991..53e36c6 100644 --- a/lib/Moose/AttributeHelpers/Trait/Collection/Array.pm +++ b/lib/Moose/AttributeHelpers/Trait/Collection/Array.pm @@ -50,9 +50,9 @@ Moose::AttributeHelpers::Collection::Array is => 'ro', isa => 'ArrayRef[Int]', default => sub { [] }, - provides => { - 'push' => 'add_options', - 'pop' => 'remove_last_option', + handles => { + add_options => 'push', + remove_last_option => 'pop', } ); diff --git a/lib/Moose/AttributeHelpers/Trait/Collection/Bag.pm b/lib/Moose/AttributeHelpers/Trait/Collection/Bag.pm index d0f4d4d..5fb342b 100644 --- a/lib/Moose/AttributeHelpers/Trait/Collection/Bag.pm +++ b/lib/Moose/AttributeHelpers/Trait/Collection/Bag.pm @@ -63,12 +63,12 @@ Moose::AttributeHelpers::Collection::Bag metaclass => 'Collection::Bag', is => 'ro', isa => 'Bag', # optional ... as is defalt - provides => { - 'add' => 'add_word', - 'get' => 'get_count_for', - 'empty' => 'has_any_words', - 'count' => 'num_words', - 'delete' => 'delete_word', + handles => { + add_word => 'add', + get_count_for => 'get', + has_any_words => 'empty', + num_words => 'count', + delete_word => 'delete', } ); diff --git a/lib/Moose/AttributeHelpers/Trait/Collection/Hash.pm b/lib/Moose/AttributeHelpers/Trait/Collection/Hash.pm index 710aad2..b0d7c2b 100644 --- a/lib/Moose/AttributeHelpers/Trait/Collection/Hash.pm +++ b/lib/Moose/AttributeHelpers/Trait/Collection/Hash.pm @@ -50,12 +50,12 @@ Moose::AttributeHelpers::Collection::Hash is => 'ro', isa => 'HashRef[Str]', default => sub { {} }, - provides => { - 'set' => 'set_option', - 'get' => 'get_option', - 'empty' => 'has_options', - 'count' => 'num_options', - 'delete' => 'delete_option', + handles => { + set_option => 'set', + get_option => 'get', + has_options => 'empty', + num_options => 'count', + delete_option => 'delete', } ); diff --git a/lib/Moose/AttributeHelpers/Trait/Collection/ImmutableHash.pm b/lib/Moose/AttributeHelpers/Trait/Collection/ImmutableHash.pm index a1f9a02..c12a4bb 100644 --- a/lib/Moose/AttributeHelpers/Trait/Collection/ImmutableHash.pm +++ b/lib/Moose/AttributeHelpers/Trait/Collection/ImmutableHash.pm @@ -50,10 +50,10 @@ Moose::AttributeHelpers::Collection::ImmutableHash is => 'ro', isa => 'HashRef[Str]', default => sub { {} }, - provides => { - 'get' => 'get_option', - 'empty' => 'has_options', - 'keys' => 'get_option_list', + handles => { + get_option => 'get', + has_options => 'empty', + get_option_list => 'keys', } ); diff --git a/lib/Moose/AttributeHelpers/Trait/Collection/List.pm b/lib/Moose/AttributeHelpers/Trait/Collection/List.pm index 68566e0..1f1a309 100644 --- a/lib/Moose/AttributeHelpers/Trait/Collection/List.pm +++ b/lib/Moose/AttributeHelpers/Trait/Collection/List.pm @@ -50,9 +50,9 @@ Moose::AttributeHelpers::Collection::List is => 'ro', isa => 'ArrayRef[Int]', default => sub { [] }, - provides => { - map => 'map_options', - grep => 'filter_options', + handles => { + map_options => 'map', + filter_options => 'grep', } ); diff --git a/lib/Moose/AttributeHelpers/Trait/Counter.pm b/lib/Moose/AttributeHelpers/Trait/Counter.pm index bf14486..2cbb835 100644 --- a/lib/Moose/AttributeHelpers/Trait/Counter.pm +++ b/lib/Moose/AttributeHelpers/Trait/Counter.pm @@ -75,10 +75,10 @@ Moose::AttributeHelpers::Counter is => 'ro', isa => 'Num', default => sub { 0 }, - provides => { - inc => 'inc_counter', - dec => 'dec_counter', - reset => 'reset_counter', + handles => { + inc_counter => 'inc', + dec_counter => 'dec', + reset_counter => 'reset', } ); @@ -92,7 +92,7 @@ This module provides a simple counter attribute, which can be incremented and decremented. If your attribute definition does not include any of I, I, -I or I but does use the C metaclass, +I or I but does use the C metaclass, then this module applies defaults as in the L above. This allows for a very basic counter definition: diff --git a/lib/Moose/AttributeHelpers/Trait/Number.pm b/lib/Moose/AttributeHelpers/Trait/Number.pm index df2662c..8e666ad 100644 --- a/lib/Moose/AttributeHelpers/Trait/Number.pm +++ b/lib/Moose/AttributeHelpers/Trait/Number.pm @@ -79,7 +79,7 @@ Moose::AttributeHelpers::Number is => 'ro', isa => 'Int', default => sub { 5 }, - provides => { + handles => { set => 'set', add => 'add', sub => 'sub', diff --git a/lib/Moose/AttributeHelpers/Trait/String.pm b/lib/Moose/AttributeHelpers/Trait/String.pm index 36af4c7..1e62902 100644 --- a/lib/Moose/AttributeHelpers/Trait/String.pm +++ b/lib/Moose/AttributeHelpers/Trait/String.pm @@ -73,9 +73,9 @@ Moose::AttributeHelpers::String is => 'rw', isa => 'Str', default => sub { '' }, - provides => { - append => "add_text", - replace => "replace_text", + handles => { + add_text => 'append', + replace_text => 'replace', } ); @@ -90,7 +90,7 @@ metaclass or use temporary variables). Additional methods are provided for completion. If your attribute definition does not include any of I, I, -I or I but does use the C metaclass, +I or I but does use the C metaclass, then this module applies defaults as in the L above. This allows for a very basic counter definition: