File Coverage

blib/lib/CGI/Application/Plugin/Authentication/Store/Session.pm
Criterion Covered Total %
statement 28 31 90.3
branch n/a
condition n/a
subroutine 7 8 87.5
pod 3 3 100.0
total 38 42 90.4


line stmt bran cond sub pod time code
1             package CGI::Application::Plugin::Authentication::Store::Session;
2             $CGI::Application::Plugin::Authentication::Store::Session::VERSION = '0.23';
3 3     3   19 use strict;
  3         5  
  3         76  
4 3     3   12 use warnings;
  3         4  
  3         81  
5              
6 3     3   13 use base qw(CGI::Application::Plugin::Authentication::Store);
  3         12  
  3         1250  
7              
8             =head1 NAME
9              
10             CGI::Application::Plugin::Authentication::Store::Session - Session based Store
11              
12             =head1 SYNOPSIS
13              
14             use base qw(CGI::Application);
15             use CGI::Application::Plugin::Session;
16             use CGI::Application::Plugin::Authentication;
17              
18             __PACKAGE__->authen->config(
19             STORE => 'Session',
20             );
21              
22             =head1 DESCRIPTION
23              
24             This module uses a session to store authentication information across multiple requests.
25             It depends on the L plugin being present. Actually,
26             it only requires that there be a 'session' method in the CGI::Application module that
27             will return a valid CGI::Session object.
28              
29             =head1 METHODS
30              
31             =head2 fetch
32              
33             This method accepts a list of parameters and fetches them from the session.
34              
35             =cut
36              
37             sub fetch {
38 41     41 1 62 my $self = shift;
39 41         94 my @params = @_;
40 41         82 my @items;
41 41         80 foreach my $param (@params) {
42 41         90 my $key = &_names_to_keys($param);
43 41         88 push @items, $self->_session->param($key);
44             }
45              
46 41         143097 return @items[0..$#items];
47             }
48              
49             =head2 save
50              
51             This method accepts a hash of parameters and values and saves them into the session.
52              
53             =cut
54              
55             sub save {
56 7     7 1 16 my $self = shift;
57 7         24 my %items = @_;
58 7         18 my $session = $self->_session;
59 7         62 while (my ($param, $value) = each %items) {
60 16         259 my $key = _names_to_keys($param);
61 16         38 $session->param( $key => $value );
62             }
63 7         202 return 1;
64             }
65              
66             =head2 delete
67              
68             This method accepts a list of parameters and deletes them from the session.
69              
70             =cut
71              
72             sub delete {
73 0     0 1 0 my $self = shift;
74 0         0 my @items = &_names_to_keys(@_);
75 0         0 $self->_session->clear(\@items);
76             }
77              
78             #
79             # Return the session object
80             #
81             sub _session {
82 48     48   133 return $_[0]->authen->_cgiapp->session;
83             }
84              
85             #
86             # We want all parameters in the session to have a common prefix
87             #
88             sub _names_to_keys {
89 57     57   96 my @names = @_;
90 57         91 my @keys = map { 'AUTH_'.uc($_) } @names;
  57         184  
91 57         151 return @keys[0..$#keys];
92             }
93              
94             =head1 SEE ALSO
95              
96             L, L, perl(1)
97              
98              
99             =head1 AUTHOR
100              
101             Cees Hek
102              
103              
104             =head1 LICENCE AND COPYRIGHT
105              
106             Copyright (c) 2005, SiteSuite. All rights reserved.
107              
108             This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
109              
110              
111             =head1 DISCLAIMER OF WARRANTY
112              
113             BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.
114              
115             IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
116              
117             =cut
118              
119             1;