|
|
| There's more than one way to do things | |
| PerlMonks |
Re: Can't call method "MoveBook" on an undefined valueby tobyink (Prior) |
| on Jan 24, 2013 at 19:52 UTC ( #1015219=note: print w/ replies, xml ) | Need Help?? |
|
You should use a default or builder for the attributes. Defaults work like this:
Builders work like this:
Defaults are very convenient to define, but builders are arguably a better way to do things: the builder is a regular method, so subclasses can easily override it, which is handy. Builders are a very handy thing when you get used to them - especially when you use them in conjunction with Moose's lazy attribute initialisation feature.
package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||