NAME

CGI::Application::CodeRM - handles CODE references returned from Run Modes

VERSION 0.01

This version works for sure with CGI::APPLICATION 3.1 ONLY, while with other versions it may or may not work. Please update it if needed.

SYNOPSIS

# in Application module

# as usual
use base CGI::Application ;

# croak if not correct version (if it don't croak it works for sure)
use CGI::Application::CodeRM ;

# does not croak (may be it works however)
use CGI::Application::CodeRM qw(-force);

DESCRIPTION

This module adds a possibility to the plain CGI::Application module: instead of returning the output itself, a run mode can return a code reference that will print the output on its own. The refereced code will be called after the printing of the headers.

The main advantage is that you can avoid to charge the memory with the whole (and sometime huge) output and print it while it is produced.

This is particularly useful if you are using HTML::MagicTemplate, that can print with minimum memory requirements, but you can also use it with your own subroutines.

Warning: For obvious reasons, if your RM returns a code reference, the cgiapp_postrun() method will not be called even if defined (see cgiapp_postrun() in CGI::Application for details). In the case you have defined a cgiapp_postrun() method, your referenced code should handle this situation on its own.

How it works

This module override the CGI::Application run() method with its own (hacked) method. For this reason it works for sure ONLY with a specific CGI::Application version, but it may work anyway with other versions that implement the same run() method. You can force the import of the hacked method even if you use a different CGI::Application version if you use the -force directive at import (see "SYNOPSIS").

HTML::MagicTemplate hints

The following example uses the output() method that returns a reference to the template output, thus collecting the output in memory until printed by the CGI::Application module.

sub a_run_mode
{
  ....
  return $mt->output('/path/to/template')
}

The following example, instead, uses the print() method that is more memory efficient, because it prints the output during the process.

sub a_run_mode
{
  ....
  return sub{ $mt->print('/path/to/template') }
}

INSTALLATION

Prerequisites
Perl version >= 5.005
CPAN
perl -MCPAN -e 'install CGI::Application::CodeRM'
Standard installation

From the directory where this file is located, type:

perl Makefile.PL
make
make test
make install

SEE ALSO

SUPPORT and FEEDBACK

I would like to have just a line of feedback from everybody who tries or actually uses this module. PLEASE, write me any comment, suggestion or request. ;-)

More information about other modules at http://perl.4pro.net/?CGI::Application::CodeRM.

AUTHOR

Domizio Demichelis, <dd@4pro.net>.

COPYRIGHT

Copyright (c)2002 Domizio Demichelis. All Rights Reserved. This is free software; it may be used freely and redistributed for free providing this copyright header remains part of the software. You may not charge for the redistribution of this software. Selling this code without Domizio Demichelis' written permission is expressly forbidden.

This software may not be modified without first notifying the author (this is to enable me to track modifications). In all cases the copyright header should remain fully intact in all modifications.

This code is provided on an "As Is'' basis, without warranty, expressed or implied. The author disclaims all warranties with regard to this software, including all implied warranties of merchantability and fitness, in no event shall the author, be liable for any special, indirect or consequential damages or any damages whatsoever including but not limited to loss of use, data or profits. By using this software you agree to indemnify the author from any liability that might arise from it is use. Should this code prove defective, you assume the cost of any and all necessary repairs, servicing, correction and any other costs arising directly or indrectly from it is use.

The copyright notice must remain fully intact at all times. Use of this software or its output, constitutes acceptance of these terms.

BUGS

First release not very tested yet, but since it does a VERY simple thing, it has very little possibility to fail ;-).