Wombat/Valve/ValveBase.pm untested

filter: Statementstmt 0.0% 0 / 39 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 12 Podpod 0.0% 0 / 8 totaltotal 0.0% 0 / 67 CC 5 SCAR 13.9
CC
5
Cov
0%
new
6.0
start
6.0
stop
6.0
CRAP 4.0
1 # -*- Mode: Perl; indent-tabs-mode: nil; -*-
2  
3 package Wombat::Valve::ValveBase;
4  
5 =pod
6  
7 =head1 NAME
8  
9 Wombat::Valve::ValveBase - valve base class
10  
11 =head1 SYNOPSIS
12  
13 =head1 DESCRIPTION
14  
15 Convenience base implementation of B<Wombat::Valve>. Subclasses
16 B<MUST> implement C<invoke()> to provide the required functionality as
17 well as C<getName()>.
18  
19 =cut
20  
21 use base qw(Wombat::Valve);
22 use fields qw(container started);
23 use strict;
24 use warnings;
25  
26 =pod
27  
28 =head1 CONSTRUCTOR
29  
30 =over
31  
32 =item new()
33  
34 Construct and return a B<Wombat::Valve::ValveBase> instance,
35 initializing fields appropriately. If subclasses override the
36 constructor, they must be sure to call
37  
38 $self->SUPER::new();
39  
40 =back
41  
42 =cut
43  
44 sub new {
45 my $self = shift;
46  
47 $self = fields::new($self) unless ref $self;
48  
49 $self->{container} = undef;
50 $self->{started} = undef;
51  
52 return $self;
53 }
54  
55 =pod
56  
57 =head1 ACCESSOR METHODS
58  
59 =over
60  
61 =item getContainer()
62  
63 Return the Container to which this Valve is attached.
64  
65 =cut
66  
67 sub getContainer {
68 my $self = shift;
69  
70 return $self->{container};
71 }
72  
73 =pod
74  
75 =item setContainer($container)
76  
77 Set the Container to which this Valve is attached.
78  
79 B<Parameters:>
80  
81 =over
82  
83 =item $container
84  
85 the B<Wombat::Container> to which this Valve is attached.
86  
87 =back
88  
89 =cut
90  
91 sub setContainer {
92 my $self = shift;
93 my $container = shift;
94  
95 $self->{container} = $container;
96  
97 return 1;
98 }
99  
100 =pod
101  
102 =back
103  
104 =head1 PUBLIC METHODS
105  
106 =over
107  
108 =item invoke ($request, $response, $context)
109  
110 Perform request processing as required by this Valve.
111  
112 B<Parameters>
113  
114 =over
115  
116 =item $request
117  
118 the B<Wombat::Request> to be processed
119  
120 =item $response
121  
122 the B<Wombat::Response> to be created
123  
124 =item $context
125  
126 the B<Wombat::ValveContext> allowing access to the next Valve in the
127 Pipeline being processed
128  
129 =back
130  
131 B<Throws:>
132  
133 =over
134  
135 =item B<Servlet::ServletException>
136  
137 if a servlet error occurs or is thrown by a subsequently invoked
138 Valve, Filter or Servlet
139  
140 =item B<Servlet::Util::IOException>
141  
142 if an input or output error occurs
143  
144 =back
145  
146 =cut
147  
148 sub invoke {}
149  
150 =pod
151  
152 =back
153  
154 =head1 PACKAGE METHODS
155  
156 =over
157  
158 =item getName()
159  
160 Return a short name for this Valve implementation. Must be overridden
161 by subclasses.
162  
163 =cut
164  
165 sub getName {}
166  
167 =pod
168  
169 =back
170  
171 =head1 LIFECYCLE METHODS
172  
173 =over
174  
175 =item start()
176  
177 Prepare for active use of this component. This method should be called
178 before any of the public methods of the component are utilized.
179  
180 B<Throws:>
181  
182 =over
183  
184 =item B<Wombat::LifecycleException>
185  
186 if the component has already been started
187  
188 =back
189  
190 =cut
191  
192 sub start {
193 my $self = shift;
194  
195 if ($self->{started}) {
196 my $msg = "start: valve already started";
197 Wombat::LifecycleException->throw($msg);
198 }
199  
200 $self->{started} = 1;
201  
202 return 1;
203 }
204  
205 =pod
206  
207 =item stop()
208  
209 Gracefully terminate active use of this component. Once this method
210 has been called, no public methods of the component should be
211 utilized.
212  
213 B<Throws:>
214  
215 =over
216  
217 =item B<Wombat::LifecycleException>
218  
219 if the component is not started
220  
221 =back
222  
223 =cut
224  
225 sub stop {
226 my $self = shift;
227  
228 unless ($self->{started}) {
229 my $msg = "stop: valve not started";
230 Wombat::LifecycleException->throw($msg);
231 }
232  
233 undef $self->{started};
234  
235 return 1;
236 }
237  
238 =pod
239  
240 =back
241  
242 =cut
243  
244 # private methods
245  
246 sub log {
247 my $self = shift;
248  
249 $self->{container}->log(@_) if $self->{container};
250  
251 return 1;
252 }
253  
254 1;
255 __END__