blib/lib/Thunderhorse/Router/SpecializedCache.pm

filter: Statementstmt 100% 34 / 34 Branchbran 71.4% 10 / 14 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 7 / 7 Podpod n/a totaltotal 90.0% 54 / 60 CC 11 SCAR 15.5
CC
11
Cov
90%
retrieve
7.1
store
5.1
BEGIN
1.0
CRAP 4.7
« blib/lib/Thunderhorse/Config.pm ↑ Summary blib/lib/Gears/Template/TT.pm »
1 package Thunderhorse::Router::SpecializedCache;
2 1 $Thunderhorse::Router::SpecializedCache::VERSION = '0.107';
3 1 ▶use v5.40;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Mooish::Base -standard, -role;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use Gears::X::Thunderhorse;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 requires qw(
9 get
10 set
11 );
12  
13 1 has field 'router' => (
14 isa => InstanceOf ['Thunderhorse::Router'],
15 writer => 1,
16 weak_ref => 1,
17 );
18  
19 # store needs to clone
20 7 ▶my sub store ($matches)
Subroutine store: called CC=5 SCAR=16.3
21 {
22 7 ▶ return undef unless defined $matches;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $matches 0 7 7
23  
24 7 my @new_matches = $matches->@*;
25 7 foreach my $match (@new_matches) {
26 7 ▶ if ($match isa 'Gears::Router::Match') {
Branch: 2 branches
BranchTrueFalseTotal
if ($match isa 'Gears::Router::Match') { } 4 3 7
elsif (ref $match eq 'ARRAY') { } 3 0 3
27 4 $match = {
28 _match_class => ref $match,
29 location => $match->location->name,
30 matched => $match->matched,
31 };
32 }
33 elsif (ref $match eq 'ARRAY') {
34 3 $match = __SUB__->($match);
35 }
36 }
37  
38 7 return \@new_matches;
39 }
40  
41 15 ▶my sub retrieve ($router, $matches)
Subroutine retrieve: called CC=7 SCAR=19.6
42 {
43 15 ▶ return undef unless defined $matches;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $matches 5 10 15
44  
45 10 my @new_matches = $matches->@*;
46 10 foreach my $match (@new_matches) {
47 10 ▶ if (ref $match eq 'HASH' && $match->{_match_class}) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $match eq 'HASH' and $match->{'_match_class'}) { } 6 4 10
elsif (ref $match eq 'ARRAY') { } 4 0 4
Condition66%2/3
ref $match eq "HASH" and $match->{"_match_class"}
!ll&&!rl&&r
406
MC/DC50%1/2
ref $match eq "HASH" and $match->{"_match_class"}
ref $match eq "HASH" $match->{"_match_class"}
Truth table66%2/3
A and B
A= ref $match eq "HASH"B= $match->{"_match_class"}
ABresult
0X0
100
111
48 6 my %args = $match->%*;
49 6 my $class = delete $args{_match_class};
50 6 my $location = $args{location};
51 6 $args{location} = $router->find($location);
52  
53 # locations must be created in a deterministic order - otherwise,
54 # this error may occur
55 Gears::X::Thunderhorse->raise("invalid cached location $location")
56 6 ▶ unless $args{location};
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"location"} 0 6 6
57 6 $match = bless \%args, $class;
58 }
59 elsif (ref $match eq 'ARRAY') {
60 4 $match = __SUB__->($router, $match);
61 }
62 }
63  
64 10 return \@new_matches;
65 }
66  
67 4 ▶around set => sub ($orig, $self, $key, $value, @args) {
Subroutine __ANON__: called CC=1 SCAR=0.0
68 4 return $self->$orig($key, store($value), @args);
69 1 };
70  
71 11 ▶around get => sub ($orig, $self, @args) {
Subroutine __ANON__: called CC=1 SCAR=0.0
72 11 return retrieve($self->router, $self->$orig(@args));
73 1 };
74  
« blib/lib/Thunderhorse/Config.pm ↑ Summary blib/lib/Gears/Template/TT.pm »