On Mon, 2005-03-14 at 10:27 -0600, Geoffrey G. Hankerson wrote:
> 3. Tony Frazier suggests
> my $subroutine = $self->run_modes->{$runmode};
>     if(!ref($subroutine) and $self->can($subroutine)) {
>       $self->$subroutine();
>     }
>     elsif(ref($subroutine) eq 'CODE' ) {
>       &$subroutine($self);
>     }
>     else {
>       die "Can't find runmode: $runmode";
>     }
> 
> Throows this error:
> Error executing run mode 'mode32': Can't use string ("21/32") as a HASH
> ref while "strict refs" in use at Supersite.pm line 683
> Line 683 is my $subroutine = $self->run_modes->{$runmode};

As others have pointed out: $self->run_modes returns a hash not a
hashref. You would have to replace the first line with the 2 lines:

my %rm_table = $self->runmodes;
my $subroutine = $rm_table{$runmode};

Also I was examining the CGI::Application source code and found out that
the code for explicitly handling coderef's had been removed so I did
some experimenting. The construct $object->$coderef() actually does what
you might think, so the if{ ... }else{ ... } in my suggestion is
redundant. The die() may not be though, if your getting the $runmode
from a HTTP query variable (ie. from the user (hidden though it may be))
you'll need to think twice about using it this way.


---------------------------------------------------------------------
Web Archive:  http://www.mail-archive.com/[email protected]/
              http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to