NAME
PSGI::Hector - Very simple PSGI web framework
SYNOPSIS
my $app = App->init({
'responsePlugin' => 'Some::Class',
});
###########################
###########################
package App;
use PSGI::Hector;
use parent qw(PSGI::Hector);
###########################
sub handleDefault{
#add code here for landing page
}
DESCRIPTION
All action subs are passed a PSGI::Hector object as the only parameter, from this you should be able to reach everything you need.
METHODS
init(\%options)
my $options = {
'responsePlugin' => 'Some::Class',
'checkReferer' => 0,
'sessionClass' => 'Some::Class',
'requestClass' => 'Some::Class',
'sefUrls' => 0,
'debug' => 1
};
my $h = PSGI::Hector->init($options);
Factory class method, used in creating the application from the app.psgi file. The return value from this method can be used where ever $app would be used.
This hash reference passed to the method contains any general options for the framework.
new(\%options, \%env)
my $options = {};
my $h = PSGI::Hector->new($options, $env);
Constructor, requires a hash references of options to be passed and the PSGI environment.
Usually this method is invoked from the init() class method.
getResponse()
my $response = $h->getResponse();
Returns the current instance of the response plugin object, previously defined in the constructor options. See PSGI::Hector::Response for more details.
getSession()
my $session = $h->getSession();
Returns the current instance of the PSGI::Hector::Session object.
getRequest()
my $request = $h->getRequest();
Returns the current instance of the PSGI::Hector::Request object.
getLog()
my $logger = $h->getLog();
returns an current instance of the PSGI::Hector::Log object.
getAction()
my $action = $h->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.
getUrlForAction($action, $queryString)
my $url = $h->getUrlForAction("someAction", "a=b&c=d");
Returns the URL for the application with the given action and query string.
getFullUrlForAction($action, $queryString)
my $url = $h->getFullUrlForAction("someAction", "a=b&c=d");
Returns the Full URL for the application with the given action and query string and hostname.
run()
$h->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 = $h->getOption("debug");
Returns the value of the configuration option given.
CONFIGURATION SUMMARY
The following list gives a summary of each Hector configuration options.
responsePlugin
A scalar string consisting of the response class to use.
See PSGI::Hector::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.
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:
$PSGI::Hector::Session::prefix = "ABC";
To change the session file save path use the following code at the top of your script:
$PSGI::Hector::Session::path = "/var/tmp";
Reverse proxies
To run your application behind a reverse proxy using apache, please use the following setup:
<Location /psgi>
RequestHeader set X-Forwarded-Script-Name /psgi
RequestHeader set X-Traversal-Path /
ProxyPass http://localhost:8080/
ProxyPassReverse http://localhost:8080/
</Location>
Author
MacGyveR <dumb@cpan.org>
Development questions, bug reports, and patches are welcome to the above address
See Also
Copyright
Copyright (c) 2017 MacGyveR. All rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.