File Coverage

blib/lib/CGI/Snapp/Demo/Three.pm
Criterion Covered Total %
statement 9 61 14.7
branch n/a
condition n/a
subroutine 3 16 18.7
pod 5 13 38.4
total 17 90 18.8


line stmt bran cond sub pod time code
1             package CGI::Snapp::Demo::Three;
2              
3 1     1   23812 use parent 'CGI::Snapp';
  1         397  
  1         6  
4 1     1   81095 use strict;
  1         3  
  1         40  
5 1     1   6 use warnings;
  1         9  
  1         761  
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 "
This is run mode '$run_mode'.
";
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 "$packageThis module is: $package.
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 -> add_callback('forward_prerun', 'third_rm_prerun');
130 0           $self -> param(run_mode_visited => []);
131 0           $self -> param(non_mode_visited => []);
132 0           $self -> start_mode('first_rm');
133 0           $self -> run_modes(first_rm => 'first_rm_method', second_rm => 'second_rm_method', third_rm => 'third_rm_method');
134              
135             } # End of setup.
136              
137             # --------------------------------------------------
138             # You don't see the output from this method because it runs after the run modes have build the HTML.
139              
140             sub teardown
141             {
142 0     0 1   my($self) = @_;
143              
144             } # End of teardown.
145              
146             # ------------------------------------------------
147              
148             sub third_rm_method
149             {
150 0     0 0   my($self) = @_;
151 0           my($ara) = $self -> param('run_mode_visited');
152              
153 0           push @$ara, 'third_rm_method()';
154              
155 0           $self -> param(run_mode_visited => $ara);
156              
157 0           return $self -> forward('first_rm');
158              
159             } # End of third_rm_method.
160              
161             # --------------------------------------------------
162              
163             sub third_rm_prerun
164             {
165 0     0 0   my($self) = @_;
166 0           my($ara) = $self -> param('run_mode_visited');
167              
168 0           push @$ara, 'third_rm_prerun()';
169              
170 0           $self -> param(run_mode_visited => $ara);
171              
172             } # End of third_rm_prerun.
173              
174             # ------------------------------------------------
175              
176             1;
177              
178             =pod
179              
180             =head1 NAME
181              
182             CGI::Snapp::Demo::Three - A template-free demo of CGI::Snapp using the forward() method
183              
184             =head1 Synopsis
185              
186             After installing the module, do one or both of:
187              
188             =over 4
189              
190             =item o Use the L script
191              
192             Unpack the distro and copy http/cgi-bin/cgi.snapp.three.cgi to your web server's cgi-bin/ directory, and make it executable.
193              
194             Then browse to http://127.0.0.1/cgi-bin/cgi.snapp.three.cgi.
195              
196             =item o Use the L script
197              
198             Note: In order to not require users to install L or L, they have been commented out in Build.PL and Makefile.PL.
199              
200             Edit httpd/cgi-bin/cgi.snapp.three.psgi and change my value for the web server's doc root from /dev/shm/html to match your set up.
201              
202             /dev/shm/ is a directory provided by L which is actually a RAM disk, and within that my doc root is the sub-directory /dev/shm/html/.
203              
204             Then, install L and L and then do one or both of:
205              
206             =over 4
207              
208             =item o Use L
209              
210             Start starman with: starman -l 127.0.0.1:5173 --workers 1 httpd/cgi-bin/cgi.snapp.three.psgi &
211              
212             =item o Use L
213              
214             Start plackup with: plackup -l 127.0.0.1:5173 httpd/cgi-bin/cgi.snapp.three.psgi &
215              
216             =back
217              
218             Then, with either starman or plackup, direct your browser to hit 127.0.0.1:5173/.
219              
220             These commands are copied from comments within httpd/cgi-bin/cgi.snapp.three.psgi. The value 5173 is of course just a suggestion. All demos in this series use port 5171 and up.
221              
222             =back
223              
224             =head1 Description
225              
226             Shows how to use the forward() method to interrupt processing of a run mode.
227              
228             The output reports which methods were and were not entered per run mode.
229              
230             Also, it shows how to hook the 'forward_prerun' hook.
231              
232             =head1 Distributions
233              
234             This module is available as a Unix-style distro (*.tgz).
235              
236             See L
237             for help on unpacking and installing distros.
238              
239             =head1 Installation
240              
241             Install L as you would for any C module:
242              
243             Run:
244              
245             cpanm CGI::Snapp::Demo::Three
246              
247             or run:
248              
249             sudo cpan CGI::Snapp::Demo::Three
250              
251             or unpack the distro, and then either:
252              
253             perl Build.PL
254             ./Build
255             ./Build test
256             sudo ./Build install
257              
258             or:
259              
260             perl Makefile.PL
261             make (or dmake or nmake)
262             make test
263             make install
264              
265             =head1 Constructor and Initialization
266              
267             C is called as C<< my($app) = CGI::Snapp::Demo::Three -> new(k1 => v1, k2 => v2, ...) >>.
268              
269             It returns a new object of type C.
270              
271             See http/cgi-bin/cgi.snapp.three.cgi.
272              
273             =head1 Methods
274              
275             =head2 run()
276              
277             Runs the code which responds to HTTP requests.
278              
279             See http/cgi-bin/cgi.snapp.three.cgi.
280              
281             =head1 Troubleshooting
282              
283             =head2 It doesn't work!
284              
285             Hmmm. Things to consider:
286              
287             =over 4
288              
289             =item o Run the *.cgi script from the command line
290              
291             shell> perl httpd/cgi-bin/cgi.snapp.three.cgi
292              
293             If that doesn't work, you're in b-i-g trouble. Keep reading for suggestions as to what to do next.
294              
295             =item o The system Perl 'v' perlbrew
296              
297             Are you using perlbrew? If so, recall that your web server will use the first line of http/cgi-bin/cgi.snapp.three.cgi to find a Perl, and that line says #!/usr/bin/env perl.
298              
299             So, you'd better turn perlbrew off and install L and this module under the system Perl, before trying again.
300              
301             =item o Generic advice
302              
303             L.
304              
305             =back
306              
307             =head1 See Also
308              
309             L
310              
311             The following are all part of this set of distros:
312              
313             L - A almost back-compat fork of CGI::Application
314              
315             L - A template-free demo of CGI::Snapp using just 1 run mode
316              
317             L - A template-free demo of CGI::Snapp using N run modes
318              
319             L - A template-free demo of CGI::Snapp using the forward() method
320              
321             L - A template-free demo of CGI::Snapp using Log::Handler::Plugin::DBI
322              
323             L - A wrapper around CGI::Snapp::Demo::Four, to simplify using Log::Handler::Plugin::DBI
324              
325             L - A plugin which uses Config::Tiny
326              
327             L - A plugin which uses Config::Tiny with 1 of N sections
328              
329             L - Persistent session data management
330              
331             L - A plugin for Log::Handler using Log::Hander::Output::DBI
332              
333             L - A helper for Log::Hander::Output::DBI to create your 'log' table
334              
335             =head1 Machine-Readable Change Log
336              
337             The file CHANGES was converted into Changelog.ini by L.
338              
339             =head1 Version Numbers
340              
341             Version numbers < 1.00 represent development versions. From 1.00 up, they are production versions.
342              
343             =head1 Support
344              
345             Email the author, or log a bug on RT:
346              
347             L.
348              
349             =head1 Author
350              
351             L was written by Ron Savage Iron@savage.net.auE> in 2012.
352              
353             Home page: L.
354              
355             =head1 Copyright
356              
357             Australian copyright (c) 2012, Ron Savage.
358              
359             All Programs of mine are 'OSI Certified Open Source Software';
360             you can redistribute them and/or modify them under the terms of
361             The Artistic License, a copy of which is available at:
362             http://www.opensource.org/licenses/index.html
363              
364             =cut