![]() |
|
Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
Re: Moose::Role not getting params passed via ->new()by tobyink (Canon) |
on Sep 19, 2013 at 06:26 UTC ( #1054777=note: print w/replies, xml ) | Need Help?? |
As derby said, $self will only be populated with keys corresponding to any attributes which have beeen defined for the class (including those defined in any roles the class does). You could define your role like this:
More importantly, you're making the mistake of treating $self like it's a hashref. It's not. (Actually it is by default, but you're supposed to pretend it's not. Let's pretend it's not...) Because it's not a hashref, keys %$self is meaningless. Instead you should access attributes via the accessors Moose generates:
Lastly, have you noticed that BUILD gets passed not one argument, but two?
use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name
In Section
Seekers of Perl Wisdom
|
|