Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: How can I use AUTOLOAD to magically define get and set methods for my member data?

by jeteve (Pilgrim)
on Apr 01, 2005 at 15:13 UTC ( [id://444212]=note: print w/replies, xml ) Need Help??


in reply to How can I use AUTOLOAD to magically define get and set methods for my member data?

Ok, for the non french reader, this is the AUTOLOAD method generating code :
sub AUTOLOAD{ my ($self,$value)= @_ ; return if $AUTOLOAD =~ /::DESTROY$/ ; my $attname = $AUTOLOAD; $attname =~ s/.*::// ; if(! exists $self->{$attname}){ Carp::confess("Attribute $attname does not exists in $self"); } my $pkg = ref($self ) ; my $code = qq{ package $pkg ; sub $attname { my \$self = shift ; \@_ ? \$self->{$attname} = shift : \$self->{$attname} ; } }; eval $code ; if( $@ ){ Carp::confess("Failed to create method $AUTOLOAD : $@"); } goto &$AUTOLOAD ; }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-03-29 09:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found