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