| 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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
ref $match eq "HASH" and $match->{"_match_class"}
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"}
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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 | |||||||||||||||||||||||||||||||||