Fwd: simultaneous defined attributes and triggers

[email protected] (Sartak)
Newsgroups perl.moose
Message-ID <[email protected]>
I accidentally replied to just Christopher:


---------- Forwarded message ----------
From: Sartak <[email protected]>
Date: Thu, Jan 29, 2009 at 8:07 PM
Subject: Re: simultaneous defined attributes and triggers
To: Christopher Brown <[email protected]>


On Thu, Jan 29, 2009 at 7:54 PM, Christopher Brown
<[email protected]> 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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.