Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

friedo's scratchpad

by friedo (Prior)
on Jul 07, 2004 at 01:43 UTC ( #372242=scratchpad: print w/replies, xml ) Need Help??

friedo's scratchpad
package Friedo::Test; use strict; use warnings; use base 'Friedo'; our $VERSION = '0.01'; { # set up some defaults my %CLASSDATA = ( foo => 1, bar => 2, baz => 3 ); # install some generic class/instance accessors no strict 'refs'; for my $key(keys %CLASSDATA) { *$key = sub { my $i = shift; if(ref $i) { $CLASSDATA{$i}{$key} = shift if $_[0]; return $CLASSDATA{$i}{$key} or $CLASSDATA{$key}; } else { $CLASSDATA{$key} = shift if $_[0]; return $CLASSDATA{$key}; } }; } use strict 'refs'; } # constructor sub new { my $invocant = shift; my %args = @_; my $self = $invocant->SUPER::new; bless $self, ref($invocant) || $invocant; return $self->_init(\%args); } # initialize new object sub _init { my $self = shift; my $args = shift; # store our instance data foreach my $key(keys %{ $args }) { my $tmp = $key; $tmp =~ s/^-//; if($self->can($tmp)) { $self->$tmp($args->{$key}); } } return $self; }
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the universe expands...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2017-07-22 17:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I came, I saw, I ...
























    Results (340 votes). Check out past polls.