CGI-Portable

 view release on metacpan or  search on metacpan

lib/CGI/Portable/AdapterCGI.pm  view on Meta::CPAN

=head1 NAME

CGI::Portable::AdapterCGI - Run under CGI, Apache::Registry, cmd line

=cut

######################################################################

package CGI::Portable::AdapterCGI;
require 5.004;

# Copyright (c) 1999-2004, Darren R. Duncan.  All rights reserved.  This module
# is free software; you can redistribute it and/or modify it under the same terms
# as Perl itself.  However, I do request that this copyright information and
# credits remain attached to the file.  If you modify this module and
# redistribute a changed version then please attach a note listing the
# modifications.  This module is available "as-is" and the author can not be held
# accountable for any problems resulting from its use.

use strict;
use warnings;
use vars qw($VERSION);
$VERSION = '0.50';

######################################################################

=head1 DEPENDENCIES

=head2 Perl Version

	5.004

=head2 Standard Modules

	Apache (when running under mod_perl only)

=head2 Nonstandard Modules

	CGI::Portable 0.50

=head1 SYNOPSIS

=head2 Content of thin shell "startup_cgi.pl" for CGI or Apache::Registry env:

	#!/usr/bin/perl
	use strict;
	use warnings;

	require CGI::Portable;
	my $globals = CGI::Portable->new();

	use Cwd;
	$globals->file_path_root( cwd() );  # let us default to current working directory
	$globals->file_path_delimiter( $^O=~/Mac/i ? ":" : $^O=~/Win/i ? "\\" : "/" );

	$globals->set_prefs( 'config.pl' );
	$globals->current_user_path_level( 1 );

	require CGI::Portable::AdapterCGI;
	my $io = CGI::Portable::AdapterCGI->new();

	$io->fetch_user_input( $globals );
	$globals->call_component( 'DemoAardvark' );
	$io->send_user_output( $globals );

	1;

=head1 DESCRIPTION

This Perl 5 object class is an adapter for CGI::Portable that takes care of the 
details for gathering user input and sending user output in a CGI environment.  
Perl scripts running under the CGI protocol communicate with the HTTP server 
through the global symbols named [%ENV, STDIN, STDOUT]; they read from the first 
two and write to the third one.  

The Perl module named Apache::Registry can also simulate a CGI environment while
running under mod_perl, with a few caveats.  CGI::Portable::AdapterCGI can sense
when it is running under Apache::Registry by checking $ENV{'GATEWAY_INTERFACE'}
and adjust its behaviour as appropriate.  Specifically, the output HTTP headers
are sent using an Apache method rather than through STDOUT.

If this module does not see a valid $ENV{'REQUEST_METHOD'} value then it will 
assume the script is being debugged on the command line and will either use 
existing shell arguments to simulate an HTTP request or it will prompt the user 
interactively for request details.  The response is sent using STDOUT as usual.

=head1 SYNTAX

This class does not export any functions or methods, so you need to call them
using object notation.  This means using B<Class-E<gt>function()> for functions
and B<$object-E<gt>method()> for methods.  If you are inheriting this class for
your own modules, then that often means something like B<$self-E<gt>method()>. 

=head1 FUNCTIONS AND METHODS

=head2 new()

This function creates a new CGI::Portable::AdapterCGI object and returns it.  
The new object has no properties, but only methods.

=cut

######################################################################

sub new {
	my $class = shift( @_ );
	my $self = bless( {}, ref($class) || $class );
	return( $self );
}

######################################################################

=head2 fetch_user_input( GLOBALS )

This method takes a CGI::Portable object as its first argument, GLOBALS, and 
feeds it all of the HTTP request and user input details that it can gather.  



( run in 0.800 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )