line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package IO::Iron::IronCache::Policy; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
## no critic (Documentation::RequirePodAtEnd) |
4
|
|
|
|
|
|
|
## no critic (Documentation::RequirePodSections) |
5
|
|
|
|
|
|
|
## no critic (Subroutines::RequireArgUnpacking |
6
|
|
|
|
|
|
|
|
7
|
6
|
|
|
6
|
|
2727
|
use 5.010_000; |
|
6
|
|
|
|
|
22
|
|
8
|
6
|
|
|
6
|
|
84
|
use strict; |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
120
|
|
9
|
6
|
|
|
6
|
|
27
|
use warnings; |
|
6
|
|
|
|
|
19
|
|
|
6
|
|
|
|
|
198
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# Global creator |
12
|
6
|
|
|
|
|
514
|
BEGIN { |
13
|
6
|
|
|
6
|
|
30
|
use parent qw( IO::Iron::PolicyBase ); # Inheritance |
|
6
|
|
|
|
|
9
|
|
|
6
|
|
|
|
|
38
|
|
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# Global destructor |
17
|
|
|
|
6
|
|
|
END { |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# ABSTRACT: Base package (inherited) for IronCache::Client package. |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
our $VERSION = '0.13'; # VERSION: generated by DZP::OurPkgVersion |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
26
|
6
|
|
|
6
|
|
13
|
use Log::Any qw{$log}; |
|
6
|
|
|
|
|
28
|
|
|
6
|
|
|
|
|
1161
|
|
27
|
6
|
|
|
6
|
|
101
|
use Hash::Util 0.06 qw{lock_keys unlock_keys}; |
|
6
|
|
|
|
|
35
|
|
|
6
|
|
|
|
|
364
|
|
28
|
6
|
|
|
6
|
|
14
|
use Carp::Assert::More; |
|
6
|
|
|
|
|
840
|
|
|
6
|
|
|
|
|
39
|
|
29
|
6
|
|
|
6
|
|
13
|
use English '-no_match_vars'; |
|
6
|
|
|
|
|
32
|
|
|
6
|
|
|
|
|
1949
|
|
30
|
6
|
|
|
6
|
|
12
|
use Params::Validate qw(:all); |
|
6
|
|
|
|
|
770
|
|
|
6
|
|
|
|
|
39
|
|
31
|
6
|
|
|
6
|
|
11
|
use Carp; |
|
6
|
|
|
|
|
300
|
|
|
6
|
|
|
|
|
34
|
|
32
|
6
|
|
|
6
|
|
10
|
use Try::Tiny; |
|
6
|
|
|
0
|
|
5951
|
|
|
0
|
|
|
|
|
0
|
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub is_cache_name_alternatives { |
37
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
38
|
0
|
|
|
|
|
0
|
my %params = validate(@_, { } ); # No parameters |
39
|
0
|
|
|
|
|
0
|
$log->tracef('Entering is_cache_name_alternatives(%s)', \%params); |
40
|
|
|
|
|
|
|
my $rval = !( |
41
|
|
|
|
|
|
|
defined $self->{'policy'}->{'definition'}->{'no_limitation'} |
42
|
0
|
|
0
|
|
|
0
|
&& $self->{'policy'}->{'definition'}->{'no_limitation'} == 1 |
43
|
|
|
|
|
|
|
); |
44
|
0
|
|
|
|
|
0
|
$log->tracef('Exiting is_cache_name_alternatives():%d', $rval); |
45
|
0
|
|
|
|
|
0
|
return $rval; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub is_item_key_alternatives { |
50
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
51
|
0
|
|
|
|
|
0
|
my %params = validate(@_, { } ); # No parameters |
52
|
0
|
|
|
|
|
0
|
$log->tracef('Entering is_item_key_alternatives(%s)', \%params); |
53
|
|
|
|
|
|
|
my $rval = !( |
54
|
|
|
|
|
|
|
defined $self->{'policy'}->{'definition'}->{'no_limitation'} |
55
|
0
|
|
0
|
|
|
0
|
&& $self->{'policy'}->{'definition'}->{'no_limitation'} == 1 |
56
|
|
|
|
|
|
|
); |
57
|
0
|
|
|
|
|
0
|
$log->tracef('Exiting is_item_key_alternatives():%d', $rval); |
58
|
0
|
|
|
|
|
0
|
return $rval; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub cache_name_alternatives { |
63
|
3
|
|
|
3
|
1
|
5816
|
my $self = shift; |
64
|
3
|
|
|
|
|
42
|
my %params = validate(@_, { } ); # No parameters |
65
|
3
|
|
|
|
|
18
|
$log->tracef('Entering cache_name_alternatives(%s)', \%params); |
66
|
|
|
|
|
|
|
|
67
|
3
|
|
|
|
|
792
|
my @alternatives = $self->alternatives( 'required_policy' => 'name' ); |
68
|
|
|
|
|
|
|
|
69
|
3
|
|
|
|
|
23
|
$log->tracef('Exiting cache_name_alternatives():%s', \@alternatives); |
70
|
3
|
|
|
|
|
1524
|
return @alternatives; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub item_key_alternatives { |
75
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
76
|
0
|
|
|
|
|
0
|
my %params = validate(@_, { } ); # No parameters |
77
|
0
|
|
|
|
|
0
|
$log->tracef('Entering item_key_alternatives(%s)', \%params); |
78
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
0
|
my @alternatives = $self->alternatives( 'required_policy' => 'item_key' ); |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
0
|
$log->tracef('Exiting item_key_alternatives():%s', \@alternatives); |
82
|
0
|
|
|
|
|
0
|
return @alternatives; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub is_valid_cache_name { |
87
|
4
|
|
|
4
|
1
|
25
|
my $self = shift; |
88
|
4
|
|
|
|
|
87
|
my %params = validate( |
89
|
|
|
|
|
|
|
@_, { |
90
|
|
|
|
|
|
|
'name' => { type => SCALAR, }, # cache name. |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
); |
93
|
4
|
|
|
|
|
27
|
$log->tracef('Entering is_valid_cache_name(%s)', \%params); |
94
|
4
|
|
|
|
|
1008
|
my $validity = 1; |
95
|
|
|
|
|
|
|
try { |
96
|
4
|
|
|
4
|
|
381
|
$log->tracef('is_valid_cache_name:Enter try/catch.'); |
97
|
4
|
|
|
|
|
290
|
$self->validate_cache_name('name' => $params{'name'}); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
catch { |
100
|
2
|
|
|
2
|
|
2544
|
$log->tracef('is_valid_cache_name:Caught exception.'); |
101
|
2
|
50
|
33
|
|
|
235
|
croak $_ unless blessed $_ && $_->can('rethrow'); ## no critic (ControlStructures::ProhibitPostfixControls) |
102
|
2
|
50
|
|
|
|
11
|
if ( $_->isa('IronPolicyException') ) { |
103
|
2
|
|
|
|
|
38
|
$log->tracef('Caught IronPolicyException.'); |
104
|
2
|
|
|
|
|
202
|
$validity = 0; |
105
|
|
|
|
|
|
|
} |
106
|
4
|
|
|
|
|
31
|
}; |
107
|
4
|
|
|
|
|
70
|
$log->tracef('Exiting is_valid_cache_name():%d', $validity); |
108
|
4
|
|
|
|
|
306
|
return $validity; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub validate_cache_name { |
113
|
6
|
|
|
6
|
1
|
14
|
my $self = shift; |
114
|
6
|
|
|
|
|
100
|
my %params = validate( |
115
|
|
|
|
|
|
|
@_, { |
116
|
|
|
|
|
|
|
'name' => { type => SCALAR, }, # cache name. |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
); |
119
|
6
|
|
|
|
|
38
|
$log->tracef('Entering validate_cache_name(%s)', \%params); |
120
|
|
|
|
|
|
|
$self->validate_with_policy( |
121
|
|
|
|
|
|
|
'policy' => 'name', |
122
|
6
|
|
|
|
|
1567
|
'candidate' => $params{'name'}); |
123
|
3
|
|
|
|
|
10
|
$log->tracef('Exiting validate_cache_name():[NONE]'); |
124
|
3
|
|
|
|
|
193
|
return; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub is_valid_item_key { |
129
|
2
|
|
|
2
|
1
|
5
|
my $self = shift; |
130
|
2
|
|
|
|
|
43
|
my %params = validate( |
131
|
|
|
|
|
|
|
@_, { |
132
|
|
|
|
|
|
|
'key' => { type => SCALAR, }, # cache name. |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
); |
135
|
2
|
|
|
|
|
16
|
$log->tracef('Entering is_valid_item_key(%s)', \%params); |
136
|
2
|
|
|
|
|
497
|
my $validity = 1; |
137
|
|
|
|
|
|
|
try { |
138
|
2
|
|
|
2
|
|
163
|
$log->tracef('is_valid_item_key:Enter try/catch.'); |
139
|
2
|
|
|
|
|
142
|
$self->validate_item_key('key' => $params{'key'}); |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
catch { |
142
|
1
|
|
|
1
|
|
912
|
$log->tracef('is_valid_item_key:Caught exception.'); |
143
|
1
|
50
|
33
|
|
|
93
|
croak $_ unless blessed $_ && $_->can('rethrow'); ## no critic (ControlStructures::ProhibitPostfixControls) |
144
|
1
|
50
|
|
|
|
6
|
if ( $_->isa('IronPolicyException') ) { |
145
|
1
|
|
|
|
|
5
|
$log->tracef('Caught IronPolicyException.'); |
146
|
1
|
|
|
|
|
86
|
$validity = 0; |
147
|
|
|
|
|
|
|
} |
148
|
2
|
|
|
|
|
21
|
}; |
149
|
2
|
|
|
|
|
31
|
$log->tracef('Exiting is_valid_item_key():%d', $validity); |
150
|
2
|
|
|
|
|
150
|
return $validity; |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
sub validate_item_key { |
155
|
3
|
|
|
3
|
1
|
9
|
my $self = shift; |
156
|
3
|
|
|
|
|
50
|
my %params = validate( |
157
|
|
|
|
|
|
|
@_, { |
158
|
|
|
|
|
|
|
'key' => { type => SCALAR, }, # cache name. |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
); |
161
|
3
|
|
|
|
|
20
|
$log->tracef('Entering validate_item_key(%s)', \%params); |
162
|
|
|
|
|
|
|
$self->validate_with_policy( |
163
|
|
|
|
|
|
|
'policy' => 'item_key', |
164
|
3
|
|
|
|
|
696
|
'candidate' => $params{'key'}); |
165
|
1
|
|
|
|
|
4
|
$log->tracef('Exiting validate_item_key():[NONE]'); |
166
|
1
|
|
|
|
|
65
|
return; |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
# INTERNAL METHODS |
171
|
|
|
|
|
|
|
# For use in the inheriting subclass |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
# This is a late binding to inherited method get_policies: |
174
|
|
|
|
|
|
|
sub _THIS_POLICY { ## no critic (Subroutines::ProhibitUnusedPrivateSubroutines) |
175
|
2
|
|
|
2
|
|
5
|
my $self = shift; |
176
|
2
|
|
|
|
|
21
|
my %params = validate( |
177
|
|
|
|
|
|
|
@_, { |
178
|
|
|
|
|
|
|
# No parameters. |
179
|
|
|
|
|
|
|
} |
180
|
|
|
|
|
|
|
); |
181
|
2
|
|
|
|
|
15
|
return 'cache'; |
182
|
|
|
|
|
|
|
} |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
1; |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
__END__ |