| 1 | package Yukki::Web::Router::Route::Match; | ||||||||||||||||||
| 2 | 4 | $Yukki::Web::Router::Route::Match::VERSION = '0.991_002'; # TRIAL | |||||||||||||||||
| 3 | |||||||||||||||||||
| 4 | 4 | ▶ | $Yukki::Web::Router::Route::Match::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::Match'; | |||||||||||||||||
| 9 | |||||||||||||||||||
| 10 | 4 | ▶ | use List::Util qw( all any ); | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 11 | 4 | ▶ | use Yukki::Error qw( http_throw ); | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 12 | |||||||||||||||||||
| 13 | 4 | ▶ | use namespace::clean; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 14 | |||||||||||||||||||
| 15 | # ABSTRACT: Matching with access controls | ||||||||||||||||||
| 16 | |||||||||||||||||||
| 17 | |||||||||||||||||||
| 18 | sub access_level { | ||||||||||||||||||
| 19 | 0 | ▶ | my $self = shift; | ||||||||||||||||
|
Subroutine
access_level: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||
| 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 | my $accepts = sub { | ||||||||||||||||||
| 28 | 0 | ▶ | my $key = shift; | ||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||
| 29 | |||||||||||||||||||
| 30 | 0 | ▶ | if (!ref $match->{$key}) { | ||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||
| 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
| |||||||||||||||||||
| 46 | 0 | return $access_level; | |||||||||||||||||
| 47 | } | ||||||||||||||||||
| 48 | } | ||||||||||||||||||
| 49 | |||||||||||||||||||
| 50 | 0 | http_throw("no ACL found to match " . $self->path); | |||||||||||||||||
| 51 | } | ||||||||||||||||||
| 52 | |||||||||||||||||||
| 53 | 4 | 1; | |||||||||||||||||
| 54 | |||||||||||||||||||
| 55 | __END__ | ||||||||||||||||||
| 56 | |||||||||||||||||||
| 57 | =pod | ||||||||||||||||||
| 58 | |||||||||||||||||||
| 59 | =encoding UTF-8 | ||||||||||||||||||
| 60 | |||||||||||||||||||
| 61 | =head1 NAME | ||||||||||||||||||
| 62 | |||||||||||||||||||
| 63 | Yukki::Web::Router::Route::Match - Matching with access controls | ||||||||||||||||||
| 64 | |||||||||||||||||||
| 65 | =head1 VERSION | ||||||||||||||||||
| 66 | |||||||||||||||||||
| 67 | version 0.991_002 | ||||||||||||||||||
| 68 | |||||||||||||||||||
| 69 | =head1 DESCRIPTION | ||||||||||||||||||
| 70 | |||||||||||||||||||
| 71 | This is a helper that include access control level checking. | ||||||||||||||||||
| 72 | |||||||||||||||||||
| 73 | =head1 EXTENDS | ||||||||||||||||||
| 74 | |||||||||||||||||||
| 75 | L<Path::Router::Route::Match> | ||||||||||||||||||
| 76 | |||||||||||||||||||
| 77 | =head1 METHODS | ||||||||||||||||||
| 78 | |||||||||||||||||||
| 79 | =head2 access_level | ||||||||||||||||||
| 80 | |||||||||||||||||||
| 81 | Evaluates the access control list against a particular path. | ||||||||||||||||||
| 82 | |||||||||||||||||||
| 83 | =head1 AUTHOR | ||||||||||||||||||
| 84 | |||||||||||||||||||
| 85 | Andrew Sterling Hanenkamp <hanenkamp@cpan.org> | ||||||||||||||||||
| 86 | |||||||||||||||||||
| 87 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||
| 88 | |||||||||||||||||||
| 89 | This software is copyright (c) 2017 by Qubling Software LLC. | ||||||||||||||||||
| 90 | |||||||||||||||||||
| 91 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||
| 92 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||
| 93 | |||||||||||||||||||
| 94 | =cut | ||||||||||||||||||