Prancer::Context
The context gives you access to all pieces of a request from request parameters to cookies, sessions and headers. It can be used by calling context from anywhere in a package that extends Prancer::Application. Otherwise you must pass it to other packages to make it available.
context
use Prancer::Application qw(:all); use parent qw(Prancer::Application); sub handle { my ($self, $env) = @_; mount('GET', '/', sub { context->header(set => 'Content-Type', value => 'text/plain'); context->body("hello world"); context->finalize(200); }); return dispatch; }
Returns the PSGI environment for the request.
This is a magical wrapper to Prancer::template() in that it works by calling Prancer::template but it will merge params, config, and session into the list of template variables using their respective names as the first key. This allows you to write this in your template:
Prancer::template()
Prancer::template
params
config
session
<% params.bar %> <% config.foo.bar %> <% session.asdf.fdsa %>
This gives access to the session in various ways. For example:
my $does_foo_exist = context->session->has('foo'); my $foo = context->session->get('foo'); context->session->set('foo', 'bar'); context->session->remove('foo');
Changes made to the session are persisted immediately to whatever medium backs your sessions.
Returns the Prancer::Request object for the request.
Returns the Prancer::Response object that will be used to generate the response.
This gives access request and response headers. For example:
# get a request header my $useragent = context->header(get => 'user-agent'); # set a response header context->header(set => 'Content-Type', value => 'text/plain');
This gives access to request and response cookies. For example:
# get a request cookie my $foo = context->cookie(get => 'foo'); # set a response cookie context->cookie(set => 'foo', value => { 'value' => 'bar', 'domain' => '.example.com', });
This is a wrapper around the param method to Prancer::Request.
param
This is a wrapper around the params method to Prancer::Request.
This is a wrapper around the upload method to Prancer::Request.
upload
This is a wrapper around the uploads method to Prancer::Request.
uploads
This is a wrapper around the body method to Prancer::Response.
body
This is a wrapper around the finalize method to Prancer::Response.
finalize
To install Prancer, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Prancer
CPAN shell
perl -MCPAN -e shell install Prancer
For more information on module installation, please visit the detailed CPAN module installation guide.