Your skill will accomplish what the force of many cannot |
|
PerlMonks |
Re^3: OO design: returning string and/or special valueby Fletch (Bishop) |
on Oct 07, 2019 at 21:46 UTC ( [id://11107167]=note: print w/replies, xml ) | Need Help?? |
OK I think I misread / elided some of your OP where you said that both values were strings. In that case C::R probably isn't what you're wanting, unless you wanted to return a magical hashref that had both values that stringified to the string bit (disclaimer I've never really used C::R in anger, just aware of it's presence).
There's also Object::Result which is a variation on the theme which is aimed at making it "easier" to return an instance with arbitrary methods; I believe it's mentioned/recommended in the updated PBP course, for whatever that's worth. After thinking over it a bit more I think I'd lean towards just a hashref, maybe Object::Result; and eschew overloading or other magic. If you name the slot with the plain string well you probably win in clarity what you lose in extra typing (say $result->{message}). Then again I drove 900+ miles this weekend so take that with a large grain of salt.</handwaving>
The cake is a lie.
In Section
Seekers of Perl Wisdom
|
|