| 1 | package Authorize::Rule; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Rule-based authorization mechanism | ||||||||||||||||||||||||||||||||||||||||||
| 3 | 20 | $Authorize::Rule::VERSION = '0.009'; | |||||||||||||||||||||||||||||||||||||||||
| 4 | 20 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 20 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 20 | ▶ | use Carp 'croak'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 20 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=16 SCAR=27.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 20 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 10 | 20 | my %opts = @_; | |||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 20 | ▶ | defined $opts{'rules'} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | or croak 'You must provide rules'; | ||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 19 | my $rules = $opts{'rules'}; | |||||||||||||||||||||||||||||||||||||||||
| 16 | 19 | ▶ | ref($rules) eq 'HASH' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | or croak 'attribute rules must be a hashref'; | ||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | # expand entity groups to their entities | ||||||||||||||||||||||||||||||||||||||||||
| 20 | 19 | ▶ | if ( $opts{'entity_groups'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 1 | ▶ | ref( $opts{'entity_groups'} ) eq 'HASH' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | or croak 'attribute entity_groups must be a hashref'; | ||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 1 | foreach my $group ( keys %{ $opts{'entity_groups'} } ) { | |||||||||||||||||||||||||||||||||||||||||
| 25 | 1 | ▶ | my $group_rules = delete $rules->{$group} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | or next; | ||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | $rules->{$_} = $group_rules | ||||||||||||||||||||||||||||||||||||||||||
| 29 | 1 | for @{ $opts{'entity_groups'}{$group} }; | |||||||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | # expand resource groups to their entities | ||||||||||||||||||||||||||||||||||||||||||
| 34 | 19 | ▶ | if ( $opts{'resource_groups'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 1 | ▶ | ref( $opts{'resource_groups'} ) eq 'HASH' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | or croak 'attribute resource_groups must be a hashref'; | ||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | # populate | ||||||||||||||||||||||||||||||||||||||||||
| 39 | 1 | foreach my $entity ( keys %{$rules} ) { | |||||||||||||||||||||||||||||||||||||||||
| 40 | 1 | foreach my $resource ( keys %{ $rules->{$entity} } ) { | |||||||||||||||||||||||||||||||||||||||||
| 41 | 2 | ▶ | my $in_rsrc = $opts{'resource_groups'}{$resource} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | or next; | ||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | $rules->{$entity}{$_} = $rules->{$entity}{$resource} | ||||||||||||||||||||||||||||||||||||||||||
| 45 | 1 | for @{$in_rsrc}; | |||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | # delete | ||||||||||||||||||||||||||||||||||||||||||
| 50 | 1 | foreach my $entity ( keys %{$rules} ) { | |||||||||||||||||||||||||||||||||||||||||
| 51 | delete $rules->{$entity}{$_} | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 1 | for keys %{ $opts{'resource_groups'} }; | |||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | 19 | return bless { | |||||||||||||||||||||||||||||||||||||||||
| 57 | default => 0, # deny by default | ||||||||||||||||||||||||||||||||||||||||||
| 58 | %opts, | ||||||||||||||||||||||||||||||||||||||||||
| 59 | }, $class; | ||||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | 115 | ▶ | sub default { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 115 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 64 | 115 | ▶ | @_ and croak 'default() is a ro attribute'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | 115 | return $self->{'default'}; | |||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | sub entity_groups { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
entity_groups: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | ▶ | @_ and croak 'entity_groups() is a ro attribute'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | return $self->{'entity_groups'}; | |||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | sub resource_groups { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
resource_groups: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | @_ and croak 'resource_groups() is a ro attribute'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | return $self->{'resource_groups'}; | |||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | 115 | ▶ | sub rules { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rules: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | 115 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 82 | 115 | ▶ | @_ and croak 'rules() is a ro attribute'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 115 | return $self->{'rules'}; | |||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | 110 | ▶ | sub is_allowed { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_allowed: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | 110 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 88 | 110 | return $self->allowed(@_)->{'action'}; | |||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | 115 | ▶ | sub allowed { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
allowed: called CC=18 SCAR=28.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | 115 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 93 | 115 | my $entity = shift; | |||||||||||||||||||||||||||||||||||||||||
| 94 | 115 | my $req_resource = shift; | |||||||||||||||||||||||||||||||||||||||||
| 95 | 115 | ▶ | my $req_params = shift || {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
shift() || {}
MC/DC100%1/1
shift() || {}
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | 115 | my $default = $self->default; | |||||||||||||||||||||||||||||||||||||||||
| 97 | 115 | my $rules = $self->rules; | |||||||||||||||||||||||||||||||||||||||||
| 98 | 115 | ▶ | my %result = ( | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$req_resource || ''
MC/DC0%0/1
$req_resource || ''
$req_resource
Truth table50%1/2
A
A= $req_resource
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | entity => $entity, | ||||||||||||||||||||||||||||||||||||||||||
| 100 | resource => ($req_resource || ''), | ||||||||||||||||||||||||||||||||||||||||||
| 101 | params => $req_params, | ||||||||||||||||||||||||||||||||||||||||||
| 102 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | 115 | ▶ | my $perms = $rules->{$entity} || {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$rules->{$entity} || {}
MC/DC100%1/1
$rules->{$entity} || {}
$rules->{$entity}
Truth table100%2/2
A
A= $rules->{$entity}
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | 115 | ▶ | my $all_entities_perms = $rules->{''} || {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$rules->{''} || {}
MC/DC100%1/1
$rules->{''} || {}
$rules->{''}
Truth table100%2/2
A
A= $rules->{''}
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | # deny entities that aren't in the rules | ||||||||||||||||||||||||||||||||||||||||||
| 108 | 115 | ▶ | $perms || $all_entities_perms | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$perms or $all_entities_perms
MC/DC0%0/2
$perms or $all_entities_perms
$perms
$all_entities_perms
Truth table33%1/3
A or B
A= $permsB= $all_entities_perms
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | or return { %result, action => $default }; | ||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | # the requested and default | ||||||||||||||||||||||||||||||||||||||||||
| 112 | 115 | ▶ | my $main_ruleset = $perms->{$req_resource} || []; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$perms->{$req_resource} || []
MC/DC100%1/1
$perms->{$req_resource} || []
$perms->{$req_resource}
Truth table100%2/2
A
A= $perms->{$req_resource}
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | 115 | ▶ | my $def_ruleset = $perms->{''} || []; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$perms->{''} || []
MC/DC100%1/1
$perms->{''} || []
$perms->{''}
Truth table100%2/2
A
A= $perms->{''}
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | # perm for all the entities. Lower priority than main&def ruleset | ||||||||||||||||||||||||||||||||||||||||||
| 116 | # we don't need to check $all_entities_perms->{''} because we have $default | ||||||||||||||||||||||||||||||||||||||||||
| 117 | 115 | ▶ | my $all_entities_ruleset = $all_entities_perms->{$req_resource} || []; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$all_entities_perms->{$req_resource} || []
MC/DC100%1/1
$all_entities_perms->{$req_resource} || []
$all_entities_perms->{$req_resource}
Truth table100%2/2
A
A= $all_entities_perms->{$req_resource}
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | # if neither, return default action | ||||||||||||||||||||||||||||||||||||||||||
| 120 | 115 | ▶ | @{ $main_ruleset } || @{ $def_ruleset } || @{ $all_entities_ruleset } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
@{$main_ruleset;} or @{$def_ruleset;} or @{$all_entities_ruleset;}
@{$main_ruleset;} or @{$def_ruleset;}
MC/DC100%3/3
@{$main_ruleset;} or @{$def_ruleset;} or @{$all_entities_ruleset;}
@{$main_ruleset;}
@{$def_ruleset;}
@{$all_entities_ruleset;}
Truth table100%4/4
A or B or C
A= @{$main_ruleset;}B= @{$def_ruleset;}C= @{$all_entities_ruleset;}
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | or return { %result, action => $default }; | ||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | 111 | foreach my $rulesets ( $main_ruleset, $def_ruleset, $all_entities_ruleset) { | |||||||||||||||||||||||||||||||||||||||||
| 124 | 175 | my $ruleset_idx = 0; | |||||||||||||||||||||||||||||||||||||||||
| 125 | 175 | my $label; | |||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | 175 | R_SET: foreach my $ruleset ( @{$rulesets} ) { | |||||||||||||||||||||||||||||||||||||||||
| 128 | 146 | ▶ | if ( ! ref $ruleset ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | 11 | $label = $ruleset; | |||||||||||||||||||||||||||||||||||||||||
| 130 | 11 | next R_SET; | |||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | 135 | $ruleset_idx++; | |||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||
| 135 | 135 | my $action = $self->match_ruleset( $ruleset, $req_params ); | |||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||
| 137 | 134 | ▶ | if ( defined $action ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 138 | 105 | my %full_result = ( | |||||||||||||||||||||||||||||||||||||||||
| 139 | %result, | ||||||||||||||||||||||||||||||||||||||||||
| 140 | ruleset_idx => $ruleset_idx, | ||||||||||||||||||||||||||||||||||||||||||
| 141 | ( label => $label )x!! $label, | ||||||||||||||||||||||||||||||||||||||||||
| 142 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||
| 144 | 105 | ▶ | $full_result{'action'} = ref $action eq 'CODE' ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | $action->( \%full_result ) : | ||||||||||||||||||||||||||||||||||||||||||
| 146 | $action; | ||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | 105 | return \%full_result; | |||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | 29 | undef $label; | |||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | 5 | return { %result, action => $default }; | |||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | 135 | ▶ | sub match_ruleset { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
match_ruleset: called CC=18 SCAR=28.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 159 | 135 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 160 | 135 | my $ruleset = shift; | |||||||||||||||||||||||||||||||||||||||||
| 161 | 135 | my $req_params = shift; | |||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | 135 | ▶ | my ( $action, @rules ) = @{$ruleset} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | or return; | ||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | # an empty return() is a failure to match | ||||||||||||||||||||||||||||||||||||||||||
| 167 | # if matching of a rule succeeds, we just move to the next rule | ||||||||||||||||||||||||||||||||||||||||||
| 168 | 135 | foreach my $rule (@rules) { | |||||||||||||||||||||||||||||||||||||||||
| 169 | 64 | ▶ | if ( ref $rule eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | # check defined params by rule against requested params | ||||||||||||||||||||||||||||||||||||||||||
| 171 | 49 | KEY: foreach my $key ( keys %{$rule} ) { | |||||||||||||||||||||||||||||||||||||||||
| 172 | 50 | ▶ | if ( defined $rule->{$key} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 173 | # check if key is missing | ||||||||||||||||||||||||||||||||||||||||||
| 174 | 48 | ▶ | defined $req_params->{$key} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | or return; | ||||||||||||||||||||||||||||||||||||||||||
| 176 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 177 | # check the key exists and value is defined | ||||||||||||||||||||||||||||||||||||||||||
| 178 | 2 | ▶ | exists $req_params->{$key} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 179 | and return; | ||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||
| 181 | # don't continue checking the value in this case | ||||||||||||||||||||||||||||||||||||||||||
| 182 | # because it's undefined | ||||||||||||||||||||||||||||||||||||||||||
| 183 | 1 | next KEY; | |||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | # check matching against a code reference | ||||||||||||||||||||||||||||||||||||||||||
| 187 | 37 | ▶ | if ( ref $rule->{$key} eq 'CODE' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 188 | 2 | ▶ | $req_params->{$key} eq $rule->{$key}->($req_params) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 189 | or return; | ||||||||||||||||||||||||||||||||||||||||||
| 190 | } elsif ( ref $rule->{$key} eq 'Regexp' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 191 | 3 | ▶ | $req_params->{$key} =~ $rule->{$key} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 192 | or return; | ||||||||||||||||||||||||||||||||||||||||||
| 193 | } elsif ( ref $rule->{$key} ) { | ||||||||||||||||||||||||||||||||||||||||||
| 194 | 1 | croak 'Rule keys can only be strings, regexps, or code'; | |||||||||||||||||||||||||||||||||||||||||
| 195 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 196 | # check matching against a simple string | ||||||||||||||||||||||||||||||||||||||||||
| 197 | 31 | ▶ | $req_params->{$key} eq $rule->{$key} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 198 | or return; # no match | ||||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||
| 201 | } elsif ( ref $rule eq 'CODE' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 202 | 2 | ▶ | $rule->($req_params) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 203 | or return; | ||||||||||||||||||||||||||||||||||||||||||
| 204 | } elsif ( ! ref $rule ) { | ||||||||||||||||||||||||||||||||||||||||||
| 205 | 13 | ▶ | defined $req_params->{$rule} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 206 | or return; # no match | ||||||||||||||||||||||||||||||||||||||||||
| 207 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | croak 'Unknown rule type'; | |||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||
| 212 | 105 | return $action; | |||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||
| 215 | 20 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||
| 217 | __END__ | ||||||||||||||||||||||||||||||||||||||||||