blib/lib/Plack/Session/Store/Transparent.pm

filter: Statementstmt 98.3% 61 / 62 Branchbran 61.1% 11 / 18 Conditioncond 33.3% 3 / 9 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 14 / 14 Podpod 100% 4 / 4 totaltotal 83.7% 93 / 111 CC 19 SCAR 14.5
CC
19
Cov
84%
new
8.1
_check_interface
6.6
fetch
4.0
CRAP 4.3
↑ Summary
1 package Plack::Session::Store::Transparent;
2 5 ▶use 5.008005;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 5 our $VERSION = "0.03";
9  
10 5 ▶use parent 'Plack::Session::Store';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 5 ▶use Plack::Util::Accessor qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
13 origin
14 cache
15 5 );
16  
17 21 ▶sub _check_interface {
Subroutine _check_interface: called CC=4 SCAR=18.9
18 21 my ($class, $obj) = @_;
19 21 ▶ return blessed $obj
Condition33%3/9
builtin::blessed($obj) && $obj->can('fetch') && $obj->can('store') && $obj->can('remove')
!ll&&!rl&&r
0021
builtin::blessed($obj) and $obj->can("fetch") and $obj->can("store")
!ll&&!rl&&r
0021
builtin::blessed($obj) and $obj->can("fetch")
!ll&&!rl&&r
0021
MC/DC0%0/4
builtin::blessed($obj) && $obj->can('fetch') && $obj->can('store') && $obj->can('remove')
builtin::blessed($obj) $obj->can("fetch") $obj->can("store") $obj->can('remove')
Truth table20%1/5
A and B and C && D
A= builtin::blessed($obj)B= $obj->can("fetch")C= $obj->can("store")D= $obj->can('remove')
ABCDresult
0XXX0
10XX0
110X0
11100
11111
20 && $obj->can('fetch')
21 && $obj->can('store')
22 && $obj->can('remove');
23 }
24  
25 7 ▶sub new {
Subroutine new: called CC=7 SCAR=21.0
Pod documented
26 7 my ($class, %args) = @_;
27  
28 7 ▶ unless ($args{origin}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args{"origin"}) 0 7 7
29 0 croak "missing mandatory parameter 'origin'";
30 }
31  
32
33 {
34 # check origin
35 7 croak 'origin requires fetch, store and remove method'
36 7 ▶ unless $class->_check_interface($args{origin});
Branch: 1 branch
BranchTrueFalseTotal
unless $class->_check_interface($args{"origin"}) 0 7 7
37  
38 # check cache
39 7 ▶ my @caches = ( ref($args{cache}) eq 'ARRAY' ? @{ $args{cache} } : $args{cache} );
Branch: 1 branch
BranchTrueFalseTotal
ref $args{'cache'} eq 'ARRAY' ? : 7 0 7
40 7 for (@caches) {
41 14 ▶ next unless $_;
Branch: 1 branch
BranchTrueFalseTotal
unless $_ 0 14 14
42 14 ▶ croak 'cache requires fetch, store and remove method'
Branch: 1 branch
BranchTrueFalseTotal
unless $class->_check_interface($_) 0 14 14
43 unless $class->_check_interface($_);
44 }
45 }
46  
47 7 return bless { %args }, $class;
48 }
49  
50 15 ▶sub fetch {
Subroutine fetch: called CC=4 SCAR=13.9
Pod documented
51 15 my ($self, $session_id) = @_;
52  
53 15 my @uppers;
54 15 for my $layer ($self->_layers) {
55 28 ▶ if (my $session = $layer->fetch($session_id)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $session = $layer->fetch($session_id)) 11 17 28
56 # ignore exceptions for availability
57 11 eval {
58 11 $_->store($session_id, $session) for @uppers;
59 };
60 11 return $session;
61 }
62 17 unshift(@uppers, $layer);
63 }
64  
65 4 return;
66 }
67  
68 13 ▶sub store {
Subroutine store: called CC=4 SCAR=13.9
Pod documented
69 13 my ($self, $session_id, $session) = @_;
70  
71 13 my @uppers;
72 13 for my $layer ($self->_layers) {
73 38 eval {
74 38 $layer->store($session_id, $session);
75 };
76 38 ▶ if (my $e = $@) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $e = $@) 1 37 38
77 1 $_->remove($session_id) for @uppers;
78 1 croak $e;
79 }
80  
81 37 push(@uppers, $layer);
82 }
83 }
84  
85 3 ▶sub remove {
Subroutine remove: called CC=2 SCAR=6.9
Pod documented
86 3 my ($self, $session_id) = @_;
87  
88 3 for my $layer ($self->_layers) {
89 8 $layer->remove($session_id);
90 }
91 }
92  
93 31 ▶sub _caches {
Subroutine _caches: called CC=3 SCAR=11.7
94 31 my ($self) = @_;
95 31 ▶ return [] unless $self->cache;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->cache 0 31 31
96 31 ▶ return ref($self->cache) eq 'ARRAY' ? $self->cache : [ $self->cache ];
Branch: 1 branch
BranchTrueFalseTotal
ref $self->cache eq 'ARRAY' ? : 31 0 31
97 }
98  
99 31 ▶sub _layers {
Subroutine _layers: called CC=1 SCAR=0.0
100 31 my ($self) = @_;
101 31 return (@{ $self->_caches }, $self->origin);
102 }
103  
104 5 1;
105 __END__
↑ Summary