From: Shawn M Moore Date: Sun, 23 Aug 2009 22:37:43 +0000 (-0400) Subject: Cleanup; include validation of push parameters X-Git-Tag: 0.89_01~5^2~6 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f4c5daebc1a9b7634f1ac7b555c9b1813d3cfaa3;p=gitmo%2FMoose.git Cleanup; include validation of push parameters --- diff --git a/lib/Moose/Manual/Delegation.pod b/lib/Moose/Manual/Delegation.pod index e0a5d09..752917f 100644 --- a/lib/Moose/Manual/Delegation.pod +++ b/lib/Moose/Manual/Delegation.pod @@ -99,25 +99,28 @@ L docs for more details on exactly how this works. Handles also will allow you to delegate to "helper" methods that work on common Perl data structures. If you remember or have ever used L the mechanism is very -similar. - +similar. + has 'queue' => ( - isa => 'ArrayRef[Item]', - traits => ['Array'], + isa => 'ArrayRef[Item]', + traits => ['Array'], default => sub { [ ] }, handles => { - add_item => 'push', + add_item => 'push', next_item => 'shift', } ) -By providing using C trait to the C parameter you signal to +By providing the C trait to the C parameter you signal to Moose that you would like to use the set of Array helpers. Moose will then -create an C and a C method that "just works". Behind the +create C and C methods that "just work". Behind the scenes C is something like - sub add_item { + sub add_item { my ($self, @items) = @_; + for my $item (@items) { + $Item_TC->validate($item); + } push @{ $self->queue }, @items; } @@ -129,7 +132,7 @@ L. Currying is a way of creating a method or function from another method or function with one of the parameters pre-defined. Moose provides the ability to -curry methods when creating delegates. +curry methods when creating delegates. package Spider; use Moose;