The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

NCGI - A Common Gateway Interface (CGI) Class

SYNOPSIS

  use NCGI;
  my $q = NCGI->query;
  my $x = NCGI->response->xhtml;

  $x->_set_lang('en');
  $x->_goto('head');
  $x->title('A Simple Example');

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

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

  $x->hr();

  if ($q->param('submit')) {
    $x->p('I think your name is ', $q->param('name'));
  }

  NCGI->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 module might be interesting 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 gives 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 or manage global objects.

The disadvantages of NCGI are

* Completely different API from CGI

* Probably not as portable

* Less features

METHODS

NCGI is a Singleton class. See Class::Singleton on CPAN if you are unfamiliar with Singltons. What this means is that you don't have to create an object before you use these methods, you can call them just like 'NCGI->query', and you can do this from any module and always get the same object back.

query

Returns the NCGI::Query object representing the inbound request from the browser.

q

A shortcut for query().

response

Returns the NCGI::Response object representing the reply. You can modify this object to generate output.

r

A shortcut for response().

on_warn

By default the Perl 'warn' function is overridden so that warnings are included xhtml response. If you want to turn this off you should set on_warn to '\&CORE::warn'.

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 '\&CORE::die'.

respond

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

frespond

Sends the header and a minimum length content back to the user agent using the _fast_string method from XML::API. Will complain if called more than once.

SEE ALSO

CGI::Simple, NCGI::Singleton, NCGI::Response::Header, NCGI::Query, NCGI::Response

COMPATABILITY

v0.05 to v0.06 was a major cleanup and a better separation of responsibility/function between the various modules. Some methods were removed from NCGI, some added to other modules. Since I don't know anyone actually using NCGI I'm willing to take the risk...

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