Gears/Router.pm

filter: Statementstmt 97.3% 36 / 37 Branchbran 100% 6 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 92.3% 12 / 13 Podpod 100% 5 / 5 totaltotal 96.7% 59 / 61 CC 6 SCAR 7.2
CC
6
Cov
98%
_match_level
4.0
flatten
3.0
_build_location
2.0
CRAP 2.1
« Gears/Config/Reader.pm ↑ Summary Gears/Role/HasContext.pm »
1 package Gears::Router;
2 5 $Gears::Router::VERSION = '0.105';
3 5 ▶use v5.40;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use Mooish::Base -standard;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 5 ▶use Gears::Router::Match;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 5 with qw(Gears::Router::Proto);
9  
10 # we are the router
11 has extended 'router' => (
12 init_arg => undef,
13 5 ▶ default => sub ($self) { $self },
Subroutine __ANON__: called CC=1 SCAR=0.0
14 5 );
15  
16 5 has param 'pattern_separator' => (
17 isa => StrLength [1],
18 default => '/',
19 );
20  
21 # base route is an empty string
22 54 ▶sub pattern ($self)
Subroutine pattern: called CC=1 SCAR=0.0
Pod documented
23 {
24 54 return '';
25 }
26  
27 # builds a new location - see Gears::Router::Proto
28 # - must create a new subclass of Gears::Router::Location, where %args are
29 # constructor arguments
30 # - must be reimplemented
31 0 ▶sub _build_location ($self, %args)
Subroutine _build_location: not called CC=1 SCAR=6.9
32 {
33 0 ...;
34 }
35  
36 # builds a new match
37 # can be reimplemented
38 331 ▶sub _build_match ($self, %args)
Subroutine _build_match: called CC=1 SCAR=0.0
39 {
40 331 return Gears::Router::Match->new(%args);
41 }
42  
43 392 ▶sub _match_level ($self, $locations, @args)
Subroutine _match_level: called CC=4 SCAR=13.9
44 {
45 392 my @matched;
46 392 foreach my $loc ($locations->@*) {
47 456 ▶ next unless my $match_data = $loc->compare(@args);
Branch: 1 branch
BranchTrueFalseTotal
unless my $match_data = $loc->compare(@args) 125 331 456
48 331 my $match = $self->_build_match(
49 location => $loc,
50 matched => $match_data,
51 );
52  
53 331 my $children = $loc->locations;
54 331 ▶ if ($children->@* > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$children > 0) { } 208 123 331
55 208 push @matched, [$match, $self->_match_level($children, @args)];
56 }
57 else {
58 123 push @matched, $match;
59 }
60 }
61  
62 392 return @matched;
63 }
64  
65 184 ▶sub _match ($self, @args)
Subroutine _match: called CC=1 SCAR=0.0
66 {
67 184 return [$self->_match_level($self->locations, @args)];
68 }
69  
70 sub match
71 182 ▶{
Subroutine match: called CC=1 SCAR=0.0
Pod documented
72 182 goto \&_match;
73 }
74  
75 2 ▶sub flat_match ($self, @args)
Subroutine flat_match: called CC=1 SCAR=0.0
Pod documented
76 {
77 2 my $matches = $self->_match(@args);
78 2 return $self->flatten($matches);
79 }
80  
81 100 ▶sub flatten ($self, $matches)
Subroutine flatten: called CC=3 SCAR=11.0
Pod documented
82 {
83 100 my @flat_matches;
84 100 foreach my $match ($matches->@*) {
85 199 ▶ if (ref $match eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $match eq 'ARRAY') { } 97 102 199
86 97 push @flat_matches, $self->flatten($match);
87 }
88 else {
89 102 push @flat_matches, $match;
90 }
91 }
92  
93 100 return @flat_matches;
94 }
95  
96 46 ▶sub clear ($self)
Subroutine clear: called CC=1 SCAR=0.0
Pod documented
97 {
98 46 $self->locations->@* = ();
99 46 return $self;
100 }
101  
102 __END__
« Gears/Config/Reader.pm ↑ Summary Gears/Role/HasContext.pm »