ples try:
sub setup{
my $self = shift;
....
....
$self->run_modes(
...
'AUTOLOAD' => \&err, # handle unknown run_mode
);
}
sub err {
my ($self, $requested_mode) = @_;
print STDERR "running AUTOLOAD\n";
return "invalid mode $requested_mode\n";
}
2008/4/16, [EMAIL PROTECTED] <[EMAIL PROTECTED]>:
>
> When creating an AUTOLOAD run mode, I wanted to name the method AUTOLOAD,
> so
> I set up my application module as:
>
>
> sub setup {
> my ($self) = @_;
> $self->run_modes([qw/mode1 mode2 AUTOLOAD/]);
> $self->start_mode("mode1");
> }
>
> sub mode1 { return "running mode1\n"; }
> sub mode2 { return "running mode2\n"; }
> sub AUTOLOAD {
> my ($self, $requested_mode) = @_;
> print STDERR "running AUTOLOAD\n";
> return "invalid mode $requested_mode\n";
> }
>
>
> However, it seems that in this case the AUTOLOAD method always runs after
> the appropriate run mode, and its second argument is undefined. For
> example:
>
>
> % ./app.pl rm=mode2
> Content-Type: text/html; charset=ISO-8859-1
>
> running mode2
> running AUTOLOAD
> Use of uninitialized value in concatenation (.) or string at
> ../lib/Credentials/App.pm line 18.
>
>
> % ./app.pl rm=foo
> running AUTOLOAD
> Content-Type: text/html; charset=ISO-8859-1
>
> invalid mode foo
> running AUTOLOAD
> Use of uninitialized value in concatenation (.) or string at
> ../lib/Credentials/App.pm line 18.
>
>
> If I name the AUTOLOAD method something else, things work as I expect:
>
>
> $self->run_modes(
> "mode1" => "mode1",
> "mode2" => "mode2",
> "AUTOLOAD" => "catchall"
> );
>
> sub catchall {
> ...
> }
>
>
> % ./app.pl rm=mode2
> Content-Type: text/html; charset=ISO-8859-1
>
> running mode2
>
>
> % ./app.pl rm=foo
> running AUTOLOAD
> Content-Type: text/html; charset=ISO-8859-1
>
> invalid mode foo
>
>
> Is this expected behavior, or is it a bug? Am I forced to name the
> AUTOLOAD
> method something other than AUTOLOAD? Is there some sort of interaction
> with
> Perl's own AUTOLOAD method?
>
> Thanks.
> Joey
>
> ##### CGI::Application community mailing list ################
> ## ##
> ## To unsubscribe, or change your message delivery options, ##
> ## visit: http://www.erlbaum.net/mailman/listinfo/cgiapp ##
> ## ##
> ## Web archive: http://www.erlbaum.net/pipermail/cgiapp/ ##
> ## Wiki: http://cgiapp.erlbaum.net/ ##
> ## ##
> ################################################################
>
>
##### CGI::Application community mailing list ################
## ##
## To unsubscribe, or change your message delivery options, ##
## visit: http://www.erlbaum.net/mailman/listinfo/cgiapp ##
## ##
## Web archive: http://www.erlbaum.net/pipermail/cgiapp/ ##
## Wiki: http://cgiapp.erlbaum.net/ ##
## ##
################################################################