blib/lib/Yukki/Web/Router/Route.pm

filter: Statementstmt 40.0% 28 / 70 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 50.0% 8 / 16 Podpod 100% 7 / 7 totaltotal 35.2% 43 / 122 CC 15 SCAR 43.9
CC
15
Cov
29%
match
182.0
create_default_mapping
12.0
is_component_slurpy
2.0
CRAP 80.7
« blib/lib/Yukki/Model/Repository.pm ↑ Summary blib/lib/Yukki/Web/Controller/Login.pm »
1 package Yukki::Web::Router::Route;
2 6 $Yukki::Web::Router::Route::VERSION = '0.991_007'; # TRIAL
3 6 $Yukki::Web::Router::Route::VERSION = '0.991007';
4 6 ▶use v5.24;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 6 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 6 extends 'Path::Router::Route';
9  
10 6 ▶use Yukki::Types qw( AccessLevel );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 6 ▶use Yukki::Web::Router::Route::Match;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 6 ▶use Types::Standard qw( ArrayRef HashRef Tuple );
Subroutine BEGIN: called CC=1 SCAR=0.0
14 6 ▶use List::Util qw( any );
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 6 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 # ABSTRACT: Adds ACLs to routes
19  
20  
21 6 has acl => (
22 is => 'ro',
23 isa => ArrayRef[Tuple[AccessLevel,HashRef]],
24 required => 1,
25 );
26  
27  
28 0 ▶sub is_component_slurpy {
Subroutine is_component_slurpy: not called CC=1 SCAR=6.9
Pod documented
29 0 my ($self, $component) = @_;
30 0 $component =~ /^[+*]:/;
31 }
32  
33  
34 0 ▶sub is_component_optional {
Subroutine is_component_optional: not called CC=1 SCAR=6.9
Pod documented
35 0 my ($self, $component) = @_;
36 0 $component =~ /^[?*]:/;
37 }
38  
39  
40 0 ▶sub is_component_variable {
Subroutine is_component_variable: not called CC=1 SCAR=6.9
Pod documented
41 0 my ($self, $component) = @_;
42 0 $component =~ /^[?*+]?:/;
43 }
44  
45  
46 0 ▶sub get_component_name {
Subroutine get_component_name: not called CC=1 SCAR=6.9
Pod documented
47 0 my ($self, $component) = @_;
48 0 my ($name) = ($component =~ /^[?*+]?:(.*)$/);
49 0 return $name;
50 }
51  
52  
53 0 ▶sub has_slurpy_match {
Subroutine has_slurpy_match: not called CC=1 SCAR=6.9
Pod documented
54 0 my $self = shift;
55 0 ▶ return any { $self->is_component_slurpy($_) } reverse @{ $self->components };
Subroutine __ANON__: not called CC=1 SCAR=6.9
56 }
57  
58  
59 0 ▶sub create_default_mapping {
Subroutine create_default_mapping: not called CC=3 SCAR=24.8
Pod documented
60 0 my $self = shift;
61  
62 0 my %defaults = %{ $self->defaults };
63 0 for my $key (keys %defaults) {
64 0 ▶ if (ref $defaults{$key} eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $defaults{$key} eq "ARRAY") 0 0 0
65 0 $defaults{$key} = [ @{ $defaults{$key} } ];
66 }
67 }
68  
69 0 return \%defaults;
70 }
71  
72  
73 0 ▶sub match {
Subroutine match: not called CC=13 SCAR=52.0
Pod documented
74 0 my ($self, $parts) = @_;
75  
76 return unless (
77 0 ▶ @$parts >= $self->length_without_optionals &&
Branch: 1 branch
BranchTrueFalseTotal
unless @$parts >= $self->length_without_optionals and $self->has_slurpy_match || @$parts <= $self->length 0 0 0
Condition0%0/6
@$parts >= $self->length_without_optionals and $self->has_slurpy_match || @$parts <= $self->length
!ll&&!rl&&r
000
$self->has_slurpy_match or @$parts <= $self->length
l!l&&r!l&&!r
000
MC/DC0%0/3
@$parts >= $self->length_without_optionals and $self->has_slurpy_match || @$parts <= $self->length
@$parts >= $self->length_without_optionals $self->has_slurpy_match @$parts <= $self->length
Truth table0%0/4
A and B or C
A= @$parts >= $self->length_without_optionalsB= $self->has_slurpy_matchC= @$parts <= $self->length
ABCresult
0XX0
1000
11X1
1011
78 ($self->has_slurpy_match || @$parts <= $self->length)
79 );
80  
81 0 my @parts = @$parts; # for shifting
82  
83 0 ▶ my $mapping = $self->has_defaults ? $self->create_default_mapping : {};
Branch: 1 branch
BranchTrueFalseTotal
$self->has_defaults ? : 0 0 0
84  
85 0 for my $c (@{ $self->components }) {
86 0 ▶ unless (@parts) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@parts) 0 0 0
87 0 ▶ die "should never get here: " .
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_component_optional($c) 0 0 0
88 "no \@parts left, but more required components remain"
89 if ! $self->is_component_optional($c);
90 0 last;
91 }
92  
93 0 my $part;
94 0 ▶ if ($self->is_component_slurpy($c)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_component_slurpy($c)) { } 0 0 0
95 0 $part = [ @parts ];
96 0 @parts = ();
97 }
98 else {
99 0 $part = shift @parts;
100 }
101  
102 0 ▶ if ($self->is_component_variable($c)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_component_variable($c)) { } 0 0 0
103 0 my $name = $self->get_component_name($c);
104  
105 0 ▶ if (my $v = $self->has_validation_for($name)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $v = $self->has_validation_for($name)) 0 0 0
106 0 ▶ return unless $v->check($part);
Branch: 1 branch
BranchTrueFalseTotal
unless $v->check($part) 0 0 0
107 }
108  
109 0 $mapping->{$name} = $part;
110 }
111  
112 else {
113 0 ▶ return unless $c eq $part;
Branch: 1 branch
BranchTrueFalseTotal
unless $c eq $part 0 0 0
114 }
115 }
116  
117 0 return Yukki::Web::Router::Route::Match->new(
118 path => join('/', @$parts),
119 route => $self,
120 mapping => $mapping,
121 );
122 }
123  
124 6 1;
125  
126 __END__
« blib/lib/Yukki/Model/Repository.pm ↑ Summary blib/lib/Yukki/Web/Controller/Login.pm »