[cgiapp] getter behavior for ->start_mode() ?

Rhesa Rozendaal perl at rhesa.com
Thu Feb 26 11:27:30 EST 2009


Terrence Brannon wrote:
> sub logout {
>     my($app)=@_;
> 
>     $app->authen->logout;
> 
>     $app->forward( $app->start_mode ); # would be nice!
> }
> 
> 
> instead I will declare a lexical variable for the Application package
> ($start_mode) and use it in both defining the start mode and forwarding to
> it.

The implementation of start_mode() suggests that this already works, and the 
following test script shows it does. I haven't checked what forward() would do 
if start_mode is a code ref.

Rhesa


use strict;
use warnings;

use Test::More tests => 2;

use CGI::Application;
$ENV{CGI_APP_RETURN_ONLY} = 1;

{
     package My::App;
     use base qw/CGI::Application/;

     sub setup {
         my $self = shift;
         $self->header_type('none');
         $self->start_mode('mode1');
         $self->run_modes([qw/ mode1 mode2 /]);
     }

     sub mode1 { 'mode1' }
     sub mode2 {
         my $self = shift;
         return 'start mode is ' . $self->start_mode;
     }
}

my $app = My::App->new;
is $app->run, 'mode1';
$app->mode_param( sub { 'mode2' } );
is $app->run, 'start mode is mode1';
__END__
1..2
ok 1
ok 2


More information about the cgiapp mailing list