Henric has asked for the wisdom of the Perl Monks concerning the following question:
Hello, I'm writing a web framework and I try to imitate the convenient behaviour of PHP, where script parameters are always present under $_POST, $_GET or $_REQUEST. I'm using CGI::Lite to do this. I created a module called iPLib::iRequest.pm and what i want to do is to put this module in the target script after form submit, so that I don't have to create an CGI::Lite object in every script and retrieve the form parameters with CGI::Lite->parse_form_data().
My (for better explanation simplified) module-code looks like this:package iPLib::iRequest; require Exporter; our @ISA = qw(Exporter); our @EXPORT = qw($_POST); use warnings; use strict; use CGI::Lite; our $_POST; my $cgi = CGI::Lite->new(); $_POST = $cgi->parse_form_data('POST'); 1;
This module is included in my target script like this (don't care for the other modules):
use warnings; use strict; use CGI::Carp qw(fatalsToBrowser warningsToBrowser); use CGI::Cookie; use iPLib::iCFG; use iPLib::iDoc; use iPLib::iRequest; my $doc = iDoc->new( BodyOnLoad => 'iInitJS()'); $doc->iAddContent("<br>".$_POST->{'TESTNAME'}."<br>"); $doc->iDraw;
This does not work, I'm getting no warning or error messages, but form-parameter TESTNAME is empty or does not change after subsequent calls. When I use CGI::Lite directly, everything works perfect.
I think i have a basic misunderstanding when the module code is executed and the exported variable $_POST is initialized.
Can anyone help me on the way ?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to initialize a Global in a module
by moritz (Cardinal) on Oct 26, 2011 at 10:42 UTC | |
by Henric (Initiate) on Oct 26, 2011 at 12:43 UTC | |
by moritz (Cardinal) on Oct 26, 2011 at 13:03 UTC | |
|
Re: How to initialize a Global in a module
by Anonymous Monk on Oct 26, 2011 at 10:56 UTC | |
by Henric (Initiate) on Oct 26, 2011 at 12:48 UTC | |
by tye (Sage) on Oct 26, 2011 at 15:54 UTC | |
by Henric (Initiate) on Oct 26, 2011 at 19:36 UTC | |
by tye (Sage) on Oct 26, 2011 at 19:58 UTC | |
by Anonymous Monk on Oct 26, 2011 at 13:18 UTC | |
|
Re: How to initialize a Global in a module
by Anonymous Monk on Oct 26, 2011 at 14:00 UTC |