Wombat/Deploy/SecurityCollection.pm untested

filter: Statementstmt 0.0% 0 / 68 Branchbran 0.0% 0 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 17 Podpod 0.0% 0 / 13 totaltotal 0.0% 0 / 110 CC 7 SCAR 14.1
CC
7
Cov
0%
new
6.0
addMethod
6.0
getMethods
6.0
CRAP 4.1
1 # -*- Mode: Perl; indent-tabs-mode: nil; -*-
2  
3 package Wombat::Deploy::SecurityCollection;
4  
5 =pod
6  
7 =head1 NAME
8  
9 Wombat::Deploy::SecurityCollection - web-resource-collection
10 deployment descriptor element class
11  
12 =head1 SYNOPSIS
13  
14 =head1 DESCRIPTION
15  
16 Representation of a web resource collection for a web application's
17 security constraint, as specified in a I<web-resource-collection>
18 element in the deployment descriptor.
19  
20 =cut
21  
22 use fields qw(description methods name patterns);
23 use strict;
24 use warnings;
25  
26 use URI::Escape ();
27  
28 =pod
29  
30 =head1 CONSTRUCTOR
31  
32 =over
33  
34 =item new()
35  
36 Construct and return a B<Wombat::Deploy::SecurityConstraint> instance,
37 initializing fields appropriately.
38  
39 B<Parameters:>
40  
41 =over
42  
43 =item $name
44  
45 the name of this SecurityCollection (optional)
46  
47 =item $description
48  
49 a description of this SecurityCollection (optional)
50  
51 =back
52  
53 =back
54  
55 =cut
56  
57 sub new {
58 my $self = shift;
59 my $name = shift;
60 my $description = shift;
61  
62 $self = fields::new($self) unless ref $self;
63  
64 $self->{description} = $description;
65 $self->{methods} = {};
66 $self->{name} = $name;
67 $self->{patterns} = {};
68  
69 return $self;
70 }
71  
72 =pod
73  
74 =head1 ACCESSOR METHODS
75  
76 =over
77  
78 =item getDescription()
79  
80 Return the description of this web resource collection.
81  
82 =cut
83  
84 sub getDescription {
85 my $self = shift;
86  
87 return $self->{description};
88 }
89  
90 =pod
91  
92 =item setDescription($description)
93  
94 Set the description of this web resource collection.
95  
96 B<Parameters:>
97  
98 =over
99  
100 =item $description
101  
102 the description to set
103  
104 =back
105  
106 =cut
107  
108 sub setDescription {
109 my $self = shift;
110 my $description = shift;
111  
112 $self->{description} = $description;
113  
114 return 1;
115 }
116  
117 =pod
118  
119 =item getName()
120  
121 Get the name of this web resource collection.
122  
123 =cut
124  
125 sub getName {
126 my $self = shift;
127  
128 return $self->{name};
129 }
130  
131 =item setName($name)
132  
133 Set the name of this web resource collection.
134  
135 B<Parameters:>
136  
137 =over
138  
139 =item $name
140  
141 the name to set
142  
143 =back
144  
145 =cut
146  
147 sub setName {
148 my $self = shift;
149 my $name = shift;
150  
151 $self->{name} = $name;
152  
153 return 1;
154 }
155  
156 =pod
157  
158 =back
159  
160 =head1 PUBLIC METHODS
161  
162 =over
163  
164 =item addMethod($method)
165  
166 Add an HTTP request method to be part of this web resource collection.
167  
168 B<Parameters:>
169  
170 =over
171  
172 =item $method
173  
174 the method to add
175  
176 =back
177  
178 =cut
179  
180 sub addMethod {
181 my $self = shift;
182 my $method = shift;
183  
184 return 1 unless $method;
185  
186 $self->{methods}->{$method} = 1;
187  
188 return 1;
189 }
190  
191 =pod
192  
193 =item hasMethod($method)
194  
195 Return true if the specified HTTP request methodd is part of this web
196 resource collection.
197  
198 B<Parameters:>
199  
200 =over
201  
202 =item $method
203  
204 the method to be checked
205  
206 =back
207  
208 =cut
209  
210 sub hasMethod {
211 my $self = shift;
212 my $method = shift;
213  
214 return $self->{methods}->{$method};
215 }
216  
217 =pod
218  
219 =item getMethods()
220  
221 Return an array containing the names of the HTTP methods that are part
222 of this web resource collection.
223  
224 =cut
225  
226 sub getMethods {
227 my $self = shift;
228  
229 my @methods = keys %{ $self->{methods} };
230  
231 return wantarray ? @methods : \@methods;
232 }
233  
234 =pod
235  
236 =item removeMethod($method)
237  
238 Remove the specified HTTP request method from those that are part of
239 this web resource collection.
240  
241 B<Parameters:>
242  
243 =over
244  
245 =item $method
246  
247 the name of the method to be removed
248  
249 =back
250  
251 =cut
252  
253 sub removeMethod {
254 my $self = shift;
255 my $method = shift;
256  
257 delete $self->{methods}->{$method};
258  
259 return 1;
260 }
261  
262 =pod
263  
264 =item addPattern($pattern)
265  
266 Add a URL pattern to be part of this web resource collection.
267  
268 B<Parameters:>
269  
270 =over
271  
272 =item $pattern
273  
274 the pattern to be added
275  
276 =back
277  
278 =cut
279  
280 sub addPattern {
281 my $self = shift;
282 my $pattern = shift;
283  
284 return 1 unless $pattern;
285  
286 $pattern = URI::Escape::uri_unescape($pattern);
287 $self->{patterns}->{$pattern} = 1;
288  
289 return 1;
290 }
291  
292 =pod
293  
294 =item hasPattern($pattern)
295  
296 Return true if the specified pattern is aprt of this web resource
297 collection.
298  
299 B<Parameters:>
300  
301 =over
302  
303 =item $pattern
304  
305 the pattern to be checked
306  
307 =back
308  
309 =cut
310  
311 sub hasPattern {
312 my $self = shift;
313 my $pattern = shift;
314  
315 return $self->{patterns}->{$pattern};
316 }
317  
318 =pod
319  
320 =item getPatterns()
321  
322 Return an array containing the URL patterns that are part of this web
323 resource collection.
324  
325 =cut
326  
327 sub getPatterns {
328 my $self = shift;
329  
330 my @patterns = keys %{ $self->{patterns} };
331  
332 return wantarray ? @patterns : \@patterns;
333 }
334  
335 =pod
336  
337 =item removePattern($pattern)
338  
339 Remove the specified URL pattern from those that are part of this web
340 resource collection.
341  
342 B<Parameters:>
343  
344 =over
345  
346 =item $pattern
347  
348 the pattern to be removed
349  
350 =back
351  
352 =cut
353  
354 sub removePattern {
355 my $self = shift;
356 my $pattern = shift;
357  
358 return 1 unless $pattern;
359  
360 delete $self->{patterns}->{$pattern};
361  
362 return 1;
363 }
364  
365 1;
366 __END__