> -----Original Message-----
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Matt Lawrence
> Sent: 01 August 2003 16:20
> To: [EMAIL PROTECTED]
> Subject: Re: Calling subroutines.
> A nice simple way of doing that would be to have a hash of 
> valid values 
> for $method.
> 
> my %valid = (
>       'METH1' => 1,
>       'MyPkg::METH2' => 1
>     );
> 
> if ($method and $valid{$method}) {
>   {
>     no strict 'refs';
>     eval { &$method(@args) };
>   }
>   if ($@) {
>     my $args = join(', ', map {"'$_'"} @args);
>     warn "Error doing $method($args):[EMAIL PROTECTED]";
>   }
> }
> else {
>   die "Invalid method $method\n";
> }
> 
> That way you know that only "approved" subroutines can be called.
> 

Great thanks.

I had thought of doing that but it needs to know about subroutines that
another programmer may put in an entirely different package. (Basically
I will be the only one to have access to this code).
I guess I can just leave the hash off..... but that just doesn't feel
very secure.... maybe it's just me :)

Andy


Reply via email to