Lightweight, Component-based, and Database-oriented Web Application Framework

About | Overview | Documentation


Documentation > Modules and APIs > GMM_CGI




The core module to handle CGI-data operations (GET/POST). It can also be used to handle cookie-data related operations. To alleviate CGI's data handling complexity and minimize dependencies on cookie-data operations, GMM_CGI module applied database cache on CGI's data to emulate state-full environment feature to the CGI parameters used in the application. In the context of Webman-framework's development strategies, for each subsequent accesses to the application, developers only need to pass the link ID and other altered or new created CGI parameters. Other previous non-altered CGI parameters passed will automatically mined out from database cache by GMM_CGI module itself and instantly available in the current active CGI runtime. For cookie-data, in most cases it will only be used to store user's session ID.



CPAN's Modules:

  • CGI::Cookies (Composition)
Webman-framework's Core Modules:
  • DB_Utilities (Composition)


1. Instantiation and Basic Parameter Setting

The $db_conn is an instance of database connection created using DBI module.

my $cgi = new GMM_CGI;


2. GMM_CGI Module and CGI Main Script

Basic skeleton code of main CGI script using GMM_CGI module member functions to handle HTML content output.

require GMM_CGI;

my $cgi = new GMM_CGI;


if (some condition...) {
    ### Must be called before $cgi->print_Header and page redirection will 
    ### only happen when $cgi->print_Header is called. 

### Uncomment the next line to implement it database cache on CGI-data.


$cgi->start_HTML($page_title, $page_properties);


### Print out all debug text added.


3. Cookie Handling

Functions to handle cookie-data. All these related cookie functions must be called before $cgi->print_Header function call.

$cgi->set_Cookie($name, $value);

4. CGI Parameter and Value

Get the current value of CGI variable named $param_name.

my $val = $cgi->param($param_name);

Same as above but also remove $param_name from the CGI variable list.
my $val = $cgi->param_Shift($param_name); 

Check if variable name $param_name is exist in the CGI variable list.
my $exist = $cgi->param_Exist($param_name);

Extract all CGI variables information from the list and add it into CGI debug text via call to $cgi->add_Debug_Text(...) function. All debug text added can be printed out latter as HTML content by calling $cgi->print_Debug_Text function (see section 2).
my @cgi_var_list = $cgi->var_Name;
foreach my $param_name (@cgi_var_list) {
    my $param_value = $cgi->param($param_name);

    $cgi->add_Debug_Text("$param_name = $param_value", __FILE__, __LINE__);    

Change the current value of CGI variable named $param_name to $param_value or add it if it's not exist yet.
if (!$cgi->set_Param_Val($param_name, $param_value)) {
    $cgi->add_Param($param_name, $param_value);

Function to simplify the previous operation to change or add (if not exist) CGI's variables and values.
$cgi->push_Param($param_name, $param_nvalue); 

5. File Upload

File names and their content, uploaded via "multipart/form-data" HTML form are simply stored in two different array variables. File names and their correspondent content can be retrieved by accessing items at the same index number from these two different array variables.

### Functions to access array variables that used store  
### the uploaded file names and their content.
my @file_name = $cgi->upl_File_Name;
my @file_content = $cgi->upl_File_Content;

for (my $i = 0; $i < @file_name; $i++) {
    my $fname = $file_name[$i];
    my $fcontent = $file_content[$i];
    ### Do whatever necessary such as saving $fcontent 
    ### as a file with name $fname. 

6. GET Data Format

Convert string value to CGI GET-data format. If $str has the value of "Hello world!" then $str_getfmt will has the value of "Hello+world!".

my $str_getfmt = $cgi->convert_GET_Format_CharToCode($str);