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

Re: Class::FakeAttributes -- Opinions Wanted

Thread Previous | Thread Next
From:
fergal@esatclear.ie
Date:
November 3, 2003 09:11
Subject:
Re: Class::FakeAttributes -- Opinions Wanted
Message ID:
187160-220031113171123712@M2W058.mail2web.com
From: A. Pagaltzis pagaltzis@gmx.de
> 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/ .



Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About