Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Strict and runtime sub names

by broquaint (Abbot)
on Sep 10, 2004 at 11:43 UTC ( #390034=note: print w/ replies, xml ) Need Help??


in reply to Strict and runtime sub names

I'd simply check if the subroutine exists and if so create the subroutine otherwise croak

use strict; use Carp 'croak'; sub AUTOLOAD { my($name) = $::AUTOLOAD =~ /::([^:'_]+)_$/; my $method = __PACKAGE__->can($name) || croak "Undefined subroutine &$::AUTOLOAD called"; no strict 'refs'; goto &{ *$name = $method }; } sub foo { print "got: @_\n" } foo_(qw/ some args/); __output__ got: some args
HTH

_________
broquaint


Comment on Re: Strict and runtime sub names
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (5)
As of 2015-07-04 10:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (59 votes), past polls