blib/lib/Tie/Cache/Autoupdater.pm

filter: Statementstmt 100% 52 / 52 Branchbran 100% 20 / 20 Conditioncond 100% 7 / 7 MC/DCmcdc 100% 4 / 4 Subroutinesub 100% 16 / 16 Podpod n/a totaltotal 100% 99 / 99 CC 14 SCAR 11.7
CC
14
Cov
100%
_fetch
7.0
TIEHASH
4.0
STORE
3.0
CRAP 3.2
↑ Summary
1 package Tie::Cache::Autoupdater;
2  
3 13 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 13 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 13 ▶use Storable 'dclone';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 13 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=6.9
9 13 eval { require Time::HiRes; };
10 13 ▶ Time::HiRes->import('time') unless $@;
Branch: 1 branch
BranchTrueFalseTotal
unless $@ 12 1 13
11 }
12  
13 13 our $VERSION = '0.22';
14  
15 14 ▶sub TIEHASH {
Subroutine TIEHASH: called CC=4 SCAR=13.9
16 14 my $class = shift;
17 14 my %structure = @_;
18  
19 14 my $self = {};
20 14 ▶ while ( my ($k, $v) = each %structure ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %structure) 16 14 30
21 $self->{ $k } = {
22 timeout => $v->{timeout} || 1,
23 source => $v->{source},
24 last => 0,
25 result => undef,
26 16 ▶ clone => $v->{clone} ? 1 : 0
Branch: 1 branch
BranchTrueFalseTotal
$v->{'clone'} ? : 3 13 16
Condition100%2/2
$v->{'timeout'} || 1
l!l
142
MC/DC100%1/1
$v->{'timeout'} || 1
$v->{'timeout'}
Truth table100%2/2
A
A= $v->{'timeout'}
Aresult
11
00
27 }
28 }
29  
30 14 bless $self, $class;
31 }
32  
33 82 ▶sub FETCH {
Subroutine FETCH: called CC=2 SCAR=6.9
34 82 my ( $self, $k ) = @_;
35  
36 82 ▶ return undef unless exists $self->{ $k };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{$k} 2 80 82
37 80 _fetch( $_[0], $k )
38 }
39  
40 14 ▶sub STORE {
Subroutine STORE: called CC=3 SCAR=11.0
41 14 my ( $self, $k, $v ) = @_;
42 $self->{ $k } = {
43 timeout => $v->{timeout} || 1,
44 source => $v->{source},
45 last => 0,
46 result => undef,
47 14 ▶ clone => $v->{clone} ? 1 : 0
Branch: 1 branch
BranchTrueFalseTotal
$v->{'clone'} ? : 1 13 14
Condition100%2/2
$v->{'timeout'} || 1
l!l
131
MC/DC100%1/1
$v->{'timeout'} || 1
$v->{'timeout'}
Truth table100%2/2
A
A= $v->{'timeout'}
Aresult
11
00
48 }
49 }
50  
51 4 ▶sub FIRSTKEY {
Subroutine FIRSTKEY: called CC=1 SCAR=0.0
52 4 keys %{$_[0]};
53 4 scalar each %{$_[0]}
54 }
55  
56 5 ▶sub NEXTKEY { scalar each %{$_[0]} }
Subroutine NEXTKEY: called CC=1 SCAR=0.0
57  
58 3 ▶sub EXISTS { exists $_[0]->{ $_[1] } }
Subroutine EXISTS: called CC=1 SCAR=0.0
59 1 ▶sub DELETE { delete $_[0]->{ $_[1] } }
Subroutine DELETE: called CC=1 SCAR=0.0
60 1 ▶sub CLEAR { %{ $_[0] } = () }
Subroutine CLEAR: called CC=1 SCAR=0.0
61 2 ▶sub SCALAR { scalar %{ $_[0] } }
Subroutine SCALAR: called CC=1 SCAR=0.0
62 1 ▶sub UNTIE { $_[0] = undef }
Subroutine UNTIE: called CC=1 SCAR=0.0
63 13 ▶sub DESTROY { return 1 }
Subroutine DESTROY: called CC=1 SCAR=0.0
64  
65 80 ▶sub _fetch {
Subroutine _fetch: called CC=7 SCAR=19.5
66 80 my ( $self, $k ) = @_;
67  
68 80 ▶ if ( $self->{$k}{last} + $self->{$k}{timeout} < time() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{$k}{"last"} + $self->{$k}{"timeout"} < &Tie::Cache::Autoupdater::time()) 50 30 80
69  
70 50 my @result = eval { $self->{$k}{source}->() };
71 50 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 3 47 50
72 3 warn qq/Check source subroutine for key $k. Error - $@\n/;
73 return undef
74 3 }
75  
76 47 ▶ if ( @result == 1 ) {
Branch: 2 branches
BranchTrueFalseTotal
if (@result == 1) { } 43 4 47
elsif (not @result) { } 1 3 4
77 43 $self->{$k}{result} = $result[0];
78 } elsif ( !@result ) {
79 1 $self->{$k}{result} = undef;
80 } else {
81 3 $self->{$k}{result} = \@result;
82 }
83  
84 47 $self->{$k}{last} = time();
85 }
86  
87 return $self->{$k}{clone} && ref $self->{$k}{result}
88 ? dclone($self->{$k}{result})
89 77 ▶ : $self->{$k}{result};
Branch: 1 branch
BranchTrueFalseTotal
$self->{$k}{'clone'} && ref $self->{$k}{'result'} ? : 8 69 77
Condition100%3/3
$self->{$k}{"clone"} and ref $self->{$k}{"result"}
!ll&&!rl&&r
6818
MC/DC100%2/2
$self->{$k}{"clone"} and ref $self->{$k}{"result"}
$self->{$k}{"clone"} ref $self->{$k}{"result"}
Truth table100%3/3
A and B
A= $self->{$k}{"clone"}B= ref $self->{$k}{"result"}
ABresult
0X0
100
111
90 }
91  
92 13 1;
93  
94 __END__
↑ Summary