The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

NCGI - A Common Gateway Interface (CGI) Class

SYNOPSIS

  use NCGI;
  my $cgi  = NCGI->instance();
  my $html = $cgi->content;

  $html->_goto('head');
  $html->title('A Simple Example');

  $html->_goto('body');
  $html->h1('Simple Form');

  $html->form_open();
  $html->_add("What's your name? ");
  $html->input({type => 'text', name => 'name'});
  $html->input({type => 'submit', name => 'submit', value => 'Submit'});

  $html->form_close();
  $html->hr();

  if ($cgi->params{submit}) {
    $html->p('I think your name is ', $cgi->params{name});
  }

  $cgi->respond();

DESCRIPTION

NCGI has the same basic function as the well known CGI module. It is an aide for authors writing CGI scripts. The advantages over CGI are

 * Smaller Codebase
 * Modular Codebase: separate Header, XHTML, Query Classes
 * XML::API based for better output
 * Easy debugging features built-in
 * Different API

The disadvantages over CGI are

 * Different API
 * Less features
 * Probably not as portable

METHODS

As NCGI derives from NCGI::Query please see the NCGI::Query documentation for base methods.

instance( ... )

NCGI is a Singleton class. See Class::Singleton on CPAN for details on what this means. The instance function returns a reference to the singleton, creating it if necessary and accepting the following parameters:

on_warn

By default the Perl 'warn' function is overridden to include the warnings in the html response. If you want to turn this off you should set on_warn to 'undef'.

on_die

By default the Perl 'die' function is overridden to include the die arguments in the html response. If you want to turn this off you should set on_die to 'undef'.

header()

Returns the NCGI::Header object for this response

content()

Get/Set the content for the response to the user agent. This must be an object that supplies at a mimimum a _print method. By default this is an XML::API object with 'head' and 'body' elements already created.

respond()

Sends the header and the content back to the user agent. Will complain if called more than once.

SEE ALSO

NCGI::Singleton, NCGI::Header, NCGI::Query, XML::API, debug

AUTHOR

Mark Lawrence <nomad@null.net>

COPYRIGHT AND LICENSE

Copyright (C) 2005 Mark Lawrence <nomad@null.net>

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.