develooper Front page | perl.module-authors | Postings from November 2003

Re: Class::FakeAttributes -- Opinions Wanted

Thread Previous | Thread Next
November 3, 2003 09:11
Re: Class::FakeAttributes -- Opinions Wanted
Message ID:
From: A. Pagaltzis
> 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 (@_) {
                                return $s;
                        } else {
                                return $attribs{$full}->{refaddr($s)};

                *{$full} = $sub;

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


mail2web - Check your email from the web at .

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About