|
|
| We don't bite newbies here... much | |
| PerlMonks |
Re: Moose composing role with required attribute into existing instanceby jandrew (Hermit) |
| on Aug 03, 2012 at 18:48 UTC ( #985309=note: print w/ replies, xml ) | Need Help?? |
|
Two possibilities occur to me. One, compose the class and role together on the fly when you build the instance (instead of adding it to the instance after creation) so that when you need it you have it and when you don't you don't have to use it. This will allow your attribute to retain the required=>1 status. (This is my preference.)
If that doesn't seem to be a good fit then just add a default value and a setter (safer than 'rw') to your 'name' attribute. This will eliminate the error. You can then use your setter to change the value to the correct one when and where you want.
TIMTOWTDI applies to Moose too!
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||||