I missed the list and only hit Jesse the first time.

*sigh*


---------- Forwarded message ----------
From: Chris Prather <perig...@gmail.com>
Date: Sun, Aug 23, 2009 at 3:06 PM
Subject: Re: More on Native Traits
To: Jesse Luehrs <d...@tozt.net>


On Fri, Aug 21, 2009 at 7:22 PM, Jesse Luehrs<d...@tozt.net> wrote:
> On Fri, Aug 21, 2009 at 09:22:26AM -0700, Hans Dieter Pearcey wrote:
>> As far as I know, nothing else needs to be done for this branch.  Jesse, 
>> Chris,
>> or Shawn -- anything I missed?
>
> Moose::Manual::Delegation needs updating for curries (and probably for
> the rest too).
>
> -doy
>

Okay,

I have added the following to the AH branch inside
Moose/Manual/Delegation.pm. Is there anything else blocking us?

=head1 PERL DATA STRUCTURES

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<MooseX::AttributeHelpers|MooseX::AttributeHelpers> the mechanisim is very
similar.

 has 'queue' => (
     isa => 'ArrayRef[Item]',
     traits => ['Array'],
     default => sub { [ ] },
     handles => {
         add_item => 'push',
         next_item => 'shift',
     }
 )

By providing using C<Array> trait to the C<traits> parameter you signal to
Moose that you would like to use the set of Array helpers. Moose will then
create an C<add_item> and a C<next_item> method that "just works". Behind the
scenes C<add_item> is something like

 sub add_item {
     my ($self, @items) = @_;
     push @{ $self->queue }, @items;
 }

There are traits for not only C<Array> but also C<Hash>, C<Bool>, C<String>,
C<Number>, and C<Counter>. For more information see the documentation in
L<Moose::Meta::Attribute::Native|Moose::Meta::Attribute::Native>.

=head1 CURRYING

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.

   package Spider;
   use Moose;

   has request => (
       is => 'ro'
       isa => 'HTTP::Request',
       handles => {
           set_user_agent => [ header => 'UserAgent'],
       }
   )

With this definiton calling C<$spider->set_user_agent('MyClient')> will behind
the scenes call C<$spider->request->header('UserAgent', 'MyClient')>.

Reply via email to