NAME
CGI::Mungo - Very simple CGI web framework
SYNOPSIS
use CGI::Mungo;
my $options = {
'responsePlugin' => 'Some::Class'
};
my $m = CGI::Mungo->new($options);
my $actions = {
"default" => sub{}, #do nothing
"list" => \&someSub(), #use a named sub
"add" => sub{my $var = 1;} #use an anonymous sub
};
$m->setActions($actions);
$m->run(); #do this thing!
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 }; 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.
- setActions()
-
my %actions = ( 'default' => \&showMenu(). 'list' => \%showList() ) $m->setActions(\%actions);
Sets the actions of the web application using a hash reference. The names of the keys in the hash reference will match the value of the given "action" form field from the current request. Hash reference values can be references to subs or annoymous subs.
An action of 'default' can be used when a visitor does not request a specific action.
- 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.
- 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.
- getThisUrl()
-
my $url = $m->getThisUrl();
Returns the full URL for the current script.
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.
Notes
To change the session prefix characters use the following code at the top of your script:
$CGI::Mungo::Session::prefix = "ABC";
Author
MacGyveR <dumb@cpan.org>
Development questions, bug reports, and patches are welcome to the above address
Copyright
Copyright (c) 2011 MacGyveR. All rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.