http://qs321.pair.com?node_id=372592

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks! I've run into yet another C::A puzzler. Specifically, I can create a $self->param() value in my CGI script and retrieve it in any non-setup() method. Why can't I retrieve the value in the setup() method? The docs say:
This function is a good place to define properties specific to your application via the $webapp->param() method.
Granted the doc example given only shows creation of properties rather than retrieval, but why shouldn't it work? Thanks in advance.

WebApp.cgi

#!/usr/local/bin/perl use WebApp; my $webapp = WebApp->new(); $webapp->param( 'var1' => 'val1' ); $webapp->param( 'var2' => 'val2' ); $webapp->run;

WebApp.pm

package WebApp; use base 'CGI::Application'; use strict; use warnings; my ( $var1, $var2 ); sub setup { my $self = shift; $self->start_mode( 'my_page' ); $self->run_modes([ 'my_page' ]); $var1 = $self->param( 'var1' ); } sub my_page { my $self = shift; $var2 = $self->param( 'var2' ); return "<p>var1: '$var1'</p>\n" . "<p>var2: '$var2'</p>\n"; } 1;

output

<p>var1: ''</p> <p>var2: 'val2'</p>