Perl Monk, Perl Meditation | |
PerlMonks |
Return $self, but what if I don't wanna?by asoftware (Novice) |
on Mar 10, 2010 at 02:04 UTC ( [id://827673]=perlquestion: print w/replies, xml ) | Need Help?? |
asoftware has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks,
Usually when you are writing a method you make the return value $self, particularly important if you have modified one or more of the objects data members. What is the best way to return some other value, while still updating $self? Often I come across code where I work that does this sort of thing (Moose style OO). So my question's are these: 1) Is it possible to update $self->foo while returning something other than $self, I doubt it. but asking just in case. 2) If not, is the above example the correct 'convention' for returning arbitrary values from a method. 3) When does it make sense to simply update an objects attributes, and expect the caller to use them instead of return values. Any thoughts you have on this subject would be greatly appreciated.
--
Cam
Back to
Seekers of Perl Wisdom
|
|