|
NAMEDancer::Session - session engine for the Dancer frameworkVERSIONversion 1.3513DESCRIPTIONThis module provides support for server-side sessions for the Dancer web framework. The session is accessible to the user via an abstraction layer implemented by the Dancer::Session class.USAGEConfigurationThe session engine must be first enabled in the environment settings, this can be done like the following:In the application code: # enabling the YAML-file-based session engine set session => 'YAML'; Or in config.yml or environments/$env.yml session: "YAML" By default sessions are disabled, you must enable them before using it. If the session engine is disabled, any Dancer::Session call will throw an exception. See "Configuration" in Dancer::Session::Abstract for more configuration options. Route HandlersWhen enabled, the session engine can be used in a route handler with the keyword session. This keyword allows you to store/retrieve values from the session by name.Storing a value into the session: session foo => 'bar'; Retrieving that value later: my $foo = session 'foo'; You can either look for an existing item in the session storage or modify one. Here is a simple example of two route handlers that implement basic "/login" and "/home" actions using the session engine. post '/login' => sub { # look for params and authenticate the user # ... if ($user) { session user_id => $user->id; } }; get '/home' => sub { # if a user is present in the session, let him go, otherwise redirect to # /login if (not session('user_id')) { redirect '/login'; } }; Of course, you probably don't want to have to duplicate the code to check whether the user is logged in for each route handler; there's an example in the Dancer::Cookbook showing how to use a before filter to check whether the user is logged in before all requests, and redirect to a login page if not. SUPPORTED ENGINESDancer has a modular session engine that makes implementing new session backends pretty easy. If you'd like to write your own, feel free to take a look at Dancer::Session::Abstract.The following engines are supported out-of-the-box (shipped with the core Dancer distribution):
Additionally, many more session engines are available from CPAN, including:
DEPENDENCYDancer::Session may depend on third-party modules, depending on the session engine used. See the session engine module for details.AUTHORSThis module has been written by Alexis Sukrieh. See the AUTHORS file that comes with this distribution for details.LICENSEThis module is free software and is released under the same terms as Perl itself.SEE ALSOSee Dancer for details about the complete framework.AUTHORDancer Core DevelopersCOPYRIGHT AND LICENSEThis software is copyright (c) 2010 by Alexis Sukrieh.This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
Visit the GSP FreeBSD Man Page Interface. |