Chapter 1.3: CGI Script

A CGI script will be generated by help.pl. You can manually create it too.

#!/usr/bin/perl

use lib qw(/home/user/tutoperl/lib);

use strict;
use JSON;

use DBI;
use XML::LibXML;
use LWP::UserAgent;

use File::Find;
use Data::Dumper;
use URI;
use URI::Escape();
use Digest::HMAC_SHA1;
use MIME::Base64();
use Template;

use Genelet::Dispatch;

Genelet::Dispatch::run("/home/user/tutoperl/conf/config.json", "/home/user/tutoperl/lib", [qw(Table1 Table2)]);

exit;

The program loads the necessary 3rd-party modules, then calls run on Genelet::Dispatch to launch CGI or FCGI. There are 4 arguments you can pass to run, in the following order:

  1. The full path the configuration file.
  2. The library path of project’s Perl classes.
  3. By default, we assume all the directory names under the project classes are valid components. You can rewrite it by placing specific components here as a array reference.
  4. 1 for FCGI and 0 for CGI, which is the default. CGI is recommended for development.
  5. The maximal size in bytes for uploading files. The default is 3M bytes.
  6. A read-only hash reference, which you can setup once and used for all the FCGI children.