# from Yuval Kogman # on Monday 02 April 2007 03:57 pm: >Then just proxy everything: >For the proper distinction between a setter and a method that >accepts arguments (and should still be shadowed) I guess you need >some meta programming, but the value is dubious IMHO.
My first thought was actually to just use class inheritance. It seems that what Andy is doing here is something like singleton object inheritance, so a class is as good an object as any. Just start with a root class and inheritable class accessors. The variant() method then returns a new class, which only exists in memory and only contains @ISA, getters, and setters. my $w10 = FormClass->variant(width => 10); # that's a "FormClass::+0", which isa('FormClass') my $blue_w10 = $w10->variant(color => 'blue'); # that's a 'FormClass::+1", which isa('FromClass::+0') Increment the number to prevent conflicts. The "+" is also a conflict prevention bit. Note that the class name is illegal at the *compiler*, but you're installing typeglobs and the runtime has no qualms about that. See chromatic's "Perl Hacks". The object could just be a string. But, I suppose it could be a blessed reference reference reference or whatever if you want DESTROY to get rid of those globs. Since you have to be careful not to DESTROY a parent of a class which is still in use, perhaps $self = \$parent would let the garbage collector do the work for you. I recommend using bare attribute names for getters and set_attrib for setters. If you want to allow instances to override values outside of variant(), then your setters have to be checking ref($self) vs $package and installing a new getter/setter pair in the ref($self) package (note that $package is not __PACKAGE__ when you play in the ether like that.) Considering how much perl does for you in keeping the hierarchy straight, I'm thinking the symbol table is as good a data store as any in this case. Even without the singletons. The only caveat I wonder about is whether there is any sort of arbitrary limit on the symbol table size. Of course, you could reimplement the symbol table with autoload and hash references, just don't break can() when you do it. --Eric -- [...proprietary software is better than gpl because...] "There is value in having somebody you can write checks to, and they fix bugs." --Mike McNamara (president of a commercial software company) --------------------------------------------------- http://scratchcomputing.com ---------------------------------------------------