CGI::Application::Generator - Dynamically build CGI::Application modules


  use CGI::Application::Generator;

  # Required methods
  my $cat = CGI::Application::Generator->new();

  # Optional methods
  $cat->use_modules(qw/My::DBICreds My::Utilities/);

  # Output-related methods


CGI::Application::Generator provides a means by which a CGI::Application module can be created from code, as opposed to being written by hand. The goal of this module is two-fold:

  1. To ease the creation of new CGI::Application modules.
  2. To allow standardization of CGI::Application coding
     styles to be more uniformly applied.

It is also the hope of this module that Computer Assisted Software Engineering (CASE) tools will eventually emerge which will allow the development process for web-based applications to be greatly improved. These CASE tools could more easily convert visual notation (such as UML state-transition diagrams) into method calls to this module, thereby creating actual code.

What This Module Does Not Do

CGI::Application::Generator is intended to create a shell of an application module based on the specification you provide. It will not output a completely functional application without additional coding. It will, however, handle the creation of all the structural parts of your application common to all CGI::Application-based modules.

CGI::Application::Generator is not a system for HTML templates. If you're looking for a Perl module which will allow you to separate Perl from HTML then I recommend you download and install HTML::Template.



      my $cat = CGI::Application::Generator->new();

    Instantiate a new CGI::Application::Generator object. This object stores the state of your application module while you build it.


      my $package_name = $cat->package_name();

    Set or get the name of the package (Perl module name). This is the package name which will be assigned to your CGI::Application module.


      my $start_mode = $cat->start_mode();

    Set or get the name of the run-mode which will be assigned as "start mode" in the output CGI::Application module.


      $cat->run_modes(qw/show_form edit_widget delete_widget/);
      my @run_modes = $cat->run_modes();

    Set or get the list of run-modes in your module. This method expects an array (or array-ref).


      my $base_module = $cat->base_module();

    Set or get the name of the module from which your module will inherit. By default, this will be set to 'CGI::Application'.


      $cat->use_modules(qw/DBI Net::SMTP Data::FormValidator/);
      my @use_modules = $cat->use_modules();

    Set or get the list of Perl modules which should be included in your module.


      my $new_dbh_method = $cat->new_dbh_method();

    Set or get the code which creates a new DBI-compatible database handle ($dbh). If specified, the CGI::Application module will automatically call this code at run-time, in the setup() method, to connect to the database and store the database handle object reference in a CGI::Application param, 'DBH'. In teardown() this database handle will be disconnected. Access to the $dbh will be automatically set up in each run-mode method.


      my $tmpl_path = $cat->tmpl_path();

    Set or get the path in which the templates for your module will be stored.


      my $app_module_tmpl = $cat->app_module_tmpl();

    Set or get the path and filename of the HTML::Template which should be used by CGI::Application::Generator to create your Perl module. By default an internal template will be used. You may implement your own template if you want to have special output for your organization's programming style.


      my $module_source = $cat->output_app_module();

    The output_app_module() method returns a scalar containing the source code of the module you've specified. Generally, you would store this output in a file named "" which would then be used by your instance script.

    For example, the following code would build the shell of a basic CGI application via CGI::Application::Generator:

      use CGI::Application::Generator;
      my $c = CGI::Application::Generator->new();
      $c->run_modes(qw/show_form do_search view_details/);
      open(OUTPUT, ">") || die($!);
      print OUTPUT $c->output_app_module();


Jesse Erlbaum <>

Support Mailing List

If you have any questions, comments, bug reports or feature suggestions, post them to the support mailing list! To join the mailing list, simply send a blank message to "".


CGI::Application, HTML::Template, perl


CGI::Application::Generator - Dynamically build CGI::Application modules from template Copyright (C) 2003 Jesse Erlbaum <>

This module is free software; you can redistribute it and/or modify it under the terms of either:

a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version,


b) the "Artistic License" which comes with this module.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See either the GNU General Public License or the Artistic License for more details.

You should have received a copy of the Artistic License with this module, in the file ARTISTIC. If not, I'll be glad to provide one.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

1 POD Error

The following errors were encountered while parsing the POD:

Around line 85:

You can't have =items (as at line 100) unless the first thing after the =over is an =item