Aaron Sherman wrote: > > What if I want my methods to be called C<.get_bar()> and C<.set_bar()>, > > since a certain Perl OO specialist suggests this approach is best for > > avoiding ambiguity in one's API? > > Then you can declare them as such: > > sub get_bar() { .bar } > sub get_baz() { .baz } > sub set_baz($newbaz) { .baz = $newbaz }
Close. They'd probably be implemented like this: method get_bar() { $.bar } method get_baz() { $.baz } method set_baz($newbaz) { $.baz = $newbaz } Of course, there would need to be some way of simultaneously preventing the automagic creation of accessors. That might be manual: class Foo { my $.bar; my $.baz; method bar is private {} method baz is private {} ... } or per-attribute: class Foo { my $.bar is accessorless; my $.baz is accessorless; ... } or (my favorite) global: class Foo { no accessors; my $.bar; my $.baz; ... } Damian > I suppose there could be some magic like: > > class Foo is accessedby('get_','','r') > is accessedby('set_','','rw') { ... } > > To declare that Foo has accessors with prefix "get_" and no suffix for > read-only acces and prefix "set_" and no suffix for read/write access. > > But, I'm not sure how valuable this would be....