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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.