Dancer::Session(3pm)
π NAME π
Dancer::Session β the session engine for the Dancer framework, bestie. It's the whole vibe provider for keeping state around between requests. π
β VERSION β
version 1.3522 β yeah she's got a number and she's proud of it. π
πΈ DESCRIPTION πΈ
Okay so here's the tea: this module provides support for server-side sessions for the Dancer web framework. The session is accessible to you (the humble user) through an abstraction layer that's implemented by the Dancer::Session class. That's it, that's the whole point, and honestly? Iconic. β¨
π¦ USAGE π¦
π Configuration
First things first, babes β the session engine has to be enabled in the environment settings before literally anything works. You can do that like this:
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 β so you must enable them before using them, no skipping steps. And if the session engine is disabled, any Dancer::Session call will throw an exception. Not a vibe. π
For more configuration options, check out "Configuration" in Dancer::Session::Abstract.
π Route Handlers
Once it's enabled, the session engine can be used in a route handler with the keyword session. This keyword lets you store/retrieve values from the session by name. Chef's kiss. π«Ά
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's a simple example of two route handlers implementing 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';
}
};
And of course, you probably don't want to duplicate the code that checks whether the user is logged in for every single 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. Work smarter, not harder. π
π SUPPORTED ENGINES π
Dancer has a modular session engine, which makes implementing new session backends pretty easy. So if you'd like to write your own, feel free to take a look at Dancer::Session::Abstract. Go off, honestly. π
The following engines are supported out-of-the-box (shipped with the core Dancer distribution):
Dancer::Session::YAMLβ a YAML file-based session backend. Pretty convenient for development purposes, but maybe not the best for production needs. Great for vibing locally, less great when the stakes are real.Dancer::Session::Simpleβ a very simple session backend that holds all session data in memory. This means the sessions are volatile, and no longer exist when the process exits. This module is likely to be most useful for testing purposes, and of little use for production. Test-only energy, fr fr.
Additionally, many more session engines are available from CPAN, including:
Dancer::Session::Memcachedβ sessions are stored in Memcached servers. This is good for production matters and is a good way to use a fast, distributed session storage. If you may be scaling up to add additional servers later, this will be a good choice.Dancer::Session::Cookieβ this module implements a session engine for sessions stored entirely inside encrypted cookies (this engine doesn't use a server-side storage).Dancer::Session::Storableβ this backend stores sessions on disc usingStorable, which offers solid performance and reliable serialization of various data structures.Dancer::Session::MongoDBβ a backend to store sessions using MongoDB.Dancer::Session::KiokuDBβ a backend to store sessions using KiokuDB.Dancer::Session::PSGIβ letPlack::Middleware::Sessionhandle sessions; may be useful to share sessions between a Dancer app and other Plack-based apps.
π§ DEPENDENCY π§
Dancer::Session may depend on third-party modules, depending on the session engine used. See the session engine module for details. (iykyk β it's giving "read the docs of the thing you picked". π)
π AUTHORS π
This module has been written by Alexis Sukrieh. See the AUTHORS file that comes with this distribution for details. Credit where credit is due. π«Ά
πΈ LICENSE πΈ
This module is free software and is released under the same terms as Perl itself. π
β¨ SEE ALSO β¨
See Dancer for details about the complete framework. Main character energy, obviously. π
π AUTHOR π
Dancer Core Developers
π COPYRIGHT AND LICENSE π
This 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.
Okay that's the whole page bestie, slay, go build something cute with sessions β¨π¦π This was Dancer::Session, perl v5.40.1, dated 2026-05-05 β no cap, that's the whole footer, mwah π
π
π¦ where this page comes from
- ubuntu stonking: libdancer-perl 1.3522-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms