ZofCMS/Plugin/Session.pm

filter: Statementstmt 37.8% 14 / 37 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 66.6% 4 / 6 Podpod 0.0% 0 / 2 totaltotal 26.4% 18 / 68 CC 11 SCAR 45.1
CC
11
Cov
25%
process
132.0
new
2.0
BEGIN
1.0
CRAP 91.1
« ZofCMS/Plugin/AutoIMGSize.pm ↑ Summary ZofCMS/Plugin/Debug/Dumper.pm »
1 package App::ZofCMS::Plugin::Session;
2  
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 our $VERSION = '1.001010'; # VERSION
7  
8 1 ▶use Storable (qw/freeze thaw/);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use DBI;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 0 ▶sub new { bless {}, shift }
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
12  
13 0 ▶sub process {
Subroutine process: not called CC=11 SCAR=48.8
Pod undocumented
14 0 my ( $self, $template, $query, $config ) = @_;
15  
16 my %conf = (
17 #dsn => "DBI:mysql:database=test;host=localhost",
18 user => 'root',
19 pass => undef,
20 opt => { RaiseError => 1, AutoCommit => 1 },
21 table => 'session',
22 create_table => 0,
23 cookie_name => 'plug_session_id',
24 cookie_expiry => '+24h',
25 auto => 1,
26 cell => 'd',
27 key => 'session',
28 no_op => 0,
29 no_load => 0,
30 no_save => 0,
31 session_expiry => 86400, # 24 hours
32 0 ▶ %{ $config->conf->{plug_session} || {} },
Condition0%0/2
$config->conf->{'plug_session'} || {}
l!l
00
MC/DC0%0/1
$config->conf->{'plug_session'} || {}
$config->conf->{'plug_session'}
Truth table0%0/2
A
A= $config->conf->{'plug_session'}
Aresult
11
00
33 0 ▶ %{ $template->{plug_session} || {} },
Condition0%0/2
$template->{'plug_session'} || {}
l!l
00
MC/DC0%0/1
$template->{'plug_session'} || {}
$template->{'plug_session'}
Truth table0%0/2
A
A= $template->{'plug_session'}
Aresult
11
00
34 );
35  
36 return
37 0 ▶ if $conf{no_op};
Branch: 1 branch
BranchTrueFalseTotal
if $conf{"no_op"} 0 0 0
38  
39 my $dbh = DBI->connect_cached(
40 0 @conf{ qw/dsn user pass opt/ }
41 );
42  
43 0 ▶ if ( $conf{create_table} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($conf{"create_table"}) 0 0 0
44 0 $dbh->do(
45 "CREATE TABLE `$conf{table}` (
46 `id` TEXT,
47 `time` VARCHAR(10),
48 `data` TEXT
49 );",
50 );
51 }
52  
53 0 my $session_id = $config->cgi->cookie( $conf{cookie_name} );
54  
55 0 ▶ if ( $conf{auto} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($conf{"auto"}) 0 0 0
56 0 $template->{plug_session} = \%conf;
57 0 ▶ if ( defined $template->{d}{session} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $template->{'d'}{'session'}) { } 0 0 0
elsif (defined $session_id) { } 0 0 0
58  
59 0 ▶ if ( defined $session_id ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $session_id) { } 0 0 0
60 $dbh->do(
61 "UPDATE $conf{table} SET data = ?, time = ? WHERE id = ?",
62 undef,
63 0 freeze( $template->{d}{session} ),
64 time(),
65 $session_id,
66 );
67 }
68 else {
69 0 $session_id = rand() . time() . rand();
70 0 $session_id =~ tr/.//d;
71 my $cookie = $config->cgi->cookie(
72 -name => $conf{cookie_name},
73 -path => '/',
74 -value => $session_id,
75 -expires => $conf{cookie_expiry},
76 0 );
77 0 print "Set-Cookie: $cookie\n";
78  
79 $dbh->do(
80 "INSERT INTO $conf{table} VALUES( ?, ?, ? );",
81 undef,
82 $session_id,
83 time(),
84 0 freeze( $template->{ $conf{cell} }{ $conf{key} } ),
85 );
86 }
87  
88 $dbh->do(
89 "DELETE FROM $conf{table} WHERE time < ?",
90 undef,
91 time() - $conf{session_expiry},
92 0 );
93 }
94 elsif ( defined $session_id ) {
95 0 ▶ my $session = $dbh->selectall_arrayref(
Condition0%0/2
$dbh->selectall_arrayref("SELECT * FROM $conf{'table'} WHERE id = ?", {'Slice', {}}, $session_id) || []
l!l
00
MC/DC0%0/1
$dbh->selectall_arrayref("SELECT * FROM $conf{'table'} WHERE id = ?", {'Slice', {}}, $session_id) || []
$dbh->selectall_arrayref("SELECT * FROM $conf{'table'} WHERE id = ?", {'Slice', {}}, $session_id)
Truth table0%0/2
A
A= $dbh->selectall_arrayref("SELECT * FROM $conf{'table'} WHERE id = ?", {'Slice', {}}, $session_id)
Aresult
11
00
96 "SELECT * FROM $conf{table} WHERE id = ?",
97 { Slice => {} },
98 $session_id,
99 ) || [];
100  
101 @$session
102 0 ▶ and $template->{ $conf{cell} }{ $conf{key} } = thaw $session->[0]{data};
Branch: 1 branch
BranchTrueFalseTotal
@$session and $$template{$conf{"cell"}}{$conf{"key"}} = thaw($session->[0]{"data"}) 0 0 0
103 }
104 }
105 }
106  
107  
108 1 1;
109 __END__
« ZofCMS/Plugin/AutoIMGSize.pm ↑ Summary ZofCMS/Plugin/Debug/Dumper.pm »