| 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
| |||||||||||||||||||||
| 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'} || ''
MC/DC100%1/1
$r->{'ENV'}{'HTTP_REFERER'} || ''
$r->{'ENV'}{'HTTP_REFERER'}
Truth table100%2/2
A
A= $r->{'ENV'}{'HTTP_REFERER'}
| |||||||||||||||||||||
| 41 | 11 | ▶ | if ($referer !~ m{\A\w+://\Q$r->{host}\E[:/]}xms) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 42 | 10 | ▶ | $UG ||= Data::UUID->new(); | ||||||||||||||||||
|
Condition66%2/3
$UG ||= "Data::UUID"->new
MC/DC0%0/2
$UG ||= "Data::UUID"->new
$UG
"Data::UUID"->new
Truth table66%2/3
A ||= B
A= $UGB= "Data::UUID"->new
| |||||||||||||||||||||
| 43 | 10 | $self->{id} = $UG->create_b64(); | |||||||||||||||||||
| 44 | } | ||||||||||||||||||||
| 45 | } | ||||||||||||||||||||
| 46 | 11 | ▶ | if ($self->{id}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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'}) || {}
MC/DC100%1/1
unquote_hash($c->{'perm'}) || {}
unquote_hash($c->{'perm'})
Truth table100%2/2
A
A= unquote_hash($c->{'perm'})
| |||||||||||||||||||||
| 54 | 11 | ▶ | $self->{temp} = unquote_hash($c->{temp}) || {}; | ||||||||||||||||||
|
Condition100%2/2
unquote_hash($c->{'temp'}) || {}
MC/DC100%1/1
unquote_hash($c->{'temp'}) || {}
unquote_hash($c->{'temp'})
Truth table100%2/2
A
A= unquote_hash($c->{'temp'})
| |||||||||||||||||||||
| 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'
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'
| |||||||||||||||||||||
| 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__ | ||||||||||||||||||||