[tpm] Lightning Talk lineup
Dave Doyle
dave.s.doyle at gmail.com
Tue Sep 30 14:27:11 PDT 2008
(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 ).
I just quizzed Richard to see if this was the case and double-checked
perlref and this is indeed the case. Apparently Richard remembers asking
Randal about this once and it was a weird kink that no one could stop the
interpreter from screwing up so they decided to add the plus. sub { return
{}; } would have been what I myself would have done initially but I went
with what I saw.
For your reference and mine, you'll find it under point 3 here:
http://perldoc.perl.org/perlref.html#Making-References
Thanks,
Dave
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/toronto-pm/attachments/20080930/2d258ed3/attachment.html>
More information about the toronto-pm
mailing list