Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Joining Module reference with its method named as string.

by djantzen (Priest)
on May 28, 2003 at 03:52 UTC ( [id://261202]=note: print w/replies, xml ) Need Help??


in reply to Joining Module reference with its method named as string.

Actually, because methods are looked up at runtime you can drop the eval altogether and just do $class->$invoke();. Of course this assumes you've already vetted the value of $invoke to ensure that it's 1) defined in the module; and 2) not a private method or otherwise unfit for use. To be on the safe side, probably using the BLOCK form of eval is the best way to go:

eval { $val = $class->$invoke() }; warn $@ if $@; # or something

BTW, it may work better to use an environment variable to indicate debugging mode rather than a harcoded string scattered about.


"The dead do not recognize context" -- Kai, Lexx

Replies are listed 'Best First'.
Re: Re: Joining Module reference with its method named as string.
by broquaint (Abbot) on May 28, 2003 at 08:47 UTC
    To be on the safe side, probably using the BLOCK form of eval is the best way to go
    Or better yet, just use can e.g
    sub foo { } my($class, $invoke) = qw/ main foo /; print "$class can $invoke" if UNIVERSAL::can($class, $invoke); __output__ yup

    HTH

    _________
    broquaint

Log In?
Username:
Password:

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

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

    No recent polls found