PlackX-Framework
view release on metacpan or search on metacpan
lib/PlackX/Framework.pm view on Meta::CPAN
$response->flash('Goodbye!'); # Store message in a cookie
On the next request:
$request->flash; # Returns 'Goodbye!'.
During the response phase, the flash cookie is cleared, unless you set another
one.
=back
=head3 PlackX::Framework::Router
This module exports the route, base, global_filter, and filter functions
to give you a minimalistic web app controller DSL. You can import this into
your main app package, as shown in the introduction, or separate packages.
If you manually subclass this module, you can also customize the keywords.
# Set up the app
package MyApp {
use PlackX::Framework;
}
# Note: The name of your controller module doesn't matter, but it must
# import from your router subclass, e.g., MyApp::Router, not directly from
# PlackX::Framework::Router!
package MyApp::Controller {
use MyApp::Router;
base '/app';
global_filter before => sub {
# I will be executed for ANY route ANYWHERE in MyApp!
...
};
filter before => sub {
# I will only be executed for the routes listed below in this package.
...
};
route '/home' => sub {
...
};
route { post => '/login' } => sub {
...
};
}
Every route action is called with two arguments: a request object and response
object. The response object is provided for convenience as the application may
return it or a different response object, (or even another request object as
described in the re-routing feature of PlackX::Framework::Request).
Filters are also called the same way, but they should only return a response
object if they wish to stop request processing. If a filter returns a false
value ($response->next is provided for semantic convenience), request processing
continues to the next matching filter or route.
Note that unlike some other frameworks, routes CANNOT cascade, but filters can.
For more information, see L<PlackX::Framework::Router>.
=head3 PlackX::Framework::Router::Engine
The PlackX::Framework::Router::Engine is a subclass of Router::Boom with some
extra convenience methods. Normally, you would not have to use this module
directly. It is used by PlackX::Framework::Router internally.
=head3 PlackX::Framework::Config
This module is provided primarily for convenience. Currently not used by PXF
directly except you may optionally store template system configuration there.
For more information, see L<PlackX::Framework::Config>.
=head3 PlackX::Framework::Template
The PlackX::Framework::Template module can automatically load and set up
Template Toolkit, offering several convenience methods. If you desire to use
a different templating system from TT, you may override as many methods as
necessary in your subclass. A new instance of this class is generated for
each request by the app() method of PlackX::Framework::Handler.
During request handling, PlackX::Framework will check if templating has been
set up by checking if a ::Template module in your application's namespace has
been loaded. If so, it will automatically create an instance of the respective
::Template class and automatically add the template variables STASH, REQUEST,
and RESPONSE to the object.
For more information, see L<PlackX::Framework::Template>.
=head3 PlackX::Framework::URIx
The PlackX::Framework::URIx is a URI processing module with extended features,
and it is a subclass of URI::Fast. It is made available to your
your request objects through $request->urix (the x is to not confuse it
with the Plack::Request->uri() method). If you have not enabled the URIx
feature in your application, with the :URIx or :all tag, the request->urix
method will cause an error.
For more information, see L<PlackX::Framework::URIx>.
=head2 Middleware
You can trigger PlackX::Framework to build middleware into your app by defining
an apply_middleware sub in your root application. The sub will be passed a PSGI
code reference and should return a PSGI code reference. (This sub will be called
as a plain sub, not as a class or object method).
package MyApp {
use PlackX::Framework;
sub apply_middleware ($app) {
$app = Plack::Middleware::Alice->wrap($app, %options);
$app = Plack::Middleware::Bob->wrap($app, %options);
( run in 1.745 second using v1.01-cache-2.11-cpan-64ef6c95b5d )