blib/lib/CGI/Snapp/Demo/Two.pm | |||
---|---|---|---|
Criterion | Covered | Total | % |
statement | 9 | 56 | 16.0 |
branch | n/a | ||
condition | n/a | ||
subroutine | 3 | 15 | 20.0 |
pod | 5 | 12 | 41.6 |
total | 17 | 83 | 20.4 |
line | stmt | bran | cond | sub | pod | time | code |
---|---|---|---|---|---|---|---|
1 | package CGI::Snapp::Demo::Two; | ||||||
2 | |||||||
3 | 1 | 1 | 211190 | use parent 'CGI::Snapp'; | |||
1 | 371 | ||||||
1 | 6 | ||||||
4 | 1 | 1 | 748058 | use strict; | |||
1 | 3 | ||||||
1 | 79 | ||||||
5 | 1 | 1 | 6 | use warnings; | |||
1 | 8 | ||||||
1 | 659 | ||||||
6 | |||||||
7 | our $VERSION = '1.02'; | ||||||
8 | |||||||
9 | # ------------------------------------------------ | ||||||
10 | |||||||
11 | sub build_form | ||||||
12 | { | ||||||
13 | 0 | 0 | 0 | my($self, $run_mode, $next_mode) = @_; | |||
14 | |||||||
15 | 0 | return " "; |
|||||
16 | |||||||
17 | } # End of build_form. | ||||||
18 | |||||||
19 | # ------------------------------------------------ | ||||||
20 | |||||||
21 | sub build_head | ||||||
22 | { | ||||||
23 | 0 | 0 | 0 | my($self) = @_; | |||
24 | 0 | my $localtime = localtime(); | |||||
25 | 0 | my($package) = __PACKAGE__; | |||||
26 | |||||||
27 | 0 | return " The time is: $localtime. "; |
|||||
28 | |||||||
29 | } # End of build_head. | ||||||
30 | |||||||
31 | # ------------------------------------------------ | ||||||
32 | |||||||
33 | sub build_tail | ||||||
34 | { | ||||||
35 | 0 | 0 | 0 | my($self) = @_; | |||
36 | |||||||
37 | 0 | return ''; | |||||
38 | |||||||
39 | } # End of build_tail. | ||||||
40 | |||||||
41 | # ------------------------------------------------ | ||||||
42 | |||||||
43 | sub build_visits | ||||||
44 | { | ||||||
45 | 0 | 0 | 0 | my($self) = @_; | |||
46 | 0 | my($html) = ''; | |||||
47 | 0 | $html .= "Methods visited which are hooked to run before setup(), in which case they can't don't normally contribute to the HTML: cgiapp_init() "; |
|||||
48 | 0 | $html .= ' Methods visited which are not run modes: ' . join(' ', @{$self -> param('non_mode_visited')}) . ' '; |
|||||
0 | |||||||
49 | 0 | $html .= ' Methods visited which are run modes: ' . join(' ', @{$self -> param('run_mode_visited')}) . ' '; |
|||||
0 | |||||||
50 | 0 | $html .= " Methods not visited until after the run mode runs, in which case they can't contribute to the HTML:" . |
|||||
51 | join(' ', 'cgiapp_postrun()', 'teardown()') . ' '; |
||||||
52 | |||||||
53 | 0 | return $html; | |||||
54 | |||||||
55 | } # End of build_visits. | ||||||
56 | |||||||
57 | # -------------------------------------------------- | ||||||
58 | # You don't see the output from this method because it is hooked to run before setup(). | ||||||
59 | |||||||
60 | sub cgiapp_init | ||||||
61 | { | ||||||
62 | 0 | 0 | 1 | my($self) = @_; | |||
63 | |||||||
64 | } # End of cgiapp_init. | ||||||
65 | |||||||
66 | # -------------------------------------------------- | ||||||
67 | |||||||
68 | sub cgiapp_prerun | ||||||
69 | { | ||||||
70 | 0 | 0 | 1 | my($self) = @_; | |||
71 | 0 | my($ara) = $self -> param('non_mode_visited'); | |||||
72 | |||||||
73 | 0 | push @$ara, 'cgiapp_prerun()'; | |||||
74 | |||||||
75 | 0 | $self -> param(non_mode_visited => $ara); | |||||
76 | |||||||
77 | } # End of cgiapp_prerun. | ||||||
78 | |||||||
79 | # -------------------------------------------------- | ||||||
80 | # You don't see the output from this method because it runs after the run modes have build the HTML. | ||||||
81 | |||||||
82 | sub cgiapp_postrun | ||||||
83 | { | ||||||
84 | 0 | 0 | 1 | my($self) = @_; | |||
85 | 0 | my($ara) = $self -> param('non_mode_visited'); | |||||
86 | |||||||
87 | 0 | push @$ara, 'cgiapp_postrun()'; | |||||
88 | |||||||
89 | 0 | $self -> param(non_mode_visited => $ara); | |||||
90 | |||||||
91 | } # End of cgiapp_postrun. | ||||||
92 | |||||||
93 | # ------------------------------------------------ | ||||||
94 | |||||||
95 | sub first_rm_method | ||||||
96 | { | ||||||
97 | 0 | 0 | 0 | my($self) = @_; | |||
98 | 0 | my($ara) = $self -> param('run_mode_visited'); | |||||
99 | |||||||
100 | 0 | push @$ara, 'first_rm_method()'; | |||||
101 | |||||||
102 | 0 | $self -> param(run_mode_visited => $ara); | |||||
103 | |||||||
104 | 0 | return $self -> build_head . $self -> build_form($self -> get_current_runmode, 'second_rm') . $self -> build_visits . $self -> build_tail; | |||||
105 | |||||||
106 | } # End of first_rm_method. | ||||||
107 | |||||||
108 | # ------------------------------------------------ | ||||||
109 | |||||||
110 | sub second_rm_method | ||||||
111 | { | ||||||
112 | 0 | 0 | 0 | my($self) = @_; | |||
113 | 0 | my($ara) = $self -> param('run_mode_visited'); | |||||
114 | |||||||
115 | 0 | push @$ara, 'second_rm_method()'; | |||||
116 | |||||||
117 | 0 | $self -> param(run_mode_visited => $ara); | |||||
118 | |||||||
119 | 0 | return $self -> build_head . $self -> build_form($self -> get_current_runmode, 'third_rm') . $self -> build_visits . $self -> build_tail; | |||||
120 | |||||||
121 | } # End of second_rm_method. | ||||||
122 | |||||||
123 | # ------------------------------------------------ | ||||||
124 | |||||||
125 | sub setup | ||||||
126 | { | ||||||
127 | 0 | 0 | 1 | my($self) = @_; | |||
128 | |||||||
129 | 0 | $self -> param(run_mode_visited => []); | |||||
130 | 0 | $self -> param(non_mode_visited => []); | |||||
131 | 0 | $self -> start_mode('first_rm'); | |||||
132 | 0 | $self -> run_modes(first_rm => 'first_rm_method', second_rm => 'second_rm_method', third_rm => 'third_rm_method'); | |||||
133 | |||||||
134 | } # End of setup. | ||||||
135 | |||||||
136 | # -------------------------------------------------- | ||||||
137 | # You don't see the output from this method because it runs after the run modes have build the HTML. | ||||||
138 | |||||||
139 | sub teardown | ||||||
140 | { | ||||||
141 | 0 | 0 | 1 | my($self) = @_; | |||
142 | |||||||
143 | } # End of teardown. | ||||||
144 | |||||||
145 | # ------------------------------------------------ | ||||||
146 | |||||||
147 | sub third_rm_method | ||||||
148 | { | ||||||
149 | 0 | 0 | 0 | my($self) = @_; | |||
150 | 0 | my($ara) = $self -> param('run_mode_visited'); | |||||
151 | |||||||
152 | 0 | push @$ara, 'third_rm_method()'; | |||||
153 | |||||||
154 | 0 | $self -> param(run_mode_visited => $ara); | |||||
155 | |||||||
156 | 0 | return $self -> build_head . $self -> build_form($self -> get_current_runmode, 'first_rm') . $self -> build_visits . $self -> build_tail; | |||||
157 | |||||||
158 | } # End of third_rm_method. | ||||||
159 | |||||||
160 | # ------------------------------------------------ | ||||||
161 | |||||||
162 | 1; | ||||||
163 | |||||||
164 | =pod | ||||||
165 | |||||||
166 | =head1 NAME | ||||||
167 | |||||||
168 | CGI::Snapp::Demo::Two - A template-free demo of CGI::Snapp using N run modes | ||||||
169 | |||||||
170 | =head1 Synopsis | ||||||
171 | |||||||
172 | After installing the module, do one or both of: | ||||||
173 | |||||||
174 | =over 4 | ||||||
175 | |||||||
176 | =item o Use the L |
||||||
177 | |||||||
178 | Unpack the distro and copy http/cgi-bin/cgi.snapp.two.cgi to your web server's cgi-bin/ directory, and make it executable. | ||||||
179 | |||||||
180 | Then browse to http://127.0.0.1/cgi-bin/cgi.snapp.two.cgi. | ||||||
181 | |||||||
182 | =item o Use the L |
||||||
183 | |||||||
184 | Note: In order to not require users to install L |
||||||
185 | |||||||
186 | Edit httpd/cgi-bin/cgi.snapp.two.psgi and change my value for the web server's doc root from /dev/shm/html to match your set up. | ||||||
187 | |||||||
188 | /dev/shm/ is a directory provided by L |
||||||
189 | |||||||
190 | Then, install L |
||||||
191 | |||||||
192 | =over 4 | ||||||
193 | |||||||
194 | =item o Use L |
||||||
195 | |||||||
196 | Start starman with: starman -l 127.0.0.1:5172 --workers 1 httpd/cgi-bin/cgi.snapp.two.psgi & | ||||||
197 | |||||||
198 | =item o Use L |
||||||
199 | |||||||
200 | Start plackup with: plackup -l 127.0.0.1:5172 httpd/cgi-bin/cgi.snapp.two.psgi & | ||||||
201 | |||||||
202 | =back | ||||||
203 | |||||||
204 | Then, with either starman or plackup, direct your browser to hit 127.0.0.1:5172/. | ||||||
205 | |||||||
206 | These commands are copied from comments within httpd/cgi-bin/cgi.snapp.two.psgi. The value 5172 is of course just a suggestion. All demos in this series use port 5171 and up. | ||||||
207 | |||||||
208 | =back | ||||||
209 | |||||||
210 | =head1 Description | ||||||
211 | |||||||
212 | Shows how to write a CGI script using L |
||||||
213 | |||||||
214 | The output reports which methods were and were not entered per run mode. | ||||||
215 | |||||||
216 | =head1 Distributions | ||||||
217 | |||||||
218 | This module is available as a Unix-style distro (*.tgz). | ||||||
219 | |||||||
220 | See L |
||||||
221 | for help on unpacking and installing distros. | ||||||
222 | |||||||
223 | =head1 Installation | ||||||
224 | |||||||
225 | Install L |
||||||
226 | |||||||
227 | Run: | ||||||
228 | |||||||
229 | cpanm CGI::Snapp::Demo::Two | ||||||
230 | |||||||
231 | or run: | ||||||
232 | |||||||
233 | sudo cpan CGI::Snapp::Demo::Two | ||||||
234 | |||||||
235 | or unpack the distro, and then either: | ||||||
236 | |||||||
237 | perl Build.PL | ||||||
238 | ./Build | ||||||
239 | ./Build test | ||||||
240 | sudo ./Build install | ||||||
241 | |||||||
242 | or: | ||||||
243 | |||||||
244 | perl Makefile.PL | ||||||
245 | make (or dmake or nmake) | ||||||
246 | make test | ||||||
247 | make install | ||||||
248 | |||||||
249 | =head1 Constructor and Initialization | ||||||
250 | |||||||
251 | C |
||||||
252 | |||||||
253 | It returns a new object of type C |
||||||
254 | |||||||
255 | See http/cgi-bin/cgi.snapp.two.cgi. | ||||||
256 | |||||||
257 | =head1 Methods | ||||||
258 | |||||||
259 | =head2 run() | ||||||
260 | |||||||
261 | Runs the code which responds to HTTP requests. | ||||||
262 | |||||||
263 | See http/cgi-bin/cgi.snapp.two.cgi. | ||||||
264 | |||||||
265 | =head1 Troubleshooting | ||||||
266 | |||||||
267 | =head2 It doesn't work! | ||||||
268 | |||||||
269 | Hmmm. Things to consider: | ||||||
270 | |||||||
271 | =over 4 | ||||||
272 | |||||||
273 | =item o Run the *.cgi script from the command line | ||||||
274 | |||||||
275 | shell> perl httpd/cgi-bin/cgi.snapp.two.cgi | ||||||
276 | |||||||
277 | If that doesn't work, you're in b-i-g trouble. Keep reading for suggestions as to what to do next. | ||||||
278 | |||||||
279 | =item o The system Perl 'v' perlbrew | ||||||
280 | |||||||
281 | Are you using perlbrew? If so, recall that your web server will use the first line of http/cgi-bin/cgi.snapp.two.cgi to find a Perl, and that line says #!/usr/bin/env perl. | ||||||
282 | |||||||
283 | So, you'd better turn perlbrew off and install L |
||||||
284 | |||||||
285 | =item o Generic advice | ||||||
286 | |||||||
287 | L |
||||||
288 | |||||||
289 | =back | ||||||
290 | |||||||
291 | =head1 See Also | ||||||
292 | |||||||
293 | L |
||||||
294 | |||||||
295 | The following are all part of this set of distros: | ||||||
296 | |||||||
297 | L |
||||||
298 | |||||||
299 | L |
||||||
300 | |||||||
301 | L |
||||||
302 | |||||||
303 | L |
||||||
304 | |||||||
305 | L |
||||||
306 | |||||||
307 | L |
||||||
308 | |||||||
309 | L |
||||||
310 | |||||||
311 | L |
||||||
312 | |||||||
313 | L |
||||||
314 | |||||||
315 | L |
||||||
316 | |||||||
317 | L |
||||||
318 | |||||||
319 | =head1 Machine-Readable Change Log | ||||||
320 | |||||||
321 | The file CHANGES was converted into Changelog.ini by L |
||||||
322 | |||||||
323 | =head1 Version Numbers | ||||||
324 | |||||||
325 | Version numbers < 1.00 represent development versions. From 1.00 up, they are production versions. | ||||||
326 | |||||||
327 | =head1 Support | ||||||
328 | |||||||
329 | Email the author, or log a bug on RT: | ||||||
330 | |||||||
331 | L |
||||||
332 | |||||||
333 | =head1 Author | ||||||
334 | |||||||
335 | L |
||||||
336 | |||||||
337 | Home page: L |
||||||
338 | |||||||
339 | =head1 Copyright | ||||||
340 | |||||||
341 | Australian copyright (c) 2012, Ron Savage. | ||||||
342 | |||||||
343 | All Programs of mine are 'OSI Certified Open Source Software'; | ||||||
344 | you can redistribute them and/or modify them under the terms of | ||||||
345 | The Artistic License, a copy of which is available at: | ||||||
346 | http://www.opensource.org/licenses/index.html | ||||||
347 | |||||||
348 | =cut |