Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
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 web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (11)
As of 2015-05-27 16:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    In my home, the TV remote control is ...









    Results (540 votes), past polls