Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

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

Hi,

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 :-)


Comment on Re: a simple matter of elegance
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://642590]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2015-07-02 00:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (25 votes), past polls