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 ?
In reply to How to initialize a Global in a module by Henric
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |