Lots of doc improvements for native delegations.
Dave Rolsky [Thu, 14 Oct 2010 17:12:29 +0000 (12:12 -0500)]
1. Start calling them native delegations consistently.

2. Doc accepted arguments and return values for all provided methods.

lib/Moose/Manual/Attributes.pod
lib/Moose/Manual/Delegation.pod
lib/Moose/Meta/Attribute/Native.pm
lib/Moose/Meta/Attribute/Native/Trait.pm
lib/Moose/Meta/Attribute/Native/Trait/Array.pm
lib/Moose/Meta/Attribute/Native/Trait/Bool.pm
lib/Moose/Meta/Attribute/Native/Trait/Code.pm
lib/Moose/Meta/Attribute/Native/Trait/Counter.pm
lib/Moose/Meta/Attribute/Native/Trait/Hash.pm
lib/Moose/Meta/Attribute/Native/Trait/Number.pm
lib/Moose/Meta/Attribute/Native/Trait/String.pm

index 4fcc39c..94207db 100644 (file)
@@ -497,10 +497,10 @@ attribute metaclasses and traits. See L<Moose::Manual::MooseX> for
 some examples. You can also write your own metaclasses and traits. See
 the "Meta" and "Extending" recipes in L<Moose::Cookbook> for examples.
 
-=head2 Native Traits
+=head2 Native Delegations
 
-The Native Traits feature allows standard Perl data structures to be treated
-as if they were objects for the purposes of delegation.
+Native delegations allow you to delegate to standard Perl data structures as
+if they were objects.
 
 For example, we can pretend that an array reference has methods like
 C<push()>, C<shift()>, C<map()>, C<count()>, and more.
index cccf343..cdfae11 100644 (file)
@@ -95,10 +95,10 @@ Finally, you can also provide a sub reference to I<generate> a
 mapping. You probably won't need this version often (if ever). See the
 L<Moose> docs for more details on exactly how this works.
 
-=head1 NATIVE TRAIT DELEGATION
+=head1 NATIVE DELEGATION
 
-The Native Traits feature allows standard Perl data structures to be treated
-as if they were objects for the purposes of delegation.
+Native delegations allow you to delegate to standard Perl data structures as
+if they were objects.
 
   has 'queue' => (
       traits  => ['Array'],
@@ -110,10 +110,10 @@ as if they were objects for the purposes of delegation.
       },
   )
 
-By providing the C<Array> trait to the C<traits> parameter you tell Moose that
-you would like to use the set of Array helpers. Moose will then create
-C<add_item> and C<next_item> methods that "just works". Behind the scenes
-C<add_item> is something like
+The C<Array> trait in the C<traits> parameter tells Moose that you would like
+to use the set of Array helpers. Moose will then create C<add_item> and
+C<next_item> methods that "just work". Behind the scenes C<add_item> is
+something like
 
   sub add_item {
       my ($self, @items) = @_;
@@ -125,7 +125,7 @@ C<add_item> is something like
       push @{ $self->queue }, @items;
   }
 
-Moose includes the following native traits:
+Moose includes the following traits for native delegation:
 
 =over 4
 
index ede20d7..a9ecda6 100644 (file)
@@ -34,7 +34,7 @@ __END__
 
 =head1 NAME
 
-Moose::Meta::Attribute::Native - Extend your attribute interfaces
+Moose::Meta::Attribute::Native - Delegate to native Perl types
 
 =head1 SYNOPSIS
 
