Damian Conway <[EMAIL PROTECTED]> writes:

> 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;
>               ...
>       }

I've recently come to the conclusion that I like my get/set methods to
look like:

    method foo() { $.foo }
    method set_foo($self: $new_foo) { $.foo = $new_foo; $self }

(Perl6 syntax obviously). I hope it's going to be possible to set that
up automagically... (Yeah, I know, if/when Perl 6 gets macros...)

-- 
Piers

   "It is a truth universally acknowledged that a language in
    possession of a rich syntax must be in need of a rewrite."
         -- Jane Austen?

Reply via email to