Gantry::Engine::CGI - CGI plugin ( or mixin )
use strict; use CGI::Carp qw(fatalsToBrowser); use MyApp qw( -Engine=CGI -TemplateEngine=Default ); use Gantry::Engine::CGI; my $cgi = Gantry::Engine::CGI->new( { locations => { '/' => 'MyApp', '/music' => 'MyApp::Music', }, config => { img_rootp => '/malcolm/images', css_rootp => '/malcolm/style', app_rootp => '/cgi-bin/theworld.cgi', } } ); # optional: templating variables $cgi->add_config( 'template_wrapper', 'wrapper.tt' ); $cgi->add_config( 'root', '/home/httpd/templates' ); # optional: database connection variables $cgi->add_config( 'dbconn', 'dbi:Pg:dbname=mydatabase' ); $cgi->add_config( 'dbuser','apache' ); # optional: add another location $cgi->add_location( '/music/artists', 'MyApp::Music::Artists' ); # Standard CGI $cgi->dispatch; # Fast-CGI use FCGI; my $request = FCGI::Request(); while( $request->Accept() >= 0 ) { $cgi->dispatch; }
Be sure add the nesscessary while loop around the cgi dispatch method call.
use FCGI; my $request = FCGI::Request(); while( $request->Accept() >= 0 ) { $cgi->dispatch; }
To enable Fast-CGI for Apache goto http://www.fastcgi.com/
Alias /cgi-bin/ "/home/httpd/cgi-bin/" <Location /cgi-bin> Options +ExecCGI AddHandler fastcgi-script cgi </Location>
This module is the binding between the Gantry framework and the CGI API. This particluar module contains the standard CGI specific bindings.
cgi object that can be used to dispatch request to corresonding
This method dispatchs the current request to the corresponding module.
Adds a configuration item to the cgi object
Adds a location to the cgi object
Used internally. Destroys posted form data.
Places all query string and form parameters into a hash, which it returns by reference.
Returns the hash reference of form and query string params.
Returns the hash reference of form and query string params unfiltered.
This method does nothing. It is here to conform the engine api. mod_perl engines return their apache request object in response to this method.
Returns the physical server this connection came in on (main server or vhost):
Delivers error output to the browser.
Dual accessor for the CGI::Simple object.
Dual accessor for updating the config hash in the CGI engine object.
This method is for plugins to use at the pre_init phase to catch XML requests and the like. It is imcompatible with normal form processing. For example Gantry::Plugins::SOAP::Doc uses it.
Returns the proper numerical code for DECLINED response.
The uri tail specific to this request. Returns:
$ENV{ PATH_INFO }, $self->config->location
Note that this a two element list.
Returns the name for the engine
For use during site object init, by Gantry.pm.
Does nothing, but meet the engine API.
Pass this method the name of a conf parameter you need. Returns the value for the parameter.
Returns the location for the current request.
Returns the HTTP method of the current request.
Returns the path info for the current request.
Returns the uri for the current request.
Returns the currently logged-in user.
returns a hash of url arguments.
/some/where?arg1=don&arg2=johnson
Returns the auth db handle (if there is one).
You should normally call get_config instead of this.
Used internally to store the config hash for a full page hit cycle.
If you are using Gantry::Conf, this will return the config hash reference for the current location.
These cache the Gantry::Conf config hash in a lexical hash. Override them if you want more persistent caching. These are instance methods. get receives the invoking object, the name of the GantryConfInstance, and the current location (for ease of use, its also in the invocant). set receives those plus the conf hash it should cache.
Returns the db handle (if there is one).
Returns whatever consume_post_body took from the post body. Use this if you also use a plugin that consumes the post body like Gantry::Plugins::SOAP::Doc does.
consume_post_body
Does nothing but meet the engine API. mod_perl engines use this.
Deprecated, merely calls response_headers (defined in Gantry.pm) for you, which you should have done yourself.
Change the value of a response header, or create a new one.
Returns the current host name from the HTTP_SERVER or the HTTP_HOST environment variables. HTTP_SERVER takes precedence.
Return whether the current request is being served by an SSL-enabled host.
Returns true if the current status is DECLINED, or false otherwise.
Prints text to STDERR so you can do the same thing under mod_perl without code changes.
Dual accessor for the locations hash passed to the constructor or built up with add_location.
Returns the IP address for the remote user
Returns port number in which the request came in on.
Prints whatever you pass to it.
Prints a redirection to the current header_out location.
Prints an error header and passes the value of $@ to custom_error.
Prints the header for the current content_type.
Returns the value set by the top-level ServerRoot directive
For internal use only. Stores the conf hash from Gantry::Conf so it doesn't have to be refetched during a single page hit.
You should use the dual accessor content_type supplied by Gantry.pm.
This method does nothing except meet the API. mod_perl engines use this to move the content type from the site object to the request object.
You should use the dual accessor no_cache supplied by Gantry.pm instead of this.
Transfers the no_cache flag from the site object to the cgi object.
Used by Gantry during site object init to transfer params from the cgi engine object to the site object.
Get or set the reply status for the client request. The Apache::Constants module provide mnemonic names for the status codes.
Does nothing but meet the engine API. mod_perl engines use it to report the numerical success code.
url_encode($value)
Accepts a value and returns it url encoded.
url_decode($value)
Accepts a value and returns it url decoded.
Uploads a file from the client's disk.
Parameter: The name of the file input element on the html form.
Returns: A hash with these keys:
a unique identifier for this upload
the base name of the file
the extension (file type) of the file
name.suffix
bytes in file
mime type of file
a handle you can read the file from
Gantry(3)
Tim Keefer <tkeefer@gmail.com>
Copyright (c) 2005-6, Tim Keefer.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.6 or, at your option, any later version of Perl 5 you may have available.
To install Gantry, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Gantry
CPAN shell
perl -MCPAN -e shell install Gantry
For more information on module installation, please visit the detailed CPAN module installation guide.