I accidentally replied to just Christopher:

---------- Forwarded message ----------
From: Sartak <sar...@gmail.com>
Date: Thu, Jan 29, 2009 at 8:07 PM
Subject: Re: simultaneous defined attributes and triggers
To: Christopher Brown <cbr...@opendatagroup.com>


On Thu, Jan 29, 2009 at 7:54 PM, Christopher Brown
<cbr...@opendatagroup.com> wrote:
> Hi Moose Folks,

Hey Christopher,

> Now, suppose that I use the syntax for defining attributes simultaneously,
>
>    has [ qw(foo bar ) ] => (
>        is => 'rw' ,
>        isa => 'Int' ,
>        trigger => sub {
>            $_[0]->{foo} = $_[1]+2 ;
>                                           # ^^^^
>        } ,
>    );

Here's how I'd do this:

   for my $name (qw(foo bar)) {
       has $name => (
           is => 'rw' ,
           isa => 'Int' ,
           trigger => sub {
               $_[0]->{$name} = $_[1]+2 ;
           } ,
       );
   }

Shawn

Reply via email to