Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Returing Multiple Items and possibly using an object

by Revelation (Deacon)
on Nov 18, 2002 at 02:12 UTC ( [id://213638]=note: print w/replies, xml ) Need Help??


in reply to Returing Multiple Items and possibly using an object

An alternate possibility would be to use the magic of the AUTOLOAD subroutine, to access data. This would allow for greater simplicity, when it comes to adding methods.
our $AUTOLOAD; sub AUTOLOAD { my $self = shift; ref($self) or return; # Non-OO/Not an autoloaded method..? return if ( $AUTOLOAD =~ /DESTROY/ ); # don't mess with garbage +collection ( my $method = $AUTOLOAD ) =~ s{.*::}{}; my ( $code, $name, $ATTRname ); if ( $method =~ /get_(\w+)/ ) { my $ATTRname = lc($1); # Could possibly do a check to make sure we have one of a group o +f specific # attributes with. # # if ( $ATTRname =~ /^(?:html_error_string|error_type|password_va +lid|user_id # |other|stuff|you|want|to|access)$/x # ) {} no strict qw{refs}; # create and register the method *{$AUTOLOAD} = sub { my $self = shift; return $self->{$ATTRname}; }; unshift @_, $self; goto &{$AUTOLOAD}; } return; }


Gyan Kapur
gyan.kapur@rhhllp.com

Replies are listed 'Best First'.
Re: Re: Returing Multiple Items and possibly using an object
by djantzen (Priest) on Nov 18, 2002 at 03:12 UTC

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (2)
As of 2024-04-26 05:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found