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 SCAR 45.5
CC
15
Cov
29%
match
182.0
create_default_mapping
12.0
is_component_slurpy
2.0
CRAP 95.0
« blib/lib/Yukki/Web/Plugin/YukkiText.pm ↑ Summary blib/lib/Yukki/Web/Controller/Attachment.pm »
1 package Yukki::Web::Router::Route;
2 4 $Yukki::Web::Router::Route::VERSION = '0.991_002'; # TRIAL
3  
4 4 ▶$Yukki::Web::Router::Route::VERSION = '0.991002';use v5.24;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 4 extends 'Path::Router::Route';
9  
10 4 ▶use Yukki::Types qw( AccessLevel );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use Yukki::Web::Router::Route::Match;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 4 ▶use Types::Standard qw( ArrayRef HashRef Tuple );
Subroutine BEGIN: called CC=1 SCAR=0.0
14 4 ▶use List::Util qw( any );
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 4 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 # ABSTRACT: Adds ACLs to routes
19  
20  
21 4 has acl => (
22 is => 'ro',
23 isa => ArrayRef[Tuple[AccessLevel,HashRef]],
24 required => 1,
25 );
26  
27  
28 sub is_component_slurpy {
29 0 ▶ my ($self, $component) = @_;
Subroutine is_component_slurpy: not called CC=1 SCAR=6.9
Pod documented
30 0 $component =~ /^[+*]:/;
31 }
32  
33  
34 sub is_component_optional {
35 0 ▶ my ($self, $component) = @_;
Subroutine is_component_optional: not called CC=1 SCAR=6.9
Pod documented
36 0 $component =~ /^[?*]:/;
37 }
38  
39  
40 sub is_component_variable {
41 0 ▶ my ($self, $component) = @_;
Subroutine is_component_variable: not called CC=1 SCAR=6.9
Pod documented
42 0 $component =~ /^[?*+]?:/;
43 }
44  
45  
46 sub get_component_name {
47 0 ▶ my ($self, $component) = @_;
Subroutine get_component_name: not called CC=1 SCAR=6.9
Pod documented
48 0 my ($name) = ($component =~ /^[?*+]?:(.*)$/);
49 0 return $name;
50 }
51  
52  
53 sub has_slurpy_match {
54 0 ▶ my $self = shift;
Subroutine has_slurpy_match: not called CC=1 SCAR=6.9
Pod documented
55 0 ▶ return any { $self->is_component_slurpy($_) } reverse @{ $self->components };
Subroutine __ANON__: not called CC=1 SCAR=6.9
56 }
57  
58  
59 sub create_default_mapping {
60 0 ▶ my $self = shift;
Subroutine create_default_mapping: not called CC=3 SCAR=24.8
Pod documented
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 sub match {
74 0 ▶ my ($self, $parts) = @_;
Subroutine match: not called CC=13 SCAR=52.0
Pod documented
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 4 1;
125  
126 __END__
127  
128 =pod
129  
130 =encoding UTF-8
131  
132 =head1 NAME
133  
134 Yukki::Web::Router::Route - Adds ACLs to routes
135  
136 =head1 VERSION
137  
138 version 0.991_002
139  
140 =head1 DESCRIPTION
141  
142 Each route in L<Yukki::Web::Router> is defined using this class.
143  
144 =head1 EXTENDS
145  
146 L<Path::Router::Route>
147  
148 =head1 ATTRIBUTES
149  
150 =head2 acl
151  
152 Each route has an access control table here that defines what access levels are
153 required of a visitor to perform each operation.
154  
155 =head1 METHODS
156  
157 =head2 is_component_slurpy
158  
159 If the path component is like "*:var" or "+:var", it is slurpy.
160  
161 =head2 is_component_optional
162  
163 If the path component is like "?:var" or "*:var", it is optional.
164  
165 =head2 is_component_variable
166  
167 If the path component is like "?:var" or "+:var" or "*:var" or ":var", it is a
168 variable.
169  
170 =head2 get_component_name
171  
172 Grabs the name out of a variable.
173  
174 =head2 has_slurpy_match
175  
176 Returns true if any component is slurpy.
177  
178 =head2 create_default_mapping
179  
180 If a default value is an array reference, copies that array.
181  
182 =head2 match
183  
184 Adds support for slurpy matching.
185  
186 =head1 AUTHOR
187  
188 Andrew Sterling Hanenkamp <hanenkamp@cpan.org>
189  
190 =head1 COPYRIGHT AND LICENSE
191  
192 This software is copyright (c) 2017 by Qubling Software LLC.
193  
194 This is free software; you can redistribute it and/or modify it under
195 the same terms as the Perl 5 programming language system itself.
196  
197 =cut
« blib/lib/Yukki/Web/Plugin/YukkiText.pm ↑ Summary blib/lib/Yukki/Web/Controller/Attachment.pm »