| 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
|
|
3027
|
use 5.010_000; |
|
|
6
|
|
|
|
|
24
|
|
|
8
|
6
|
|
|
6
|
|
49
|
use strict; |
|
|
6
|
|
|
|
|
16
|
|
|
|
6
|
|
|
|
|
122
|
|
|
9
|
6
|
|
|
6
|
|
31
|
use warnings; |
|
|
6
|
|
|
|
|
11
|
|
|
|
6
|
|
|
|
|
239
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# Global creator |
|
12
|
6
|
|
|
|
|
531
|
BEGIN { |
|
13
|
6
|
|
|
6
|
|
33
|
use parent qw( IO::Iron::PolicyBase ); # Inheritance |
|
|
6
|
|
|
|
|
13
|
|
|
|
6
|
|
|
|
|
46
|
|
|
14
|
|
|
|
|
|
|
} |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# Global destructor |
|
17
|
|
|
|
6
|
|
|
END { |
|
18
|
|
|
|
|
|
|
} |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# ABSTRACT: Base package (inherited) for IronCache::Client package. |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
our $VERSION = '0.14'; # VERSION: generated by DZP::OurPkgVersion |
|
23
|
|
|
|
|
|
|
|
|
24
|
6
|
|
|
6
|
|
15
|
use Log::Any qw{$log}; |
|
|
6
|
|
|
|
|
65
|
|
|
|
6
|
|
|
|
|
1231
|
|
|
25
|
6
|
|
|
6
|
|
104
|
use Hash::Util 0.06 qw{lock_keys unlock_keys}; |
|
|
6
|
|
|
|
|
35
|
|
|
|
6
|
|
|
|
|
377
|
|
|
26
|
6
|
|
|
6
|
|
14
|
use Carp::Assert::More; |
|
|
6
|
|
|
|
|
976
|
|
|
|
6
|
|
|
|
|
41
|
|
|
27
|
6
|
|
|
6
|
|
17
|
use English '-no_match_vars'; |
|
|
6
|
|
|
|
|
33
|
|
|
|
6
|
|
|
|
|
1999
|
|
|
28
|
6
|
|
|
6
|
|
55
|
use Params::Validate qw(:all); |
|
|
6
|
|
|
|
|
840
|
|
|
|
6
|
|
|
|
|
42
|
|
|
29
|
6
|
|
|
6
|
|
15
|
use Carp; |
|
|
6
|
|
|
|
|
297
|
|
|
|
6
|
|
|
|
|
42
|
|
|
30
|
6
|
|
|
6
|
|
11
|
use Try::Tiny; |
|
|
6
|
|
|
0
|
|
6412
|
|
|
|
0
|
|
|
|
|
0
|
|
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub is_cache_name_alternatives { |
|
33
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
|
34
|
0
|
|
|
|
|
0
|
my %params = validate( @_, {} ); # No parameters |
|
35
|
0
|
|
|
|
|
0
|
$log->tracef( 'Entering is_cache_name_alternatives(%s)', \%params ); |
|
36
|
|
|
|
|
|
|
my $rval = !( defined $self->{'policy'}->{'definition'}->{'no_limitation'} |
|
37
|
0
|
|
0
|
|
|
0
|
&& $self->{'policy'}->{'definition'}->{'no_limitation'} == 1 ); |
|
38
|
0
|
|
|
|
|
0
|
$log->tracef( 'Exiting is_cache_name_alternatives():%d', $rval ); |
|
39
|
0
|
|
|
|
|
0
|
return $rval; |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub is_item_key_alternatives { |
|
43
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
|
44
|
0
|
|
|
|
|
0
|
my %params = validate( @_, {} ); # No parameters |
|
45
|
0
|
|
|
|
|
0
|
$log->tracef( 'Entering is_item_key_alternatives(%s)', \%params ); |
|
46
|
|
|
|
|
|
|
my $rval = !( defined $self->{'policy'}->{'definition'}->{'no_limitation'} |
|
47
|
0
|
|
0
|
|
|
0
|
&& $self->{'policy'}->{'definition'}->{'no_limitation'} == 1 ); |
|
48
|
0
|
|
|
|
|
0
|
$log->tracef( 'Exiting is_item_key_alternatives():%d', $rval ); |
|
49
|
0
|
|
|
|
|
0
|
return $rval; |
|
50
|
|
|
|
|
|
|
} |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub cache_name_alternatives { |
|
53
|
3
|
|
|
3
|
1
|
6207
|
my $self = shift; |
|
54
|
3
|
|
|
|
|
50
|
my %params = validate( @_, {} ); # No parameters |
|
55
|
3
|
|
|
|
|
24
|
$log->tracef( 'Entering cache_name_alternatives(%s)', \%params ); |
|
56
|
|
|
|
|
|
|
|
|
57
|
3
|
|
|
|
|
1044
|
my @alternatives = $self->alternatives( 'required_policy' => 'name' ); |
|
58
|
|
|
|
|
|
|
|
|
59
|
3
|
|
|
|
|
22
|
$log->tracef( 'Exiting cache_name_alternatives():%s', \@alternatives ); |
|
60
|
3
|
|
|
|
|
1652
|
return @alternatives; |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub item_key_alternatives { |
|
64
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
|
65
|
0
|
|
|
|
|
0
|
my %params = validate( @_, {} ); # No parameters |
|
66
|
0
|
|
|
|
|
0
|
$log->tracef( 'Entering item_key_alternatives(%s)', \%params ); |
|
67
|
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
0
|
my @alternatives = $self->alternatives( 'required_policy' => 'item_key' ); |
|
69
|
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
0
|
$log->tracef( 'Exiting item_key_alternatives():%s', \@alternatives ); |
|
71
|
0
|
|
|
|
|
0
|
return @alternatives; |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub is_valid_cache_name { |
|
75
|
4
|
|
|
4
|
1
|
60
|
my $self = shift; |
|
76
|
4
|
|
|
|
|
176
|
my %params = validate( |
|
77
|
|
|
|
|
|
|
@_, |
|
78
|
|
|
|
|
|
|
{ |
|
79
|
|
|
|
|
|
|
'name' => { type => SCALAR, }, # cache name. |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
); |
|
82
|
4
|
|
|
|
|
47
|
$log->tracef( 'Entering is_valid_cache_name(%s)', \%params ); |
|
83
|
4
|
|
|
|
|
1402
|
my $validity = 1; |
|
84
|
|
|
|
|
|
|
try { |
|
85
|
4
|
|
|
4
|
|
557
|
$log->tracef('is_valid_cache_name:Enter try/catch.'); |
|
86
|
4
|
|
|
|
|
445
|
$self->validate_cache_name( 'name' => $params{'name'} ); |
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
catch { |
|
89
|
2
|
|
|
2
|
|
3077
|
$log->tracef('is_valid_cache_name:Caught exception.'); |
|
90
|
2
|
50
|
33
|
|
|
187
|
croak $_ unless blessed $_ && $_->can('rethrow'); ## no critic (ControlStructures::ProhibitPostfixControls) |
|
91
|
2
|
50
|
|
|
|
11
|
if ( $_->isa('IronPolicyException') ) { |
|
92
|
2
|
|
|
|
|
7
|
$log->tracef('Caught IronPolicyException.'); |
|
93
|
2
|
|
|
|
|
181
|
$validity = 0; |
|
94
|
|
|
|
|
|
|
} |
|
95
|
4
|
|
|
|
|
60
|
}; |
|
96
|
4
|
|
|
|
|
86
|
$log->tracef( 'Exiting is_valid_cache_name():%d', $validity ); |
|
97
|
4
|
|
|
|
|
412
|
return $validity; |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub validate_cache_name { |
|
101
|
6
|
|
|
6
|
1
|
15
|
my $self = shift; |
|
102
|
6
|
|
|
|
|
133
|
my %params = validate( |
|
103
|
|
|
|
|
|
|
@_, |
|
104
|
|
|
|
|
|
|
{ |
|
105
|
|
|
|
|
|
|
'name' => { type => SCALAR, }, # cache name. |
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
); |
|
108
|
6
|
|
|
|
|
49
|
$log->tracef( 'Entering validate_cache_name(%s)', \%params ); |
|
109
|
|
|
|
|
|
|
$self->validate_with_policy( |
|
110
|
|
|
|
|
|
|
'policy' => 'name', |
|
111
|
6
|
|
|
|
|
1773
|
'candidate' => $params{'name'} |
|
112
|
|
|
|
|
|
|
); |
|
113
|
3
|
|
|
|
|
12
|
$log->tracef('Exiting validate_cache_name():[NONE]'); |
|
114
|
3
|
|
|
|
|
247
|
return; |
|
115
|
|
|
|
|
|
|
} |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub is_valid_item_key { |
|
118
|
2
|
|
|
2
|
1
|
5
|
my $self = shift; |
|
119
|
2
|
|
|
|
|
40
|
my %params = validate( |
|
120
|
|
|
|
|
|
|
@_, |
|
121
|
|
|
|
|
|
|
{ |
|
122
|
|
|
|
|
|
|
'key' => { type => SCALAR, }, # cache name. |
|
123
|
|
|
|
|
|
|
} |
|
124
|
|
|
|
|
|
|
); |
|
125
|
2
|
|
|
|
|
19
|
$log->tracef( 'Entering is_valid_item_key(%s)', \%params ); |
|
126
|
2
|
|
|
|
|
485
|
my $validity = 1; |
|
127
|
|
|
|
|
|
|
try { |
|
128
|
2
|
|
|
2
|
|
161
|
$log->tracef('is_valid_item_key:Enter try/catch.'); |
|
129
|
2
|
|
|
|
|
141
|
$self->validate_item_key( 'key' => $params{'key'} ); |
|
130
|
|
|
|
|
|
|
} |
|
131
|
|
|
|
|
|
|
catch { |
|
132
|
1
|
|
|
1
|
|
1261
|
$log->tracef('is_valid_item_key:Caught exception.'); |
|
133
|
1
|
50
|
33
|
|
|
86
|
croak $_ unless blessed $_ && $_->can('rethrow'); ## no critic (ControlStructures::ProhibitPostfixControls) |
|
134
|
1
|
50
|
|
|
|
7
|
if ( $_->isa('IronPolicyException') ) { |
|
135
|
1
|
|
|
|
|
4
|
$log->tracef('Caught IronPolicyException.'); |
|
136
|
1
|
|
|
|
|
105
|
$validity = 0; |
|
137
|
|
|
|
|
|
|
} |
|
138
|
2
|
|
|
|
|
26
|
}; |
|
139
|
2
|
|
|
|
|
31
|
$log->tracef( 'Exiting is_valid_item_key():%d', $validity ); |
|
140
|
2
|
|
|
|
|
176
|
return $validity; |
|
141
|
|
|
|
|
|
|
} |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
sub validate_item_key { |
|
144
|
3
|
|
|
3
|
1
|
6
|
my $self = shift; |
|
145
|
3
|
|
|
|
|
54
|
my %params = validate( |
|
146
|
|
|
|
|
|
|
@_, |
|
147
|
|
|
|
|
|
|
{ |
|
148
|
|
|
|
|
|
|
'key' => { type => SCALAR, }, # cache name. |
|
149
|
|
|
|
|
|
|
} |
|
150
|
|
|
|
|
|
|
); |
|
151
|
3
|
|
|
|
|
21
|
$log->tracef( 'Entering validate_item_key(%s)', \%params ); |
|
152
|
|
|
|
|
|
|
$self->validate_with_policy( |
|
153
|
|
|
|
|
|
|
'policy' => 'item_key', |
|
154
|
3
|
|
|
|
|
793
|
'candidate' => $params{'key'} |
|
155
|
|
|
|
|
|
|
); |
|
156
|
1
|
|
|
|
|
5
|
$log->tracef('Exiting validate_item_key():[NONE]'); |
|
157
|
1
|
|
|
|
|
64
|
return; |
|
158
|
|
|
|
|
|
|
} |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
# INTERNAL METHODS |
|
161
|
|
|
|
|
|
|
# For use in the inheriting subclass |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
# This is a late binding to inherited method get_policies: |
|
164
|
|
|
|
|
|
|
sub _THIS_POLICY { ## no critic (Subroutines::ProhibitUnusedPrivateSubroutines) |
|
165
|
2
|
|
|
2
|
|
6
|
my $self = shift; |
|
166
|
2
|
|
|
|
|
57
|
my %params = validate( |
|
167
|
|
|
|
|
|
|
@_, |
|
168
|
|
|
|
|
|
|
{ |
|
169
|
|
|
|
|
|
|
# No parameters. |
|
170
|
|
|
|
|
|
|
} |
|
171
|
|
|
|
|
|
|
); |
|
172
|
2
|
|
|
|
|
51
|
return 'cache'; |
|
173
|
|
|
|
|
|
|
} |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
1; |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
__END__ |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=pod |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=encoding UTF-8 |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=head1 NAME |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
IO::Iron::IronCache::Policy - Base package (inherited) for IronCache::Client package. |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=head1 VERSION |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
version 0.14 |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
# new() in the inheriting sub class. |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
sub new { |
|
196
|
|
|
|
|
|
|
my ($class, $params) = @_; |
|
197
|
|
|
|
|
|
|
my $self = IO::Iron::IronCache::Policy->new(); |
|
198
|
|
|
|
|
|
|
# Add more keys to the self hash. |
|
199
|
|
|
|
|
|
|
my @self_keys = ( |
|
200
|
|
|
|
|
|
|
'caches', # References to all objects created of class IO::Iron::IronCache::Cache. |
|
201
|
|
|
|
|
|
|
legal_keys(%{$self}), |
|
202
|
|
|
|
|
|
|
); |
|
203
|
|
|
|
|
|
|
unlock_keys(%{$self}); |
|
204
|
|
|
|
|
|
|
lock_keys_plus(%{$self}, @self_keys); |
|
205
|
|
|
|
|
|
|
my @caches; |
|
206
|
|
|
|
|
|
|
$self->{'caches'} = \@caches; |
|
207
|
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
unlock_keys(%{$self}); |
|
209
|
|
|
|
|
|
|
bless $self, $class; |
|
210
|
|
|
|
|
|
|
lock_keys(%{$self}, @self_keys); |
|
211
|
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
return $self; |
|
213
|
|
|
|
|
|
|
} |
|
214
|
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=for stopwords IronCache Params IronHTTPCallException Mikko Koivunalho timestamp cas Cas |
|
216
|
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=for stopwords NoIronPolicyException IronPolicyException |
|
218
|
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=head1 METHODS |
|
220
|
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=head2 is_cache_name_alternatives |
|
222
|
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=head2 is_item_key_alternatives |
|
224
|
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=head2 cache_name_alternatives |
|
226
|
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
Return all possible cache name alternatives according to the current policy. |
|
228
|
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=over 8 |
|
230
|
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
[No parameters.] |
|
232
|
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
=back |
|
234
|
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
Return: list of cache name alternatives |
|
236
|
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
Will throw NoIronPolicyException if there is no limit to the alternatives. |
|
238
|
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
=head2 item_key_alternatives |
|
240
|
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
Return all possible item key alternatives according to the current policy. |
|
242
|
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
=over 8 |
|
244
|
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
[No parameters.] |
|
246
|
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
=back |
|
248
|
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
Return: list of item key alternatives |
|
250
|
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
Will throw NoIronPolicyException if there is no limit to the alternatives. |
|
252
|
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
=head2 is_valid_cache_name |
|
254
|
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
Check if the cache name is valid according to the policy. Return 1/0. |
|
256
|
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
=over 8 |
|
258
|
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
=item name string to verify. |
|
260
|
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
=back |
|
262
|
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
=head2 validate_cache_name |
|
264
|
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
Same as above but if validation fails, throws IronPolicyException. |
|
266
|
|
|
|
|
|
|
If valid, returns undefined. |
|
267
|
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
=over 8 |
|
269
|
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
=item name string to verify. |
|
271
|
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
=back |
|
273
|
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
=head2 is_valid_item_key |
|
275
|
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
Check if the item key is valid according to the policy. Return 1/0. |
|
277
|
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
=over 8 |
|
279
|
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
=item key string to verify. |
|
281
|
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
=back |
|
283
|
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
=head2 validate_item_key |
|
285
|
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
Same as above but if validation fails, throws IronPolicyException. |
|
287
|
|
|
|
|
|
|
If valid, returns undefined. |
|
288
|
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
=over 8 |
|
290
|
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
=item key string to verify. |
|
292
|
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
=back |
|
294
|
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
=head1 AUTHOR |
|
296
|
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
Mikko Koivunalho <mikko.koivunalho@iki.fi> |
|
298
|
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
=head1 BUGS |
|
300
|
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
Please report any bugs or feature requests to bug-io-iron@rt.cpan.org or through the web interface at: |
|
302
|
|
|
|
|
|
|
http://rt.cpan.org/Public/Dist/Display.html?Name=IO-Iron |
|
303
|
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
305
|
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
This software is copyright (c) 2023 by Mikko Koivunalho. |
|
307
|
|
|
|
|
|
|
|
|
308
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
309
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
310
|
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
The full text of the license can be found in the |
|
312
|
|
|
|
|
|
|
F<LICENSE> file included with this distribution. |
|
313
|
|
|
|
|
|
|
|
|
314
|
|
|
|
|
|
|
=cut |