File Coverage

blib/lib/Data/Session/ID/MD5.pm
Criterion Covered Total %
statement 23 25 92.0
branch n/a
condition 1 2 50.0
subroutine 8 9 88.8
pod 1 3 33.3
total 33 39 84.6


line stmt bran cond sub pod time code
1             package Data::Session::ID::MD5;
2              
3 2     2   1717 use parent 'Data::Session::ID';
  2         6  
  2         18  
4 2     2   131 no autovivification;
  2         5  
  2         13  
5 2     2   102 use strict;
  2         6  
  2         46  
6 2     2   10 use warnings;
  2         5  
  2         79  
7              
8 2     2   12 use Digest::MD5;
  2         5  
  2         90  
9              
10 2     2   13 use Hash::FieldHash ':all';
  2         5  
  2         924  
11              
12             our $errstr = '';
13             our $VERSION = '1.18';
14              
15             # -----------------------------------------------
16              
17             sub generate
18             {
19 20     20 0 57 my($self) = @_;
20              
21 20         848 return Digest::MD5 -> new -> add($$, time, rand(time) ) -> hexdigest;
22              
23             } # End of generate.
24              
25             # -----------------------------------------------
26              
27             sub id_length
28             {
29 0     0 0 0 my($self) = @_;
30              
31 0         0 return 32;
32              
33             } # End of id_length.
34              
35             # -----------------------------------------------
36              
37             sub new
38             {
39 35     35 1 325 my($class, %arg) = @_;
40 35   50     144 $arg{verbose} ||= 0;
41              
42 35         2873 return from_hash(bless({}, $class), \%arg);
43              
44             } # End of new.
45              
46             # -----------------------------------------------
47              
48             1;
49              
50             =pod
51              
52             =head1 NAME
53              
54             L - A persistent session manager
55              
56             =head1 Synopsis
57              
58             See L for details.
59              
60             =head1 Description
61              
62             L allows L to generate session ids using L.
63              
64             To use this module do this:
65              
66             =over 4
67              
68             =item o Specify an id generator of type MD5, as Data::Session -> new(type => '... id:MD5 ...')
69              
70             =back
71              
72             =head1 Case-sensitive Options
73              
74             See L for important information.
75              
76             =head1 Method: new()
77              
78             Creates a new object of type L.
79              
80             C takes a hash of key/value pairs, some of which might mandatory. Further, some combinations
81             might be mandatory.
82              
83             The keys are listed here in alphabetical order.
84              
85             They are lower-case because they are (also) method names, meaning they can be called to set or get
86             the value at any time.
87              
88             =over 4
89              
90             =item o verbose => $integer
91              
92             Print to STDERR more or less information.
93              
94             Typical values are 0, 1 and 2.
95              
96             This key is normally passed in as Data::Session -> new(verbose => $integer).
97              
98             This key is optional.
99              
100             =back
101              
102             =head1 Method: generate()
103              
104             Generates the next session id, or dies if it can't.
105              
106             The algorithm is Digest::MD5 -> new -> add($$, time, rand(time) ) -> hexdigest.
107              
108             Returns the new id.
109              
110             =head1 Method: id_length()
111              
112             Returns 32 because that's the number of hex digits in a MD5 digest.
113              
114             This can be used to generate the SQL to create the sessions table.
115              
116             See scripts/digest.pl.
117              
118             =head1 Support
119              
120             Log a bug on RT: L.
121              
122             =head1 Author
123              
124             L was written by Ron Savage Iron@savage.net.auE> in 2010.
125              
126             Home page: L.
127              
128             =head1 Copyright
129              
130             Australian copyright (c) 2010, Ron Savage.
131              
132             All Programs of mine are 'OSI Certified Open Source Software';
133             you can redistribute them and/or modify them under the terms of
134             The Artistic License, a copy of which is available at:
135             http://www.opensource.org/licenses/index.html
136              
137             =cut