|
|
| Syntactic Confectionery Delight | |
| PerlMonks |
Checking for Presence of Optional Attribute in Moose Objectby roho (Prior) |
| on Jul 03, 2010 at 21:28 UTC ( #847938=perlquestion: print w/ replies, xml ) | Need Help?? |
|
roho has asked for the
wisdom of the Perl Monks concerning the following question:
I have a Moose class with an attribute that is not required. When I try to
access this attribute in an object where it is not present, the warning message
"Use of uninitialized value in concatenation (.) or string"
is generated. How can I check for the presence of an optional attribute
without generating the warning message?
The sample code below is a simple Moose class with 1 required attribute (name) and 1 optional attribute (age). The 'show_person' method generates the warning message because $self->age() is not present in the current object.
Just referencing $self->age() in 'show_person' to test it generates the warning, as in:
"Its not how hard you work, its how much you get done."
Back to
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||||||