in reply to Re: Calling OO-method From A Hash
in thread Calling OO-method From A Hash

Of course the truly paranoid will make sure that it's a valid method first.

my $method = $q->param( 'method' ); # ... or whatever if( my $m = $obj->can( $method ) ) { $obj->$m( @params ); } else { die "I can't call $method on a ", ref $obj; }

Replies are listed 'Best First'.
Re: Re: Re: Calling OO-method From A Hash
by tinita (Parson) on Mar 03, 2004 at 09:56 UTC
    beware of method names like "main::unsafe" for example. can() will return \&main::unsafe and not undef. this is also addressed in perlsec.pod.
    better will be checking in a dispatch table in case $method comes from outside.
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re^3: Calling OO-method From A Hash
by Anonymous Monk on Mar 03, 2004 at 03:06 UTC

    And the knowledgable would know that the extra code doesn't get you much, since calling an invalid method will die as it is...

      The more knowledgeable would realize the die was just an example and that they could replace it with code which gracefully handles the problem (perhaps redirecting to an error page, or listing the valid methods).

        The most knowledgeable would know that you are indeed correct and that I misspelled 'knowledgeable'. :)