On Tuesday 27 Apr 2010 18:54:06 Dave Rolsky wrote: > On Tue, 27 Apr 2010, Shlomi Fish wrote: > > [code] > > has '_get_paragraph_tag_name' => (is => 'ro', default => "para"); > > [/code] > > > > And maybe specialise it further using «has '+_get_paragraph_tag_name'», > > but it seems like it would be much more verbose. > > I would do this ... > > has _paragraph_name => ( is => 'ro', builder => '_build_paragraph_name' > ); > > Then in the parent class: > > sub _build_paragraph_name { > die 'This method must be overridden in the child' > } >
Wouldn't it mean that perl will call the _build_paragraph_name of the sub- class upon every instantiation of an object? I could be prematurely micro- optimising in thinking that it matters, though. > As an aside, naming an attribute with a name starting with "get" is an > abomination. If you want PBP style accessors, use MooseX::FollowPBP. > Attribute names should be nouns, not verbs. Well, first of all, I used _get_ here in my code as a clarification because I used it in the sub-class-mutated-constant-method previously. I realise it's not wise to use _get_something() for attributes/properties/fields/object- members/etc. (like has '_get_something'). Otherwise you can have code like '$self->_get_something("New Value");'. That put aside, I sometimes prefix methods returning calculations (not object properties) with "get_" or "calc_". Whether *that* is a good idea, is much more of a colour of the bike shed argument, and it probably doesn't matter too much. Regards, Shlomi Fish -- ----------------------------------------------------------------- Shlomi Fish http://www.shlomifish.org/ "The Human Hacking Field Guide" - http://shlom.in/hhfg God considered inflicting XSLT as the tenth plague of Egypt, but then decided against it because he thought it would be too evil. Please reply to list if it's a mailing list post - http://shlom.in/reply .