@@ -42,11 +42,11 @@ Moose::Meta::Attribute::Native - Extend your attribute interfaces
   use Moose;
 
   has 'mapping' => (
-      traits    => [ 'Hash' ],
-      is        => 'rw',
-      isa       => 'HashRef[Str]',
-      default   => sub { {} },
-      handles   => {
+      traits  => ['Hash'],
+      is      => 'rw',
+      isa     => 'HashRef[Str]',
+      default => sub { {} },
+      handles => {
           exists_in_mapping => 'exists',
           ids_in_mapping    => 'keys',
           get_mapping       => 'get',
@@ -55,16 +55,12 @@ Moose::Meta::Attribute::Native - Extend your attribute interfaces
       },
   );
 
-
-  # ...
-
   my $obj = MyClass->new;
   $obj->set_quantity(10);      # quantity => 10
   $obj->set_mapping('foo', 4); # foo => 4
   $obj->set_mapping('bar', 5); # bar => 5
   $obj->set_mapping('baz', 6); # baz => 6
 
-
   # prints 5
   print $obj->get_mapping('bar') if $obj->exists_in_mapping('bar');
 
@@ -73,42 +69,56 @@ Moose::Meta::Attribute::Native - Extend your attribute interfaces
 
 =head1 DESCRIPTION
 
-While L<Moose> attributes provide a way to name your accessors, readers,
-writers, clearers and predicates, this set of traits provides commonly
-used attribute helper methods for more specific types of data.
+Native delegations allow you to delegate to native Perl data
+structure as if they were objects. For example, in the L</SYNOPSIS> you can
+see a hash reference being treated as if it has methods named C<exists()>,
+C<keys()>, C<get()>, and C<set()>.
+
+The delegation methods (mostly) map to Perl builtins and operators. The return
+values of these delegations should be the same as the corresponding Perl
+operation. Any deviations will be explicitly documented.
+
+=head1 API
 
-As seen in the L</SYNOPSIS>, you specify the data structure via the
-C<trait> parameter. Available traits are below; see L</METHOD PROVIDERS>.
+Native delegations are enabled by passing certain options to C<has> when
+creating an attribute.
 
-This module used to exist as the L<MooseX::AttributeHelpers> extension. It was
-very commonly used, so we moved it into core Moose. Since this gave us a chance
-to change the interface, you will have to change your code or continue using
-the L<MooseX::AttributeHelpers> extension. L<MooseX::AttributeHelpers> should
-continue to work.
+=head2 traits
 
-=head1 PARAMETERS
+To enable this feature, pass the appropriate name in the C<traits> array
+reference for the attribute. For example, to enable this feature for hash
+reference, we include C<'Hash'> in the list of traits.
+
+=head2 isa
+
+You will need to make sure that the attribute has an appropriate type. For
+example, to use this with a Hash you must specify that your attribute is some
+sort of C<HashRef>.
+
+If you I<don't> specify a type, each trait has a default type it will use.
 
 =head2 handles
 
-This is like C<< handles >> in L<Moose/has>, 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 >>.
+This is just like any other delegation, but only a hash reference is allowed
+when defining native delegations. The keys are the methods to be created in
+the class which contains the attribute. The values are the methods provided by
+the associated trait. Currying works the same way as it does with any other
+delegation.
 
-=head1 NATIVE TYPES
+See the docs for each native trait for details on what methods are available.
+
+=head1 TRAITS FOR NATIVE DELEGATIONS
 
 =over
 
 =item L<Array|Moose::Meta::Attribute::Native::Trait::Array>
 
-Common methods for array references.
-
     has 'queue' => (
-        traits    => ['Array'],
-        is        => 'ro',
-        isa       => 'ArrayRef[Str]',
-        default   => sub { [] },
-        handles   => {
+        traits  => ['Array'],
+        is      => 'ro',
+        isa     => 'ArrayRef[Str]',
+        default => sub { [] },
+        handles => {
             add_item  => 'push',
             next_item => 'shift',
             # ...
@@ -117,14 +127,12 @@ Common methods for array references.
 
 =item L<Bool|Moose::Meta::Attribute::Native::Trait::Bool>
 
-Common methods for boolean values.
-
     has 'is_lit' => (
-        traits    => ['Bool'],
-        is        => 'rw',
-        isa       => 'Bool',
-        default   => 0,
-        handles   => {
+        traits  => ['Bool'],
+        is      => 'ro',
+        isa     => 'Bool',
+        default => 0,
+        handles => {
             illuminate  => 'set',
             darken      => 'unset',
             flip_switch => 'toggle',
@@ -135,14 +143,14 @@ Common methods for boolean values.
 
 =item L<Code|Moose::Meta::Attribute::Native::Trait::Code>
 
-Common methods for code references.
-
     has 'callback' => (
-        traits    => ['Code'],
-        is        => 'ro',
-        isa       => 'CodeRef',
-        default   => sub { sub { 'called' } },
-        handles   => {
+        traits  => ['Code'],
+        is      => 'ro',
+        isa     => 'CodeRef',
+        default => sub {
+            sub {'called'}
+        },
+        handles => {
             call => 'execute',
             # ...
         }
@@ -150,14 +158,12 @@ Common methods for code references.
 
 =item L<Counter|Moose::Meta::Attribute::Native::Trait::Counter>
 
-Methods for incrementing and decrementing a counter attribute.
-
     has 'counter' => (
-        traits    => ['Counter'],
-        is        => 'ro',
-        isa       => 'Num',
-        default   => 0,
-        handles   => {
+        traits  => ['Counter'],
+        is      => 'ro',
+        isa     => 'Num',
+        default => 0,
+        handles => {
             inc_counter   => 'inc',
             dec_counter   => 'dec',
             reset_counter => 'reset',
@@ -167,14 +173,12 @@ Methods for incrementing and decrementing a counter attribute.
 
 =item L<Hash|Moose::Meta::Attribute::Native::Trait::Hash>
 
-Common methods for hash references.
-
     has 'options' => (
-        traits    => ['Hash'],
-        is        => 'ro',
-        isa       => 'HashRef[Str]',
-        default   => sub { {} },
-        handles   => {
+        traits  => ['Hash'],
+        is      => 'ro',
+        isa     => 'HashRef[Str]',
+        default => sub { {} },
+        handles => {
             set_option => 'set',
             get_option => 'get',
             has_option => 'exists',
@@ -184,14 +188,12 @@ Common methods for hash references.
 
 =item L<Number|Moose::Meta::Attribute::Native::Trait::Number>
 
-Common numerical operations.
-
     has 'integer' => (
-        traits    => ['Number'],
-        is        => 'ro',
-        isa       => 'Int',
-        default   => 5,
-        handles   => {
+        traits  => ['Number'],
+        is      => 'ro',
+        isa     => 'Int',
+        default => 5,
+        handles => {
             set => 'set',
             add => 'add',
             sub => 'sub',
@@ -205,14 +207,12 @@ Common numerical operations.
 
 =item L<String|Moose::Meta::Attribute::Native::Trait::String>
 
-Common methods for string operations.
-
     has 'text' => (
-        traits    => ['String'],
-        is        => 'rw',
-        isa       => 'Str',
-        default   => q{},
-        handles   => {
+        traits  => ['String'],
+        is      => 'ro',
+        isa     => 'Str',
+        default => q{},
+        handles => {
             add_text     => 'append',
             replace_text => 'replace',
             # ...
@@ -221,6 +221,15 @@ Common methods for string operations.
 
 =back
 
+=head1 COMPATIBILITY WITH MooseX::AttributeHelpers
+
+This feature used to be a separated CPAN distribution called
+L<MooseX::AttributeHelpers>.
+
+When the feature was incorporated into the Moose core, some of the API details
+were changed. The underlying capabilities are the same, but some details of
+the API were changed.
+
 =head1 BUGS
 
 See L<Moose/BUGS> for details on reporting bugs.
index 9fa865d..a44b7dd 100644 (file)
@@ -157,7 +157,7 @@ __END__
 
 =head1 NAME
 
-Moose::Meta::Attribute::Native::Trait - Base role for helpers
+Moose::Meta::Attribute::Native::Trait - Shared role for native delegation traits
 
 =head1 BUGS
 
@@ -165,7 +165,8 @@ See L<Moose/BUGS> for details on reporting bugs.
 
 =head1 SEE ALSO
 
-Documentation for Moose native traits starts at L<Moose::Meta::Attribute Native>
+Documentation for Moose native traits can be found in
+L<Moose::Meta::Attribute::Native>.
 
 =head1 AUTHORS
 
index 544d64a..e05d2e0 100644 (file)
@@ -45,7 +45,7 @@ __END__
 
 =head1 NAME
 
-Moose::Meta::Attribute::Native::Trait::Array - Helper trait for ArrayRef attributes
+Moose::Meta::Attribute::Native::Trait::Array - Helper trait for array delegation
 
 =head1 SYNOPSIS
 
@@ -53,23 +53,23 @@ Moose::Meta::Attribute::Native::Trait::Array - Helper trait for ArrayRef attribu
     use Moose;
 
     has 'options' => (
-       traits     => ['Array'],
-       is         => 'ro',
-       isa        => 'ArrayRef[Str]',
-       default    => sub { [] },
-       handles    => {
-           all_options    => 'elements',
-           add_option     => 'push',
-           map_options    => 'map',
-           filter_options => 'grep',
-           find_option    => 'first',
-           get_option     => 'get',
-           join_options   => 'join',
-           count_options  => 'count',
-           has_options    => 'count',
-           has_no_options => 'is_empty',
-           sorted_options => 'sort',
-       },
+        traits  => ['Array'],
+        is      => 'ro',
+        isa     => 'ArrayRef[Str]',
+        default => sub { [] },
+        handles => {
+            all_options    => 'elements',
+            add_option     => 'push',
+            map_options    => 'map',
+            filter_options => 'grep',
+            find_option    => 'first',
+            get_option     => 'get',
+            join_options   => 'join',
+            count_options  => 'count',
+            has_options    => 'count',
+            has_no_options => 'is_empty',
+            sorted_options => 'sort',
+        },
     );
 
     no Moose;
@@ -84,103 +84,148 @@ array operations.
 
 =over 4
 
-=item B<count>
+=item * B<count>
 
 Returns the number of elements in the array.
 
-   $stuff = Stuff->new;
-   $stuff->options(["foo", "bar", "baz", "boo"]);
+  $stuff = Stuff->new;
+  $stuff->options( [ "foo", "bar", "baz", "boo" ] );
 
-   my $count = $stuff->count_options;
-   print "$count\n"; # prints 4
+  print $stuff->count_options; # prints 4
 
-=item B<is_empty>
+This method does not accept any arguments.
+
+=item * B<is_empty>
 
 Returns a boolean value that is true when the array has no elements.
 
-   $stuff->has_no_options ? die "No options!\n" : print "Good boy.\n";
+  $stuff->has_no_options ? die "No options!\n" : print "Good boy.\n";
+
+This method does not accept any arguments.
+
+=item * B<elements>
 
-=item B<elements>
+Returns all of the elements of the array as an array (not an array reference).
 
-Returns all of the elements of the array.
+  my @option = $stuff->all_options;
+  print "@options\n";    # prints "foo bar baz boo"
 
-   my @option = $stuff->all_options;
-   print "@options\n"; # prints "foo bar baz boo"
+This method does not accept any arguments.
 
-=item B<get($index)>
+=item * B<get($index)>
 
 Returns an element of the array by its index. You can also use negative index
 numbers, just as with Perl's core array handling.
 
-   my $option = $stuff->get_option(1);
-   print "$option\n"; # prints "bar"
+  my $option = $stuff->get_option(1);
+  print "$option\n";    # prints "bar"
+
+If the specified element does not exist, this will return C<undef>.
+
+This method does accepts just one argument.
+
+=item * B<pop>
+
+Just like Perl's builtin C<pop>.
+
+This method does not accept any arguments.
+
+=item * B<push($value1, $value2, value3 ...)>
+
+Just like Perl's builtin C<push>. Returns the number of elements in the new
+array.
+
+This method accepts any number of arguments.
+
+=item * B<shift>
 
-=item B<pop>
+Just like Perl's builtin C<shift>.
 
-=item B<push($value1, $value2, value3 ...)>
+This method does not accept any arguments.
 
-=item B<shift>
+=item * B<unshift($value1, $value2, value3 ...)>
 
-=item B<unshift($value1, $value2, value3 ...)>
+Just like Perl's builtin C<unshift>. Returns the number of elements in the new
+array.
 
-=item B<splice($offset, $length, @values)>
+This method accepts any number of arguments.
 
-These methods are all equivalent to the Perl core functions of the same name.
+=item * B<splice($offset, $length, @values)>
 
-=item B<first( sub { ... } )>
+Just like Perl's builtin C<splice>. In scalar context, this returns the last
+element removed, or C<undef> if no elements were removed. In list context,
+this returns all the elements removed from the array.
+
+This method requires at least one argument.
+
+=item * B<first( sub { ... } )>
 
 This method returns the first item matching item in the array, just like
 L<List::Util>'s C<first> function. The matching is done with a subroutine
-reference you pass to this method. The reference will be called against each
+reference you pass to this method. The subroutine will be called against each
 element in the array until one matches or all elements have been checked.
 
-   my $found = $stuff->find_option( sub { /^b/ } );
-   print "$found\n"; # prints "bar"
+  my $found = $stuff->find_option( sub {/^b/} );
+  print "$found\n";    # prints "bar"
+
+This method requires a single argument.
 
-=item B<grep( sub { ... } )>
+=item * B<grep( sub { ... } )>
 
 This method returns every element matching a given criteria, just like Perl's
 core C<grep> function. This method requires a subroutine which implements the
 matching logic.
 
-   my @found = $stuff->filter_options( sub { /^b/ } );
-   print "@found\n"; # prints "bar baz boo"
+  my @found = $stuff->filter_options( sub {/^b/} );
+  print "@found\n";    # prints "bar baz boo"
 
-=item B<map( sub { ... } )>
+This method requires a single argument.
+
+=item * B<map( sub { ... } )>
 
 This method transforms every element in the array and returns a new array,
 just like Perl's core C<map> function. This method requires a subroutine which
 implements the transformation.
 
-   my @mod_options = $stuff->map_options( sub { $_ . "-tag" } );
-   print "@mod_options\n"; # prints "foo-tag bar-tag baz-tag boo-tag"
+  my @mod_options = $stuff->map_options( sub { $_ . "-tag" } );
+  print "@mod_options\n";    # prints "foo-tag bar-tag baz-tag boo-tag"
+
+This method requires a single argument.
 
-=item B<reduce( sub { ... } )>
+=item * B<reduce( sub { ... } )>
 
-This method condenses an array into a single value, by passing a function the
+This method turns an array into a single value, by passing a function the
 value so far and the next value in the array, just like L<List::Util>'s
 C<reduce> function. The reducing is done with a subroutine reference you pass
 to this method.
 
-   my $found = $stuff->reduce_options( sub { $_[0] . $_[1] } );
-   print "$found\n"; # prints "foobarbazboo"
+  my $found = $stuff->reduce_options( sub { $_[0] . $_[1] } );
+  print "$found\n";    # prints "foobarbazboo"
+
+This method requires a single argument.
 
-=item B<sort( sub { ... } )>
+=item * B<sort>
 
-Returns a the array in sorted order.
+=item * B<sort( sub { ... } )>
+
+Returns the elements of the array in sorted order.
 
 You can provide an optional subroutine reference to sort with (as you can with
-Perl's core C<sort> function). However, instead of using C<$a> and C<$b>, you
-will need to use C<$_[0]> and C<$_[1]> instead.
+Perl's core C<sort> function). However, instead of using C<$a> and C<$b> in
+this subroutine, you will need to use C<$_[0]> and C<$_[1]>.
+
+  # ascending ASCIIbetical
+  my @sorted = $stuff->sort_options();
+
+  # Descending alphabetical order
+  my @sorted_options = $stuff->sort_options( sub { lc $_[1] cmp lc $_[0] } );
+  print "@sorted_options\n";    # prints "foo boo baz bar"
 
-   # ascending ASCIIbetical
-   my @sorted = $stuff->sort_options();
+This method accepts a single argument.
 
-   # Descending alphabetical order
-   my @sorted_options = $stuff->sort_options( sub { lc $_[1] cmp lc $_[0] } );
-   print "@sorted_options\n"; # prints "foo boo baz bar"
+=item * B<sort_in_place>
 
-=item B<sort_in_place>
+=item * B<sort_in_place( sub { ... } )>
 
 Sorts the array I<in place>, modifying the value of the attribute.
 
@@ -188,60 +233,89 @@ You can provide an optional subroutine reference to sort with (as you can with
 Perl's core C<sort> function). However, instead of using C<$a> and C<$b>, you
 will need to use C<$_[0]> and C<$_[1]> instead.
 
-=item B<shuffle>
+This method does not define a return value.
 
-Returns the array, with indices in random order, like C<shuffle> from
+This method accepts a single argument.
+
+=item * B<shuffle>
+
+Returns the elements of the array in random order, like C<shuffle> from
 L<List::Util>.
 
-=item B<uniq>
+This method does not accept any arguments.
+
+=item * B<uniq>
 
-Returns the array, with all duplicate elements removed, like C<uniq> from
+Returns the array with all duplicate elements removed, like C<uniq> from
 L<List::MoreUtils>.
 
-=item B<join($str)>
+This method does not accept any arguments.
+
+=item * B<join($str)>
 
 Joins every element of the array using the separator given as argument, just
 like Perl's core C<join> function.
 
-   my $joined = $stuff->join_options( ':' );
-   print "$joined\n"; # prints "foo:bar:baz:boo"
+  my $joined = $stuff->join_options(':');
+  print "$joined\n";    # prints "foo:bar:baz:boo"
+
+This method requires a single argument.
 
-=item B<set($index, $value)>
+=item * B<set($index, $value)>
 
 Given an index and a value, sets the specified array element's value.
 
-=item B<delete($index)>
+This method returns the value at C<$index> after the set.
+
+This method requires two arguments.
+
+=item * B<delete($index)>
 
 Removes the element at the given index from the array.
 
-=item B<insert($index, $value)>
+This method returns the deleted value. Note that if no value exists, it will
+return C<undef>.
+
+This method requires one argument.
+
+=item * B<insert($index, $value)>
 
 Inserts a new element into the array at the given index.
 
-=item B<clear>
+This method returns the new value at C<$index>.
+
+This method requires two arguments.
+
+=item * B<clear>
 
 Empties the entire array, like C<@array = ()>.
 
-=item B<accessor>
+This method does not define a return value.
+
+This method does not accept any arguments.
+
+=item * B<accessor($index)>
+
+=item * B<accessor($index, $value)>
 
 This method provides a get/set accessor for the array, based on array indexes.
 If passed one argument, it returns the value at the specified index.  If
 passed two arguments, it sets the value of the specified index.
 
-=item B<natatime($n, $code)>
+When called as a setter, this method returns the new value at C<$index>.
+
+This method accepts one or two arguments.
+
+=item * B<natatime($n)>
+
+=item * B<natatime($n, $code)>
 
 This method returns an iterator which, on each call, returns C<$n> more items
 from the array, in order, like C<natatime> from L<List::MoreUtils>. A coderef
 can optionally be provided; it will be called on each group of C<$n> elements
 in the array.
 
-=back
-
-=head1 METHODS
-
-=over 4
-
-=item B<meta>
+This method accepts one or two arguments.
 
 =back
 
index 93cfbe0..b636230 100644 (file)
@@ -31,11 +31,11 @@ Moose::Meta::Attribute::Native::Trait::Bool - Helper trait for Bool attributes
   use Moose;
 
   has 'is_lit' => (
-      traits    => ['Bool'],
-      is        => 'rw',
-      isa       => 'Bool',
-      default   => 0,
-      handles   => {
+      traits  => ['Bool'],
+      is      => 'rw',
+      isa     => 'Bool',
+      default => 0,
+      handles => {
           illuminate  => 'set',
           darken      => 'unset',
           flip_switch => 'toggle',
@@ -44,10 +44,10 @@ Moose::Meta::Attribute::Native::Trait::Bool - Helper trait for Bool attributes
   );
 
   my $room = Room->new();
-  $room->illuminate;     # same as $room->is_lit(1);
-  $room->darken;         # same as $room->is_lit(0);
-  $room->flip_switch;    # same as $room->is_lit(not $room->is_lit);
-  return $room->is_dark; # same as !$room->is_lit
+  $room->illuminate;        # same as $room->is_lit(1);
+  $room->darken;            # same as $room->is_lit(0);
+  $room->flip_switch;       # same as $room->is_lit(not $room->is_lit);
+  return $room->is_dark;    # same as !$room->is_lit
 
 =head1 DESCRIPTION
 
@@ -56,31 +56,27 @@ basic math operations.
 
 =head1 PROVIDED METHODS
 
+None of these methods accept arguments.
+
 =over 4
 
-=item B<set>
+=item * B<set>
 
-Sets the value to C<1>.
+Sets the value to C<1> and returns C<1>.
 
-=item B<unset>
+=item * B<unset>
 
-Set the value to C<0>.
+Set the value to C<0> and returns C<0>.
 
-=item B<toggle>
+=item * B<toggle>
 
 Toggles the value. If it's true, set to false, and vice versa.
 
-=item B<not>
-
-Equivalent of 'not C<$value>'.
-
-=back
-
-=head1 METHODS
+Returns the new value.
 
-=over 4
+=item * B<not>
 
-=item B<meta>
+Equivalent of 'not C<$value>'.
 
 =back
 
index 0647da1..b1333cf 100644 (file)
@@ -28,18 +28,19 @@ Moose::Meta::Attribute::Native::Trait::Code - Helper trait for Code attributes
   use Moose;
 
   has 'callback' => (
-      traits    => ['Code'],
-      is        => 'ro',
-      isa       => 'CodeRef',
-      default   => sub { sub { print "called" } },
-      handles   => {
+      traits  => ['Code'],
+      is      => 'ro',
+      isa     => 'CodeRef',
+      default => sub {
+          sub { print "called" }
+      },
+      handles => {
           call => 'execute',
       },
   );
 
   my $foo = Foo->new;
-  $foo->call; # prints "called"
-
+  $foo->call;    # prints "called"
 
 =head1 DESCRIPTION
 
@@ -49,24 +50,16 @@ This provides operations on coderef attributes.
 
 =over 4
 
-=item B<execute(@args)>
+=item * B<execute(@args)>
 
 Calls the coderef with the given args.
 
-=item B<execute_method(@args)>
+=item * B<execute_method(@args)>
 
 Calls the coderef with the the instance as invocant and given args.
 
 =back
 
-=head1 METHODS
-
-=over 4
-
-=item B<meta>
-
-=back
-
 =head1 BUGS
 
 See L<Moose/BUGS> for details on reporting bugs.
index eb16ce1..14334d9 100644 (file)
@@ -37,11 +37,11 @@ Moose::Meta::Attribute::Native::Trait::Counter - Helper trait for counters
   use Moose;
 
   has 'counter' => (
-      traits    => ['Counter'],
-      is        => 'ro',
-      isa       => 'Num',
-      default   => 0,
-      handles   => {
+      traits  => ['Counter'],
+      is      => 'ro',
+      isa     => 'Num',
+      default => 0,
+      handles => {
           inc_counter   => 'inc',
           dec_counter   => 'dec',
           reset_counter => 'reset',
@@ -49,9 +49,9 @@ Moose::Meta::Attribute::Native::Trait::Counter - Helper trait for counters
   );
 
   my $page = MyHomePage->new();
-  $page->inc_counter; # same as $page->counter( $page->counter + 1 );
-  $page->dec_counter; # same as $page->counter( $page->counter - 1 );
-  
+  $page->inc_counter;    # same as $page->counter( $page->counter + 1 );
+  $page->dec_counter;    # same as $page->counter( $page->counter - 1 );
+
   my $count_by_twos = 2;
   $page->inc_counter($count_by_twos);
 
@@ -65,31 +65,34 @@ amount of change is one.
 
 =over 4
 
-=item B<set($value)>
+=item * B<set($value)>
 
-Set the counter to the specified value.
+Sets the counter to the specified value and returns the new value.
 
-=item B<inc($arg)>
+This method requires a single argument.
 
-Increase the attribute value by the amount of the argument.  
-No argument increments the value by 1. 
+=item * B<inc>
 
-=item B<dec($arg)>
+=item * B<inc($arg)>
 
-Decrease the attribute value by the amount of the argument.  
-No argument decrements the value by 1.
+Increases the attribute value by the amount of the argument, or by 1 if no
+argument is given. This method returns the new value.
 
-=item B<reset>
+This method accepts a single argument.
 
-Resets the value stored in this slot to it's default value.
+=item * B<dec>
 
-=back
+=item * B<dec($arg)>
 
-=head1 METHODS
+Decreases the attribute value by the amount of the argument, or by 1 if no
+argument is given. This method returns the new value.
 
-=over 4
+This method accepts a single argument.
+
+=item * B<reset>
 
-=item B<meta>
+Resets the value stored in this slot to its default value, and returns the new
+value.
 
 =back
 
index e34639e..6cdf98e 100644 (file)
@@ -69,33 +69,50 @@ hash-like operations.
 
 Returns values from the hash.
 
-In list context return a list of values in the hash for the given keys.
-In scalar context returns the value for the last key specified.
+In list context it returns a list of values in the hash for the given keys. In
+scalar context it returns the value for the last key specified.
+
+This method requires at least one argument.
 
 =item B<set($key =E<gt> $value, $key2 =E<gt> $value2...)>
 
-Sets the elements in the hash to the given values.
+Sets the elements in the hash to the given values. It returns the new values
+set for each key, in the same order as the keys passed to the method.
+
+This method requires at least two arguments, and expects an even number of
+arguments.
 
 =item B<delete($key, $key2, $key3...)>
 
 Removes the elements with the given keys.
 
+In list context it returns a list of values in the hash for the deleted
+keys. In scalar context it returns the value for the last key specified.
+
 =item B<keys>
 
 Returns the list of keys in the hash.
 
+This method does not accept any arguments.
+
 =item B<exists($key)>
 
 Returns true if the given key is present in the hash.
 
+This method requires a single argument.
+
 =item B<defined($key)>
 
 Returns true if the value of a given key is defined.
 
+This method requires a single argument.
+
 =item B<values>
 
 Returns the list of values in the hash.
 
+This method does not accept any arguments.
+
 =item B<kv>
 
 Returns the key/value pairs in the hash as an array of array references.
@@ -104,28 +121,42 @@ Returns the key/value pairs in the hash as an array of array references.
       print "$pair->[0] = $pair->[1]\n";
   }
 
+This method does not accept any arguments.
+
 =item B<elements>
 
 Returns the key/value pairs in the hash as a flattened list..
 
+This method does not accept any arguments.
+
 =item B<clear>
 
 Resets the hash to an empty value, like C<%hash = ()>.
 
+This method does not accept any arguments.
+
 =item B<count>
 
 Returns the number of elements in the hash. Also useful for not empty: 
 C<< has_options => 'count' >>.
 
+This method does not accept any arguments.
+
 =item B<is_empty>
 
 If the hash is populated, returns false. Otherwise, returns true.
 
-=item B<accessor>
+This method does not accept any arguments.
+
+=item B<accessor($key)>
+
+=item B<accessor($key, $value)>
 
 If passed one argument, returns the value of the specified key. If passed two
 arguments, sets the value of the specified key.
 
+When called as a setter, this method returns the value that was set.
+
 =back
 
 =head1 METHODS
index 40f30cf..361fb81 100644 (file)
@@ -33,11 +33,11 @@ Moose::Meta::Attribute::Native::Trait::Number - Helper trait for Num attributes
   use Moose;
 
   has 'integer' => (
-      traits    => ['Number'],
-      is        => 'ro',
-      isa       => 'Num',
-      default   => 5,
-      handles   => {
+      traits  => ['Number'],
+      is      => 'ro',
+      isa     => 'Num',
+      default => 5,
+      handles => {
           set => 'set',
           add => 'add',
           sub => 'sub',
@@ -49,8 +49,8 @@ Moose::Meta::Attribute::Native::Trait::Number - Helper trait for Num attributes
   );
 
   my $real = Real->new();
-  $real->add(5); # same as $real->integer($real->integer + 5);
-  $real->sub(2); # same as $real->integer($real->integer - 2);
+  $real->add(5);    # same as $real->integer($real->integer + 5);
+  $real->sub(2);    # same as $real->integer($real->integer - 2);
 
 =head1 DESCRIPTION
 
@@ -65,43 +65,34 @@ package.
 
 =over 4
 
-=item B<set($value)>
+=item * B<add($value)>
 
-Alternate way to set the value.
+Adds the current value of the attribute to C<$value>. Returns the new value.
 
-=item B<add($value)>
+=item * B<sub($value)>
 
-Adds the current value of the attribute to C<$value>.
+Subtracts C<$value> from the current value of the attribute. Returns the new
+value.
 
-=item B<sub($value)>
+=item * B<mul($value)>
 
-Subtracts C<$value> from the current value of the attribute.
+Multiplies the current value of the attribute by C<$value>. Returns the new
+value.
 
-=item B<mul($value)>
+=item * B<div($value)>
 
-Multiplies the current value of the attribute by C<$value>.
+Divides the current value of the attribute by C<$value>. Returns the new
+value.
 
-=item B<div($value)>
+=item * B<mod($value)>
 
-Divides the current value of the attribute by C<$value>.
+Returns the current value of the attribute modulo C<$value>. Returns the new
+value.
 
-=item B<mod($value)>
+=item * B<abs>
 
-Returns the current value of the attribute modulo C<$value>.
-
-=item B<abs>
-
-Sets the current value of the attribute to its absolute value.
-
-=back
-
-=head1 METHODS
-
-=over 4
-
-=item B<meta>
-
-=item B<method_constructors>
+Sets the current value of the attribute to its absolute value. Returns the new
+value.
 
 =back
 
index 60bdb8a..4d690a8 100644 (file)
@@ -40,18 +40,18 @@ Moose::Meta::Attribute::Native::Trait::String - Helper trait for Str attributes
   use Moose;
 
   has 'text' => (
-      traits    => ['String'],
-      is        => 'rw',
-      isa       => 'Str',
-      default   => q{},
-      handles   => {
+      traits  => ['String'],
+      is      => 'rw',
+      isa     => 'Str',
+      default => q{},
+      handles => {
           add_text     => 'append',
           replace_text => 'replace',
       },
   );
 
   my $page = MyHomePage->new();
-  $page->add_text("foo"); # same as $page->text($page->text . "foo");
+  $page->add_text("foo");    # same as $page->text($page->text . "foo");
 
 =head1 DESCRIPTION
 
@@ -72,59 +72,72 @@ above. This allows for a very basic string definition:
 
 =over 4
 
-=item B<inc>
+=item * B<inc>
 
 Increments the value stored in this slot using the magical string autoincrement
 operator. Note that Perl doesn't provide analogous behavior in C<-->, so
-C<dec> is not available.
+C<dec> is not available. This method returns the new value.
 
-=item B<append($string)>
+This method does not accept any arguments.
 
-Append a string, like C<.=>.
+=item * B<append($string)>
 
-=item B<prepend($string)>
+Appends to the string, like C<.=>, and returns the new value.
 
-Prepend a string.
+This method requires a single argument.
 
-=item B<replace($pattern, $replacement)>
+=item * B<prepend($string)>
+
+Prepends to the string and returns the new value.
+
+This method requires a single argument.
+
+=item * B<replace($pattern, $replacement)>
 
 Performs a regexp substitution (L<perlop/s>). There is no way to provide the
 C<g> flag, but code references will be accepted for the replacement, causing
 the regex to be modified with a single C<e>. C</smxi> can be applied using the
-C<qr> operator.
+C<qr> operator. This method returns the new value.
 
-=item B<match($pattern)>
+This method requires two arguments.
 
-Like C<replace> but without the replacement. Provided mostly for completeness.
+=item * B<match($pattern)>
 
-=item B<chop>
+Runs the regex against the string and returns the matching value(s).
 
-L<perlfunc/chop>
+This method requires a single argument.
 
-=item B<chomp>
+=item * B<chop>
 
-L<perlfunc/chomp>
+Just like L<perlfunc/chop>. This method returns the chopped character.
 
-=item B<clear>
+This method does not accept any arguments.
 
-Sets the string to the empty string (not the value passed to C<default>).
+=item * B<chomp>
+
+Just like L<perlfunc/chomp>. This method returns the number of characters
+removed.
 
-=item B<length>
+This method does not accept any arguments.
 
-L<perlfunc/length>
+=item * B<clear>
 
-=item B<substr>
+Sets the string to the empty string (not the value passed to C<default>).
 
-L<perlfunc/substr>. We go to some lengths to match the different functionality
-based on C<substr>'s arity.
+This method does not have a defined return value.
 
-=back
+This method does not accept any arguments.
 
-=head1 METHODS
+=item * B<length>
 
-=over 4
+Just like L<perlfunc/length>, returns the length of the string.
+
+=item * B<substr>
+
+This acts just like L<perlfunc/substr>. When called as a writer, it returns
+the substring that was replaced, just like the Perl builtin.
 
-=item B<meta>
+This method requires at least one argument, and accepts no more than three.
 
 =back