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

filter: Statementstmt 53.8% 21 / 39 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 60.0% 6 / 10 Podpod 100% 1 / 1 totaltotal 48.2% 28 / 58 CC 6 SCAR 21.3
CC
6
Cov
45%
__ANON__
20.0
access_level
12.0
__ANON__
2.0
CRAP 8.4
« blib/lib/Yukki/Web/Plugin/Spreadsheet.pm ↑ Summary blib/lib/Yukki/Web/Response.pm »
1 package Yukki::Web::Router::Route::Match;
2 6 $Yukki::Web::Router::Route::Match::VERSION = '0.991_007'; # TRIAL
3 6 $Yukki::Web::Router::Route::Match::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::Match';
9  
10 6 ▶use List::Util qw( all any );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 6 ▶use Yukki::Error qw( http_throw );
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 6 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 # ABSTRACT: Matching with access controls
16  
17  
18 0 ▶sub access_level {
Subroutine access_level: not called CC=3 SCAR=24.8
Pod documented
19 0 my $self = shift;
20  
21 0 my $mapping = $self->mapping;
22 0 my $acl = $self->route->acl;
23  
24 0 for my $rule (@$acl) {
25 0 my ($access_level, $match) = @$rule;
26  
27 0 ▶ my $accepts = sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
28 0 my $key = shift;
29  
30 0 ▶ if (!ref $match->{$key}) {
Branch: 3 branches
BranchTrueFalseTotal
if (not ref $match->{$key}) { } 0 0 0
elsif (ref $match->{$key} eq 'CODE') { } 0 0 0
elsif (ref $match->{$key} eq 'ARRAY') { } 0 0 0
31 0 return $mapping->{$key} eq $match->{$key};
32 }
33 elsif (ref $match->{$key} eq 'CODE') {
34 0 local $_ = $mapping->{$key};
35 0 return $match->{$key}->($mapping->{$key});
36 }
37 elsif (ref $match->{$key} eq 'ARRAY') {
38 0 ▶ return any { $mapping->{$key} eq $_ } $match->{$key}->@*;
Subroutine __ANON__: not called CC=1 SCAR=6.9
39 }
40 else {
41 0 die "unknown ACL authorization check type";
42 }
43 0 };
44  
45 0 ▶ if (all { $accepts->($_) } keys %$match) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if (&all(sub { &$accepts($_); } , keys %$match)) 0 0 0
46 0 return $access_level;
47 }
48 }
49  
50 0 http_throw("no ACL found to match " . $self->path);
51 }
52  
53 6 1;
54  
55 __END__
« blib/lib/Yukki/Web/Plugin/Spreadsheet.pm ↑ Summary blib/lib/Yukki/Web/Response.pm »