File Coverage

blib/lib/Mojolicious/Plugin/Sessions3S.pm
Criterion Covered Total %
statement 20 21 95.2
branch 1 2 50.0
condition 2 4 50.0
subroutine 6 6 100.0
pod 1 1 100.0
total 30 34 88.2


line stmt bran cond sub pod time code
1             package Mojolicious::Plugin::Sessions3S;
2             # ABSTRACT: Manage Sessions Storage, State and Sid generation in Mojolicious
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 for the parameters description.
25              
26             If no arguments are provided, this fallsback to the stock L behaviour.
27              
28             You can then use L session related methods (C, C) 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 2     2   57470 use strict;
  2         4  
  2         48  
41 2     2   8 use warnings;
  2         2  
  2         48  
42 2     2   7 use Mojo::Base 'Mojolicious::Plugin';
  2         6  
  2         13  
43              
44 2     2   1097 use Mojolicious::Sessions::ThreeS;
  2         4  
  2         13  
45              
46             =head2 register
47              
48             Implementation for L base class
49              
50             =cut
51              
52             sub register{
53 3     3 1 2615 my ($self, $app, $args) = @_;
54 3   50     9 $args ||= {};
55 3 50 50     15 unless( ( ref($args) || '' ) eq 'HASH' ){
56 0         0 confess("Argument to ".ref($self)." should be an HashRef");
57             }
58              
59             # Inject the session manager in the Mojo::App:
60 3         12 my $sessions_manager = Mojolicious::Sessions::ThreeS->new( $args );
61 3         14 $app->sessions( $sessions_manager );
62              
63             # Install the helpers
64             $app->helper( session_id => sub{
65 4     4   218 my ($c) = @_;
66 4         12 return $sessions_manager->get_session_id( $c->session() , $c );
67 3         31 } );
68             }
69              
70             =head1 COPYRIGHT
71              
72             This is copyright Jerome Eteve (JETEVE) 2016
73              
74             With the support of Broadbean UK Ltd. L
75              
76             =cut
77              
78             1;