From: A. Pagaltzis [EMAIL PROTECTED]
> And then there's accessor/mutator generation.. ie what
> ::MethodMaker does. Which there seems to be no easy way to do
> (with lexicals) using inside out objects..

Wouldn't this do what you want (roughly, it may not actually compile...)

use Scalar::Util qw(refaddr);

{
        my %attribs;
        sub make_attr {
                my $class = shift;
                my $attr = shift;

                my $full = "${class}::${attr}";

                my $sub = sub {
                        my $s=shift;
                        if (@_) {
                                $attribs{$full}->{refaddr($s)}=shift;
                                return $s;
                        } else {
                                return $attribs{$full}->{refaddr($s)};
                        }
                }

                *{$full} = $sub;
        }
}

obviously you'd add an import method to make it nice to use too,

F


--------------------------------------------------------------------
mail2web - Check your email from the web at
http://mail2web.com/ .


Reply via email to