Newsgroups: perl.perl6.language
From: willi...@tni.com (John Williams)
Date: Fri, 27 Feb 2004 19:37:57 -0700 (MST)
Local: Fri, Feb 27 2004 9:37 pm
Subject: Thinking about Accessors
This may all be explained in the upcoming A12, but I'm trying to get
Accessors figured out in my head, and I had a few questions and comments. ===== paraphrased from Damian in http://www.nntp.perl.org/group/perl.perl6.language/9576) it seems very likely that if you write: class Foo { # version 1 then you'll get an automagically created lvalue accessor method that will my $foo = Foo.new(); and then later define a real C<Foo::bar_attr> method to encapsulate it: class Foo { # version 2 ===== From Damian's comments I conclude: There will be one autogenerated accessor, with the same name as the It will work correctly in all these cases: $x = $foo.bar_attr; # read My question is about these cases: $foo.bar_attr += $z # read then write L<Apocalypse 6/Lvalue subroutines> would seem to apply here because of the In fact, I think Damian's example above (written long before A6, so not $foo.bar_attr = 12; According to A6, it should probably be written like this: method bar_attr() is rw { But if we *always* have to return a proxy object, in case someone uses += I really like the "is Proxy" for tie-ing things, but I keep thinking its a The accessor would have a simple signature: method bar(?$val) {...} It is simple to know if the accessor is reading or writing: method bar(?$val) { But I am asking for magic with that, because $foo.bar is no longer what it A proxy should be able to do anything, it just doesn't do it as simply as I want to get from here method bar_attr(?$val) is accessor { to here method bar_attr() is rw { using a break-the-rules trait called accessor. I'm not sure what method gets called when a trait is applied to something, trait accessor { method APPLY( Code $acc : ) { # add the rw trait # wrap the applyee I *think* that accomplishes my goal of simple-to-write accessors (for method bar_attr(?$rvalue) is accessor { Or maybe I'm missing the point completely.... comments? rebuttals? ~ John Williams You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||