Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re: a simple matter of elegance

by tfrayner (Curate)
on Oct 04, 2007 at 08:04 UTC ( #642590=note: print w/replies, xml ) Need Help??

in reply to a simple matter of elegance


I've not seen this suggested yet:

{ no strict qw(refs); foreach my $method ( keys %{ $self->{'data'} } ) { *{$method} = sub { my ( $self ) = @_; return $self->{'data'}->{$method}; }; } }
I've used this a few times in the past to generate repetitive object accessors/mutators.

Cheers, Tim

Update: I beg your pardon, snoopy beat me to it :-)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://642590]
[LanX]: whats the correct way to make a perlbug report for perldoc?
[erix]: chacka
[LanX]: with a diff? which perldoc version should I take from where?
[erix]: one would think: git clone git://perl5.git.
[LanX]: I have to clone it all ?
[LanX]: urban dictionry blocked

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (8)
As of 2017-04-24 15:20 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (442 votes). Check out past polls.