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>
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.