NAME
CGI::Mungo - Very simple CGI web framework
SYNOPSIS
my $options = {
'responsePlugin' => 'Some::Class'
};
my $m = App->new($options);
$m->run(); #do this thing!
###########################
package App;
use base qw(CGI::Mungo);
sub handleDefault{
#add code here for landing page
}
DESCRIPTION
All action subs are passed a CGI::Mungo object as the only parameter, from this you should be able to reach everything you need.
METHODS
new(\%options)
my $options = {
'responsePlugin' => 'Some::Class',
'checkReferer' => 0,
'sessionClass' => 'Some::Class',
'requestClass' => 'Some::Class',
'SefUrls' => 0,
'debug' => 1
};
my $m = CGI::Mungo->new($options);
Constructor, requires a hash references to be passed as the only argument. This hash reference contains any general options for the framework.
getResponse()
my $response = $m->getResponse();
Returns an instance of the response plugin object, previously defined in the constructor options. See CGI::Mungo::Response for more details.
getSession()
my $session = $m->getSession();
Returns an instance of the CGI::Mungo::Session object.
getRequest()
my $request = $m->getRequest();
Returns an instance of the CGI::Mungo::Request object.
getAction()
my $action = $m->getAction();
Returns the curent action that the web application is performing. This is the current value of the "action" request form field or query string item.
If search engine friendly URLs are turned on the action will be determined from the last part of the script URL.
getFullUrl()
my $url = $m->getFullUrl();
Returns the full URL for the application.
getUrlForAction($action, $queryString)
my $url = $m->getUrlForAction("someAction", "a=b&c=d");
Returns the Full URL for the application with the given action and query string
run()
$m->run();
This methood is required for the web application to deal with the current request. It should be called after any setup is done.
If the response object decides that the response has not been modified then this method will not run any action functions.
The action sub run will be determined by first checking the actions hash if previously given to the object then by checking if a method prefixed with "handle" exists in the current class.
getOption("key")
my $value = $m->getOption("debug");
Returns the value of the configuration option given.
CONFIGURATION SUMMARY
The following list gives a summary of each Mungo configuration options.
responsePlugin
A scalar string consisting of the response class to use.
See CGI::Mungo::Response::Base for details on how to create your own response class, or a list of response classes provided in this package.
checkReferer
Flag to indicate if referer checking should be performed. When enabled an error will raised when the referer is not present or does not contain the server's hostname.
This option is enabled by default.
sessionClass
A scalar string consisting of the session class to use. Useful if you want to change the way session are stored.
Defaults to ref($self)::Session
requestClass
A scalar string consisting of the request class to use. Useful if you want to change the way requests are handled.
Defaults to ref($self)::Request
sefUrls
A boolean value indicating if search engine friendly URLS are to be used. The following .htaccess rewrite rule should be used:
RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ /cgi-bin/app.cgi [L]
debug
A boolean value indicating if debug mode is enabled. This can then be used in output views or code to print extra debug.
Notes
To change the session prefix characters use the following code at the top of your script:
$CGI::Mungo::Session::prefix = "ABC";
To change the session file save path use the following code at the top of your script:
$CGI::Mungo::Session::path = "/var/tmp";
Author
MacGyveR <dumb@cpan.org>
Development questions, bug reports, and patches are welcome to the above address
Copyright
Copyright (c) 2012 MacGyveR. All rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.