Controller - Root application controller/dispatcher
my ($cgi, $request, $headers, $content); BEGIN { Pinwheel::Controller::connect(':controller/:action/:id'); } $cgi = new CGI(); $request = { host => $ENV{'HTTP_HOST'}, path => $ENV{'PATH_INFO'}, base => '/' }; ($headers, $content) = Controller::dispatch($request); print $cgi->header(%$headers); print $content;
Dispatch an HTTP request to the appropriate controller package and return the generated headers and content.
Add a route to the list recognised by the application. See "connect" in Pinwheel::Mapper.
TODO, document me.
Generate a URL from a route (added with "connect"). See "generate" in Pinwheel::Mapper.
As well as the params allowed by $mapper->generate, the following additional params are supported:
$mapper->generate
Boolean; defaults to true.
Normally, URLs for this site will be partial, e.g. "/some/path". Setting only_path = 0> causes such URLs to become absolute, e.g. "http://host.example.com/some/path".
only_path =
Render a 302 redirect. The target URL (i.e. the "Location" header of the response) is found as follows:
The form redirect_to($url) is recognised by the fact that $url contains at least one "/". The url is prefixed by "http://" plus this request's "Host" header, unless $url matches m[^\w+://].
redirect_to($url)
$url
m[^\w+://]
Otherwise, the URL is found by calling url_for([NAME], PARAMS, only_path => 0).
url_for([NAME], PARAMS, only_path => 0)
Note: not exportable.
Before doing whatever it is that render_error does, it calls the sub given by $Controller::error_logger in void context with three arguments: STATUS, MESSAGE, and the error depth. (TODO: define the error depth).
render_error
$Controller::error_logger
$Controller::error_logger defaults to \&Controller::default_error_logger, which shows the error via Carp::cluck if the STATUS is 500.
\&Controller::default_error_logger
Carp::cluck
Calls render_error(404, MSG)
render_error(404, MSG)
Calls render_error(500, MSG)
render_error(500, MSG)
Returns the start time of the request, as specified by the 'time' argument to dispatch. (Hence, expressed as seconds since the epoch).
dispatch
Like request_time, but returns the answer as a Pinwheel::Model::Time object. (Always returns a new model object, so it's safe to modify the returned object if you wish).
request_time
Pinwheel::Model::Time
Adds headers via set_header such that the response expires $seconds seconds after the request time.
set_header
$seconds
Adds headers via set_header such that the response expires at the time specified by $time (which should be a Pinwheel::Model::Time object).
Adds headers via set_header such that the response expires now.
respond_to is called with an alternating list of (format-name, handler-coderef) pairs, except that each handler-coderef is optional. For example:
respond_to
respond_to('html', 'txt', 'xml' => \&xml_handler, 'json');
Once a format is selected (TODO, document this) the handler is then invoked; if no handler was specified, the following is used:
render(format => $format);
TODO, also document 404 "Format not supported" errors and the format stack.
Sets $format_param. This specifies the name of the route parameter used to select among multiple formats, as used by accepts and respond_to.
$format_param
accepts
The default format_param is "format".
Preloads all templates found under the templates_root.
Exported by default: url_for redirect_to render render_to_string render_404 render_500 set_header expires_in expires_at expires_now accepts respond_to params query_params
May be exported: connect dispatch format set_base_format set_format_param expand_static_path set_static_root set_templates_root request_time request_time_model
A&M Network Publishing <DLAMNetPub@bbc.co.uk>
To install Pinwheel, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Pinwheel
CPAN shell
perl -MCPAN -e shell install Pinwheel
For more information on module installation, please visit the detailed CPAN module installation guide.