Easy/Session.pm

filter: Statementstmt 98.1% 53 / 54 Branchbran 83.3% 5 / 6 Conditioncond 75.0% 9 / 12 MC/DCmcdc 42.8% 3 / 7 Subroutinesub 100% 11 / 11 Podpod 100% 2 / 2 totaltotal 90.2% 83 / 92 CC 9 SCAR 14.1
CC
9
Cov
93%
_init
8.1
save
2.0
BEGIN
1.0
CRAP 4.1
« Easy/Headers.pm ↑ Summary Easy.pm »
1 package CGI::Easy::Session;
2 2 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 our $VERSION = 'v2.0.1';
9  
10 2 ▶use Data::UUID;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use CGI::Easy::Util qw( quote_list unquote_hash );
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 2 ▶use constant SESSION_EXPIRE => 365*24*60*60; # 1 year
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 2 my $UG;
16  
17  
18 11 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
19 11 my ($class, $r, $h) = @_;
20 11 my $self = {
21 id => undef,
22 perm => undef,
23 temp => undef,
24 _r => $r,
25 _h => $h,
26 };
27 11 bless $self, $class;
28 11 $self->_init;
29 11 return $self;
30 }
31  
32 11 ▶sub _init {
Subroutine _init: called CC=8 SCAR=20.9
33 11 my ($self) = @_;
34 11 my $r = $self->{_r};
35 11 my $c = $r->{cookie};
36 11 ▶ if ($c->{sid}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->{'sid'}) { } 0 11 11
37 0 $self->{id} = $c->{sid};
38 }
39 else {
40 11 ▶ my $referer = $r->{ENV}{HTTP_REFERER} || q{};
Condition100%2/2
$r->{'ENV'}{'HTTP_REFERER'} || ''
l!l
110
MC/DC100%1/1
$r->{'ENV'}{'HTTP_REFERER'} || ''
$r->{'ENV'}{'HTTP_REFERER'}
Truth table100%2/2
A
A= $r->{'ENV'}{'HTTP_REFERER'}
Aresult
11
00
41 11 ▶ if ($referer !~ m{\A\w+://\Q$r->{host}\E[:/]}xms) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($referer =~ m[\A\w+://\Q$r->{"host"}\E[:/]]msx) 10 1 11
42 10 ▶ $UG ||= Data::UUID->new();
Condition66%2/3
$UG ||= "Data::UUID"->new
l!l&&r!l&&!r
910
MC/DC0%0/2
$UG ||= "Data::UUID"->new
$UG "Data::UUID"->new
Truth table66%2/3
A ||= B
A= $UGB= "Data::UUID"->new
ABresult
1X1
011
000
43 10 $self->{id} = $UG->create_b64();
44 }
45 }
46 11 ▶ if ($self->{id}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"id"}) 10 1 11
47 $self->{_h}->add_cookie({
48 name => 'sid',
49 value => $self->{id},
50 10 expires => time + SESSION_EXPIRE,
51 });
52 }
53 11 ▶ $self->{perm} = unquote_hash($c->{perm}) || {};
Condition100%2/2
unquote_hash($c->{'perm'}) || {}
l!l
110
MC/DC100%1/1
unquote_hash($c->{'perm'}) || {}
unquote_hash($c->{'perm'})
Truth table100%2/2
A
A= unquote_hash($c->{'perm'})
Aresult
11
00
54 11 ▶ $self->{temp} = unquote_hash($c->{temp}) || {};
Condition100%2/2
unquote_hash($c->{'temp'}) || {}
l!l
29
MC/DC100%1/1
unquote_hash($c->{'temp'}) || {}
unquote_hash($c->{'temp'})
Truth table100%2/2
A
A= unquote_hash($c->{'temp'})
Aresult
11
00
55 11 return;
56 }
57  
58 2 ▶sub save {
Subroutine save: called CC=2 SCAR=7.0
Pod documented
59 2 my ($self) = @_;
60 2 my $h = $self->{_h};
61 2 ▶ my @other_cookies = grep {$_->{name} ne 'perm' && $_->{name} ne 'temp'}
Condition33%1/3
$_->{'name'} ne 'perm' && $_->{'name'} ne 'temp'
!ll&&!rl&&r
002
MC/DC0%0/2
$_->{'name'} ne 'perm' && $_->{'name'} ne 'temp'
$_->{'name'} ne 'perm' $_->{'name'} ne 'temp'
Truth table33%1/3
A && B
A= $_->{'name'} ne 'perm'B= $_->{'name'} ne 'temp'
ABresult
0X0
100
111
62 2 @{ $h->{'Set-Cookie'} };
63 $h->{'Set-Cookie'} = [
64 @other_cookies,
65 {
66 name => 'perm',
67 2 value => quote_list(%{ $self->{perm} }),
68 expires => time + SESSION_EXPIRE,
69 },
70 {
71 name => 'temp',
72 2 value => quote_list(%{ $self->{temp} }),
73 },
74 ];
75 2 return;
76 }
77  
78  
79 2 1; # Magic true value required at end of module
80 __END__
« Easy/Headers.pm ↑ Summary Easy.pm »