| 1 | package Mojolicious::Plugin::Sessions3S; | ||||||||||||||||||||
| 2 | # ABSTRACT: Manage Sessions Storage, State and Sid generation in Mojolicious | ||||||||||||||||||||
| 3 | 3 | $Mojolicious::Plugin::Sessions3S::VERSION = '0.004'; | |||||||||||||||||||
| 4 | =head1 NAME | ||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | Mojolicious::Plugin::Sessions3S - Manage mojolicious sessions Storage, State and SID generation | ||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | =head1 DESCRIPTION | ||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | This plugins puts you in control of how your sessions are stored, how the state persists | ||||||||||||||||||||
| 11 | in the client browser and how session Ids are generated. | ||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | It provides a drop in replacement for the standard Mojolicious::Sessions mechanism and | ||||||||||||||||||||
| 14 | will NOT require any change of your application code (except the setup of course). | ||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | =head1 SYNOPSIS | ||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | $app->plugin( 'Sessions3S' => { | ||||||||||||||||||||
| 19 | state => .., | ||||||||||||||||||||
| 20 | storage => ..., | ||||||||||||||||||||
| 21 | sidgen => ... | ||||||||||||||||||||
| 22 | }); | ||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | See L<Mojolicious::Sessions::ThreeS> for the parameters description. | ||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | If no arguments are provided, this fallsback to the stock L<Mojolicious::Sessions> behaviour. | ||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | You can then use L<Mojolicious::Controller> session related methods (C<session>, C<flash>) as usual. | ||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | With the addition of the following methods (helpers): | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | =head2 session_id | ||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | Always returns the ID of the current session: | ||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | my $session_id = $c->session_id(); | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | =cut | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | 3 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 41 | 3 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 42 | 3 | ▶ | use Mojo::Base 'Mojolicious::Plugin'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | 3 | ▶ | use Mojolicious::Sessions::ThreeS; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | =head2 register | ||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | Implementation for L<Mojolicious::Plugin> base class | ||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | =cut | ||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | 3 | ▶ | sub register{ | ||||||||||||||||||
|
Subroutine
register: called CC=4 SCAR=14.6
Pod
documented
| |||||||||||||||||||||
| 53 | 3 | my ($self, $app, $args) = @_; | |||||||||||||||||||
| 54 | 3 | ▶ | $args ||= {}; | ||||||||||||||||||
|
Condition50%1/2
$args ||= {}
MC/DC0%0/1
$args ||= {}
$args
Truth table50%1/2
A
A= $args
| |||||||||||||||||||||
| 55 | 3 | ▶ | unless( ( ref($args) || '' ) eq 'HASH' ){ | ||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
ref $args || ''
MC/DC0%0/1
ref $args || ''
ref $args
Truth table50%1/2
A
A= ref $args
| |||||||||||||||||||||
| 56 | 0 | confess("Argument to ".ref($self)." should be an HashRef"); | |||||||||||||||||||
| 57 | } | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | # Inject the session manager in the Mojo::App: | ||||||||||||||||||||
| 60 | 3 | my $sessions_manager = Mojolicious::Sessions::ThreeS->new( $args ); | |||||||||||||||||||
| 61 | 3 | $app->sessions( $sessions_manager ); | |||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | # Install the helpers | ||||||||||||||||||||
| 64 | 4 | ▶ | $app->helper( session_id => sub{ | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 65 | 4 | my ($c) = @_; | |||||||||||||||||||
| 66 | 4 | return $sessions_manager->get_session_id( $c->session() , $c ); | |||||||||||||||||||
| 67 | 3 | } ); | |||||||||||||||||||
| 68 | } | ||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | =head1 COPYRIGHT | ||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | This is copyright Jerome Eteve (JETEVE) 2016 | ||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | With the support of Broadbean UK Ltd. L<http://www.broadbean.co.uk> | ||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | =cut | ||||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | 3 | 1; | |||||||||||||||||||