> One of the features I like about Eiffel is what Meyer calls the Uniform
> Access principle...It sounds as though Perl 6 is heading towards supporting 
> this.  Have we actually got there?

That's the intention, yes.

The details still need to be nutted out, but it seems very likely that if you
write:

        class Foo { # version 1

                my $.bar_attr is public;
        }

then you'll get an automagically created lvalue accessor method that will allow
you to write:

        my $foo = Foo.new();

        $foo.bar_attr = 1;

and then later define a real C<Foo::bar_attr> method to encapsulate it:

        class Foo {     # version 2

                my $.bar_attr;

                method bar_attr is rw($rvalue) () {
                        if exists $rvalue {
                                croak "Negative value" if $rvalue < 0;
                                $.bar_attr = $rvalue;
                        }
                        return $.bar_attr;
                }
        }


More interestingly, it may also be that, by default, the C<operator:{}> (i.e.
hash-look-up) method of a class invokes the accessor of the same name as the
key, so that:

        $foo.bar_attr = 1;

could also be written:

        $foo.{bar_attr} = 1;

and still have the same Uniform Access effect.

This would help Perl 6 support legacy Perl 5 OO code
(not to mention legacy Perl 5 OO coders ;-) 

Damian

Reply via email to