Serialize/sql_abstract.pm

filter: Statementstmt 100% 37 / 37 Branchbran 75.0% 6 / 8 Conditioncond 100% 4 / 4 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 2 totaltotal 93.1% 54 / 58 CC 11 SCAR 14.0
CC
11
Cov
96%
freeze
5.0
thaw
5.0
_time_to_iso8601
3.0
CRAP 4.1
« Driver/pure_sql.pm ↑ Summary
1 package CGI::Session::Serialize::sql_abstract;
2 1 require CGI::Session::ErrorHandler;
3 1 ▶use vars qw(@ISA $VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 @ISA = qw( CGI::Session::ErrorHandler );
6  
7 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 $VERSION = 0.70;
10  
11 # here's the kind of Perl -> SQL that's happening here
12  
13 # _SESSION_ID => session_id
14 # _SESSION_CTIME (seconds since epoch) => creation_time (as timestamp)
15 # _SESSION_ATIME (seconds since epoch) => last_access_time (as timestamp)
16 # _SESSION_ETIME (seconds) => duration (as interval)
17 # _SESSION_REMOTE_ADDR => remote_addr
18 # _SESSION_EXPIRE_LIST => {
19 # field_name => $seconds => field_name_exp_secs
20 # ...
21 # },
22  
23  
24 2 ▶sub freeze {
Subroutine freeze: called CC=5 SCAR=16.1
Pod undocumented
25 2 my ($self,$data) = @_;
26 2 ▶ return undef unless ref $data;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $data 0 2 2
27  
28 my %sql = (
29 session_id => $data->{_SESSION_ID},
30 creation_time => _time_to_iso8601($data->{_SESSION_CTIME}),
31 last_access_time => _time_to_iso8601($data->{_SESSION_ATIME}),
32 # 'ETIME' was such a bad name, we rename it to 'duration'
33 # I mean, ATIME and CTIMES are *times*, wouldn't you expect ETIME to be a time, too?
34 # Instead, it's a duration until expiration, it seconds
35 duration => ($data->{_SESSION_ETIME} && "$data->{_SESSION_ETIME} seconds"),
36 remote_addr => $data->{_SESSION_REMOTE_ADDR},
37 2 ▶ );
Condition100%2/2
$data->{'_SESSION_ETIME'} && "$data->{'_SESSION_ETIME'} seconds"
!ll
11
MC/DC100%1/1
$data->{'_SESSION_ETIME'} && "$data->{'_SESSION_ETIME'} seconds"
$data->{'_SESSION_ETIME'}
Truth table100%2/2
A
A= $data->{'_SESSION_ETIME'}
Aresult
00
11
38  
39 2 for my $field (keys %{ $data->{_SESSION_EXPIRE_LIST} }) {
40 2 $sql{$field.'_exp_secs'} = $data->{_SESSION_EXPIRE_LIST}->{$field};
41 }
42  
43 # pass the rest through unchanged
44 2 for (grep {!/^_SESSION/} keys %$data) {
45 2 $sql{$_} = $data->{$_};
46 }
47  
48 2 return \%sql;
49  
50 }
51  
52 # convert from seconds-from-epoch to ISO 8601 standard time format
53 6 ▶sub _time_to_iso8601 {
Subroutine _time_to_iso8601: called CC=3 SCAR=11.0
54 6 ▶ my $time = shift || return undef;
Condition100%2/2
shift() || (return undef)
l!l
51
MC/DC100%1/1
shift() || (return undef)
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
55 5 require Date::Calc;
56 5 import Date::Calc (qw/Localtime/);
57 # import Date::Calc (qw/Time_to_Date/);
58  
59 5 my ($y,$M,$d,$h,$m,$s) = Localtime($time);
60 # my ($y,$M,$d,$h,$m,$s) = Time_to_Date($time);
61  
62 # Sometimes bad dates return answers near the Epoch.
63 # Since this is a session handling module, sessions
64 # should never have dates over 30 years in the past...
65 5 ▶ if ($y <= 1970 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y <= 1970) { } 2 3 5
66 2 return undef;
67 }
68 else {
69 # 'YYYY-MM-DD HH:mm:SS'
70 3 return sprintf ('%04d-%02d-%02d %02d:%02d:%02d', $y,$M,$d,$h,$m,$s );
71 }
72  
73  
74  
75 }
76  
77  
78 # convert from the database format back to CGI::Session format
79 1 ▶sub thaw {
Subroutine thaw: called CC=5 SCAR=16.1
Pod undocumented
80 1 my ($self,$data) = @_;
81 1 ▶ return undef unless ref $data;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $data 0 1 1
82  
83 my %out = (
84 _SESSION_ID => $data->{session_id},
85 _SESSION_CTIME => $data->{creation_time}, # Times from DB should be in Epoch fmt already
86 _SESSION_ATIME => $data->{last_access_time},
87 _SESSION_ETIME => $data->{end_time},
88 _SESSION_REMOTE_ADDR => $data->{remote_addr},
89 1 );
90 1 for (keys %$data) {
91 7 ▶ if (/(.*)_exp_secs$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/(.*)_exp_secs$/) 1 6 7
92 1 $out{_SESSION_EXPIRE_LIST}->{$1} = $data->{$_};
93 }
94 }
95  
96 # pass the rest through unchanged
97 1 for (grep {!/^(session_id|creation_time|last_access_time|end_time|remote_addr)$|_exp_secs$/} keys %$data) {
98 1 $out{$_} = $data->{$_};
99 }
100  
101 1 return \%out;
102 }
103  
104 1 1;
« Driver/pure_sql.pm ↑ Summary