| 1 | package Gears::Router; | ||||||||||
| 2 | 4 | $Gears::Router::VERSION = '0.103'; | |||||||||
| 3 | 4 | ▶ | use v5.40; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 4 | ▶ | use Mooish::Base -standard; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 4 | ▶ | use Gears::Router::Match; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 4 | with qw(Gears::Router::Proto); | |||||||||
| 9 | |||||||||||
| 10 | # we are the router | ||||||||||
| 11 | ▶ | has extended 'router' => ( | |||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 12 | init_arg => undef, | ||||||||||
| 13 | 4 | default => sub ($self) { $self }, | |||||||||
| 14 | 4 | ); | |||||||||
| 15 | |||||||||||
| 16 | # base route is an empty string | ||||||||||
| 17 | sub pattern ($self) | ||||||||||
| 18 | ▶ | { | |||||||||
|
Subroutine
pattern: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 19 | 43 | return ''; | |||||||||
| 20 | } | ||||||||||
| 21 | |||||||||||
| 22 | # builds a new location - see Gears::Router::Proto | ||||||||||
| 23 | # - must create a new subclass of Gears::Router::Location, where %args are | ||||||||||
| 24 | # constructor arguments | ||||||||||
| 25 | # - must be reimplemented | ||||||||||
| 26 | sub _build_location ($self, %args) | ||||||||||
| 27 | ▶ | { | |||||||||
|
Subroutine
_build_location: not called CC=1 SCAR=6.9
| |||||||||||
| 28 | 0 | ...; | |||||||||
| 29 | } | ||||||||||
| 30 | |||||||||||
| 31 | # builds a new match | ||||||||||
| 32 | # can be reimplemented | ||||||||||
| 33 | sub _build_match ($self, %args) | ||||||||||
| 34 | ▶ | { | |||||||||
|
Subroutine
_build_match: called CC=1 SCAR=0.0
| |||||||||||
| 35 | 308 | return Gears::Router::Match->new(%args); | |||||||||
| 36 | } | ||||||||||
| 37 | |||||||||||
| 38 | sub _match_level ($self, $locations, @args) | ||||||||||
| 39 | ▶ | { | |||||||||
|
Subroutine
_match_level: called CC=4 SCAR=13.9
| |||||||||||
| 40 | 360 | my @matched; | |||||||||
| 41 | 360 | foreach my $loc ($locations->@*) { | |||||||||
| 42 | 387 | ▶ | next unless my $match_data = $loc->compare(@args); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 43 | 308 | my $match = $self->_build_match( | |||||||||
| 44 | location => $loc, | ||||||||||
| 45 | matched => $match_data, | ||||||||||
| 46 | ); | ||||||||||
| 47 | |||||||||||
| 48 | 308 | my $children = $loc->locations; | |||||||||
| 49 | 308 | ▶ | if ($children->@* > 0) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 50 | 199 | push @matched, [$match, $self->_match_level($children, @args)]; | |||||||||
| 51 | } | ||||||||||
| 52 | else { | ||||||||||
| 53 | 109 | push @matched, $match; | |||||||||
| 54 | } | ||||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | 360 | return @matched; | |||||||||
| 58 | } | ||||||||||
| 59 | |||||||||||
| 60 | sub _match ($self, @args) | ||||||||||
| 61 | ▶ | { | |||||||||
|
Subroutine
_match: called CC=1 SCAR=0.0
| |||||||||||
| 62 | 161 | return [$self->_match_level($self->locations, @args)]; | |||||||||
| 63 | } | ||||||||||
| 64 | |||||||||||
| 65 | sub match | ||||||||||
| 66 | { | ||||||||||
| 67 | 159 | ▶ | goto \&_match; | ||||||||
|
Subroutine
match: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 68 | } | ||||||||||
| 69 | |||||||||||
| 70 | sub flat_match ($self, @args) | ||||||||||
| 71 | ▶ | { | |||||||||
|
Subroutine
flat_match: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 72 | 2 | my $matches = $self->_match(@args); | |||||||||
| 73 | 2 | return $self->flatten($matches); | |||||||||
| 74 | } | ||||||||||
| 75 | |||||||||||
| 76 | sub flatten ($self, $matches) | ||||||||||
| 77 | ▶ | { | |||||||||
|
Subroutine
flatten: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 78 | 100 | my @flat_matches; | |||||||||
| 79 | 100 | foreach my $match ($matches->@*) { | |||||||||
| 80 | 199 | ▶ | if (ref $match eq 'ARRAY') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 81 | 97 | push @flat_matches, $self->flatten($match); | |||||||||
| 82 | } | ||||||||||
| 83 | else { | ||||||||||
| 84 | 102 | push @flat_matches, $match; | |||||||||
| 85 | } | ||||||||||
| 86 | } | ||||||||||
| 87 | |||||||||||
| 88 | 100 | return @flat_matches; | |||||||||
| 89 | } | ||||||||||
| 90 | |||||||||||
| 91 | sub clear ($self) | ||||||||||
| 92 | ▶ | { | |||||||||
|
Subroutine
clear: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 93 | 38 | $self->locations->@* = (); | |||||||||
| 94 | 38 | return $self; | |||||||||
| 95 | } | ||||||||||
| 96 | |||||||||||
| 97 | __END__ | ||||||||||