Thread

Posted on Sat Jan 21 01:05:26 2006 by cowanbill
Suggestion for new accessor style
Class::Meta offers a useful accessor style that you may want to consider. From Class::Meta doc:
The boolean data type is the only one that uses a slightly different approach to the creation of affordance accessors: It creates three of them. Assuming you're creating a boolean attribute named "alive", it will create these accessors:
sub is_alive { shift->{alive} } sub set_alive_on { shift->{alive} = 1 } sub set_alive_off { shift->{alive} = 0 }

Suggested accessor style name is 'bool' or 'boolean'.
A good coding practice is to prefix the boolean attribute/field with 'is_', i.e. 'is_alive'. Example: 'is_finished' for the object attribute. Using the above accessor style would require naming the boolean attributes without the 'is_'; this seems to be a reasonable approach. Other thoughts on how to fit coding practive with this useful accessor style?

Thanks for your hard work, Bill
Direct Responses: 1672 | Write a response
Posted on Sat Jan 21 02:13:17 2006 by jdhedden in response to 1671
Re: Suggestion for new accessor style
This is the first time I've ever seen such an accessor style, so it strikes me as kind of non-standard. I don't really see the utility of '$obj->set_alive_on()' over '$obj->set_alive(1)'. Further, having separate 'on' and 'off' accessors precludes constructs like '$obj->set_alive($bool)'.
Write a response