On 2004-04-20 at 11:37:18, Larry Wall wrote: > So do whatever you like to the declarations, but make sure you preserve > the symmetry and extensibility of > > $obj.foo([EMAIL PROTECTED], *%NONSENSE) # get value of $.foo > $obj.foo([EMAIL PROTECTED], *%NONSENSE) = 5 # set $.foo = 5 > > And while you're at it, make sure your syntactic sugar doesn't force > people to duplicate the code to process [EMAIL PROTECTED] and *%NONSENSE in > their getter and setter.
Works for me. I just want to make sure that it's easy to write classes that preserve that interface when there *is* no $.foo within the implementation of the class. After all, the point of abstraction is to hide implementation details, so it shouldn't matter to the caller whether or not the attribute exists. And the fact that it looks like it exists to the caller shouldn't force the implementation to manufacture attributes just because otherwise there's no lvalue to return for assignment purposes. As a trivial example, imagine that I want a class Length that lets me do conversions: my $len = new Length(furlongs => 10) say $len.feet ==> 6600.0132 $1en.feet = 6 say $len.meters ==> 1.8288 say $len.furlongs ==> 0.0090908909 Ideally, the implementation of this class should consist of a single attribute to store the length (in whatever it considers to be the canonical units), a conversion table, and a single AUTOLOAD/method_missing/whatever method which does conversions based on (a) the name by which its invoked and (b) whether it's invoked as an lvalue or rvalue. -Mark