Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Re^2: Moose goodness for status-code values?

by dynamo (Chaplain)
on Nov 19, 2011 at 06:02 UTC ( [id://938943] : note . print w/replies, xml ) Need Help??

in reply to Re: Moose goodness for status-code values?
in thread Moose goodness for status-code values?

I see a few potential problems with the strategy you describe here, perhaps they are related to why the Boolean module doesn't work the way you'd like out of the box. You might want to take another look though, it does help get you most of the way there.

One problem is that you didn't follow the convention of storing a single bit of information using 0 for false/fail and 1 for true/pass. The easiest solution here is to go with the flow and use something like $record->status(0) for fail, and $record->status(1) for pass. Next easiest would be to define functions called pass and fail, so you can use them as barewords instead of 0 and 1.

Or, you can have the user pass specific values such as 'F' or 'P', and still /store/ the value as a native boolean. You would have to write your own accessor, but it wouldn't be terribly complex, and what you are requesting is pretty unusual / dangerous style-wise, I'm not surprised there isn't yet a module to automagically create method names for each potential value of a variable in the namespace of it's containing class.

Having said that, when you know you want to create them, you could just declare the accessor subs yourself along with the attribute in a Moose::Role, and then 'with' them into whatever class(es) you'd like, which is a little bit automagical.

  • Comment on Re^2: Moose goodness for status-code values?