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 is an aide for authors writing CGI scripts. It has the same basic function as the well known CGI module although with a completely different interface.

WHEN TO USE NCGI?

NCGI does not make sense if you are already using and are comfortable with the standard CGI module. However if would like to easily produce standards-compliant XHTML using a proper object-oriented interface then this is the module for you.

The advantages of NCGI are:

* Has a true object oriented interface. The incoming query, the outgoing header and the outgoing content are all objects. The content object is modified via method calls mainting a true document object model. This give you the flexibility of creating content 'out of order'. Ie you can create a 'title' element inside the 'head' element and then add to the 'body' element, but go back later and add a 'link' to the 'head'.

* Will always produce valid (and nicely indented) XML as long as you use the API.

* Improved debugging - Warnings and 'die' statements are automatically added to the content object allieviating the head scratching that goes on when you receive an Internal Server Error. The content that you created up to this point is still displayed and the entire document is still conformant.

* Is based on a Singleton class (see Class::Singleton for a description) meaning that you can easily work with the same query/header/content objects from multiple modules without having to pass around strings.

The disadvantages of NCGI are

* Completely different API from CGI

* Probably not as portable

* Less features

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. 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

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

AUTHOR

Mark Lawrence <nomad@null.net>

Feel free to send me a mail telling me if you have used this module. Until now I'm the only known user...

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.