[tpm] Lightning Talk lineup
Alex Beamish
talexb at gmail.com
Fri Oct 3 09:39:08 PDT 2008
On Tue, Sep 30, 2008 at 5:27 PM, Dave Doyle <dave.s.doyle at gmail.com> wrote:
> (with apologies to Ilia for sending it to him first instead of the list...
> damn reply button)
>
> Side note from my Lightning talk.
>
> It came up at one point why when I was defining an attribute I did this:
>
> has 'x' => (
> is => 'rw',
> isa => 'HashRef',
> default => sub { +{} },
> );
>
> In Moose, if you're defining a type with a default that is not a scalar, you
> have to use an anonymous sub. But in all the Moose examples for hashrefs,
> you see the "sub { +{} }". The good Abbot Beamish questioned me on this
> peculiar plus sign and I guessed was because the Perl interpreter needed to
> disambiguate the use of the braces ( a BLOCK or a HASHREF ).
Hi Dave!
Amazingly enough, I actually used this new-found piece of knowledge
today, building an array of hashrefs for a call to a library that I
cannot (yet) change:
my @symbols = map { +{ 'key' => $_ } } @things;
Proof once again that Perl is an unbelievably powerful language. I'm
glad you used it, and I asked you about it. :)
--
Alex Beamish
Toronto, Ontario
aka talexb
More information about the toronto-pm
mailing list