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


Perl Version


Standard Modules

        Apache (when running under mod_perl only)

Nonstandard Modules

        CGI::Portable 0.50


Content of thin shell "" for CGI or Apache::Registry env:

        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( '' );
        $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 );



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.


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



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

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. The user_path() is always initialized from $ENV{'PATH_INFO'} by this method; if you want it to be from a query param then you can update it yourself later.

send_user_output( GLOBALS )

This method takes a CGI::Portable object as its first argument, GLOBALS, and sends to the user as much of the HTTP response and user output details that it can get from the object.

send_quick_html_response( CONTENT )

This method takes a string containing an HTML document as its first argument, CONTENT, and sends an http response appropriate for an HTML document which includes CONTENT as the http body.

send_quick_redirect_response( URL )

This method takes a string containing an url as its first argument, URL, and sends an http redirection header to send the client browser to that url.


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.

I am always interested in knowing how my work helps others, so if you put this module to use in any of your own products or services then I would appreciate (but not require) it if you send me the website url for said product or service, so I know who you are. Also, if you make non-proprietary changes to the module because it doesn't work the way you need, and you are willing to make these freely available, then please send me a copy so that I can roll desirable changes into the main release.

Address comments, suggestions, and bug reports to


perl(1), CGI::Portable, Apache.