Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Generic/Variable/Dynamic Subroutines? (Not a redefine)

by shmem (Chancellor)
on Aug 18, 2017 at 19:28 UTC ( [id://1197628]=note: print w/replies, xml ) Need Help??


in reply to Generic/Variable/Dynamic Subroutines? (Not a redefine)

Just pass the method into the sub:

sub Call { my $self = shift; my $method = shift; my $it = $self->OStream->$method($_[0]); $self->Trace(_CallerStr($it)); return $it; };

If you want to call the methods by their name without them being defined, there is AUTOLOAD:

our $AUTOLOAD; # needs to be a package global sub AUTOLOAD { $AUTOLOAD =~ s/.*:://; # strip package name return if $AUTOLOAD eq 'DESTROY'; splice @_, 1, 0, $AUTOLOAD; # package/object, method, rest of args goto \&Call; }
perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2024-04-18 15:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found