From: Bruno Vecchi Date: Wed, 7 Jan 2009 14:21:06 +0000 (+0000) Subject: Pod edit: added synopsys and usage examples for every list method. X-Git-Tag: 0.16~15 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1b5dc533e8dc116647b10adef707a75ff997d721;p=gitmo%2FMooseX-AttributeHelpers.git Pod edit: added synopsys and usage examples for every list method. --- diff --git a/lib/MooseX/AttributeHelpers/MethodProvider/List.pm b/lib/MooseX/AttributeHelpers/MethodProvider/List.pm index 44ed822..a1618d9 100644 --- a/lib/MooseX/AttributeHelpers/MethodProvider/List.pm +++ b/lib/MooseX/AttributeHelpers/MethodProvider/List.pm @@ -92,7 +92,36 @@ __END__ =head1 NAME MooseX::AttributeHelpers::MethodProvider::List - + +=SYNOPSIS + + package Stuff; + use Moose; + use MooseX::AttributeHelpers; + + has 'options' => ( + metaclass => 'Collection::List', + is => 'rw', + isa => 'ArrayRef[Str]', + default => sub { [] }, + auto_deref => 1, + provides => { + 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', + + } + ); + + no Moose; + 1; + =head1 DESCRIPTION This is a role which provides the method generators for @@ -111,24 +140,69 @@ L. =over 4 =item B +Returns the number of elements of the list. + + $stuff = Stuff->new; + $stuff->options(["foo", "bar", "baz", "boo"]); + + my $count = $stuff->count_options; + print "$count\n"; # prints 4 + +=item B +If the list is populated, returns true. Otherwise, returns false. -=item B + $stuff->do_i_have_options ? print "Good boy.\n" : die "No options!\n" ; =item B +Returns the first element that returns true in the anonymous subroutine +passed as argument. + + my $found = $stuff->find_option( sub { $_[0] =~ /^b/ } ); + print "$found\n"; # prints "bar" =item B +Returns every elemnt of the list that returns true in the anonymous +subroutine passed as argument. + + my @found = $stuff->filter_options( sub { $_[0] =~ /^b/ } ); + print "@found\n"; # prints "bar baz boo" =item B +Executes the anonymouse subroutine given as argument sequentially +for each element of the list. + +my @mod_options = $stuff->map_options( sub { $_[0] . "-tag" } ); +print "@mod_options\n"; # prints "foo-tag bar-tag baz-tag boo-tag" =item B +Returns an element of the list by its index. + + my $option = $stuff->get_option(1); + print "$option\n"; # prints "bar" =item B +Joins every elemnt of the list using the separator given as argument. + + my $joined = $stuff->join_options( ':' ); + print "$joined\n"; # prints "foo:bar:baz:boo" =item B +Returns an element of the list by its index. + + my $option = $stuff->get_option(1); + print "$option\n"; # prints "bar" =item B +Returns the first element. + + my $first = $stuff->first_option; + print "$first\n"; # prints "foo" =item B +Returns the last item. + + my $last = $stuff->last_option; + print "$last\n"; # prints "boo" =back