in reply to Re: Moose goodness for status-code values?
in thread Moose goodness for status-code values?
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.
|
---|