Dancer::Core::Role::SessionFactory - Role for session factories
version 2.0000_01
Any class that consumes this role will be able to store, create, retrieve and destroy session objects.
The name of the cookie to create for storing the session key
Defaults to dancer.session
dancer.session
The domain of the cookie to create for storing the session key. Defaults to the empty string and is unused as a result.
The path of the cookie to create for storing the session key. Defaults to "/".
Default duration before session cookie expiration. If set, the Dancer::Core::Session expires attribute will be set to the current time plus this duration.
expires
Boolean flag to tell if the session cookie is secure or not.
Default is false.
Boolean flag to tell if the session cookie is http only.
Default is true.
Following is the interface provided by this role. When specified the required methods to implement are described.
Create a brand new session object and store it. Returns the newly created session object.
Triggers an exception if the session is unable to be created.
my $session = MySessionFactory->create();
This method does not need to be implemented in the class.
Returns a randomly-generated, guaranteed-unique string. (It is not guaranteed cryptographically secure, but it's still reasonably strong for general use.) This method is used internally by create() to set the session ID.
This method does not need to be implemented in the class unless an alternative method for session ID generation is desired.
Return the session object corresponding to the session ID given. If none is found, triggers an exception.
my $session = MySessionFactory->retrieve(id => $id);
The method _retrieve must be implemented. It must take $id as a single argument and must return a hash reference of session data.
_retrieve
$id
Purges the session object that matches the ID given. Returns the ID of the destroyed session if succeeded, triggers an exception otherwise.
MySessionFactory->destroy(id => $id);
The _destroy method must be implemented. It must take $id as a single argumenet and destroy the underlying data.
_destroy
Make sure the session object is stored in the factory's backend. This method is called to notify the backend about the change in the session object.
An exception is triggered if the session is unable to be updated in the backend.
MySessionFactory->flush(session => $session);
The _flush method must be implemented. It must take two arguments: the $id and a hash reference of session data.
_flush
Coerce a session object into a Dancer::Core::Cookie object.
MySessionFactory->cookie(session => $session);
Return a list of all session IDs stored in the backend. Useful to create cleaning scripts, in conjunction with session's creation time.
The _sessions method must be implemented. It must return an array reference of session IDs (or an empty array reference).
_sessions
Dancer Core Developers
This software is copyright (c) 2012 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.
To install Dancer, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Dancer
CPAN shell
perl -MCPAN -e shell install Dancer
For more information on module installation, please visit the detailed CPAN module installation guide.