File Coverage

blib/lib/CGI/Snapp/Demo/Four.pm
Criterion Covered Total %
statement 9 64 14.0
branch n/a
condition n/a
subroutine 3 13 23.0
pod 3 10 30.0
total 15 87 17.2


line stmt bran cond sub pod time code
1             package CGI::Snapp::Demo::Four;
2              
3 1     1   25535 use parent 'CGI::Snapp';
  1         334  
  1         6  
4 1     1   130598 use strict;
  1         3  
  1         43  
5 1     1   6 use warnings;
  1         8  
  1         728  
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           $self -> log(debug => "build_form($run_mode, $next_mode)");
16              
17 0           return "
This is run mode '$run_mode'.
";
18              
19             } # End of build_form.
20              
21             # ------------------------------------------------
22              
23             sub build_head
24             {
25 0     0 0   my($self) = @_;
26              
27 0           $self -> log(debug => 'build_head()');
28              
29 0           my $localtime = localtime();
30 0           my($package) = __PACKAGE__;
31              
32 0           return "$packageThis module is: $package.
The time is: $localtime.
";
33              
34             } # End of build_head.
35              
36             # ------------------------------------------------
37              
38             sub build_tail
39             {
40 0     0 0   my($self) = @_;
41              
42 0           $self -> log(debug => 'build_tail()');
43              
44 0           return '';
45              
46             } # End of build_tail.
47              
48             # ------------------------------------------------
49              
50             sub build_visits
51             {
52 0     0 0   my($self) = @_;
53              
54 0           $self -> log(debug => 'build_visits()');
55              
56 0           my($html) = '';
57 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()
";
58 0           $html .= '
Methods visited which are not run modes:
' . join('
', @{$self -> param('non_mode_visited')}) . '
';
  0            
59 0           $html .= '
Methods visited which are run modes:
' . join('
', @{$self -> param('run_mode_visited')}) . '
';
  0            
60 0           $html .= "
Methods not visited until after the run mode runs,
in which case they can't contribute to the HTML:
" .
61             join('
', 'cgiapp_postrun()', 'teardown()') . '
';
62              
63 0           return $html;
64              
65             } # End of build_visits.
66              
67             # --------------------------------------------------
68              
69             sub cgiapp_prerun
70             {
71 0     0 1   my($self) = @_;
72 0           my($ara) = $self -> param('non_mode_visited');
73              
74 0           $self -> log(debug => 'cgiapp_prerun()');
75              
76 0           push @$ara, 'cgiapp_prerun()';
77              
78 0           $self -> param(non_mode_visited => $ara);
79              
80             } # End of cgiapp_prerun.
81              
82             # --------------------------------------------------
83             # You don't see the output from this method because it runs after the run modes have build the HTML.
84              
85             sub cgiapp_postrun
86             {
87 0     0 1   my($self) = @_;
88 0           my($ara) = $self -> param('non_mode_visited');
89              
90 0           $self -> log(debug => 'cgiapp_postrun()');
91              
92 0           push @$ara, 'cgiapp_postrun()';
93              
94 0           $self -> param(non_mode_visited => $ara);
95              
96             } # End of cgiapp_postrun.
97              
98             # ------------------------------------------------
99              
100             sub first_rm_method
101             {
102 0     0 0   my($self) = @_;
103 0           my($ara) = $self -> param('run_mode_visited');
104              
105 0           $self -> log(debug => 'first_rm_method()');
106              
107 0           push @$ara, 'first_rm_method()';
108              
109 0           $self -> param(run_mode_visited => $ara);
110              
111 0           return $self -> build_head . $self -> build_form($self -> get_current_runmode, 'second_rm') . $self -> build_visits . $self -> build_tail;
112              
113             } # End of first_rm_method.
114              
115             # ------------------------------------------------
116              
117             sub second_rm_method
118             {
119 0     0 0   my($self) = @_;
120 0           my($ara) = $self -> param('run_mode_visited');
121              
122 0           $self -> log(debug => 'second_rm_method()');
123              
124 0           push @$ara, 'second_rm_method()';
125              
126 0           $self -> param(run_mode_visited => $ara);
127              
128 0           return $self -> build_head . $self -> build_form($self -> get_current_runmode, 'third_rm') . $self -> build_visits . $self -> build_tail;
129              
130             } # End of second_rm_method.
131              
132             # ------------------------------------------------
133              
134             sub setup
135             {
136 0     0 1   my($self) = @_;
137              
138 0           $self -> log(debug => 'setup()');
139              
140 0           $self -> param(run_mode_visited => []);
141 0           $self -> param(non_mode_visited => []);
142 0           $self -> start_mode('first_rm');
143 0           $self -> run_modes(first_rm => 'first_rm_method', second_rm => 'second_rm_method', third_rm => 'third_rm_method');
144              
145             } # End of setup.
146              
147             # ------------------------------------------------
148              
149             sub third_rm_method
150             {
151 0     0 0   my($self) = @_;
152 0           my($ara) = $self -> param('run_mode_visited');
153              
154 0           $self -> log(debug => 'third_rm_method()');
155              
156 0           push @$ara, 'third_rm_method()';
157              
158 0           $self -> param(run_mode_visited => $ara);
159              
160 0           return $self -> build_head . $self -> build_form($self -> get_current_runmode, 'first_rm') . $self -> build_visits . $self -> build_tail;
161              
162             } # End of third_rm_method.
163              
164             # ------------------------------------------------
165              
166             1;
167              
168             =pod
169              
170             =head1 NAME
171              
172             CGI::Snapp::Demo::Four - A template-free demo of CGI::Snapp using Log::Handler::Plugin::DBI
173              
174             =head1 Synopsis
175              
176             After installing the module (see L), do one or both of:
177              
178             =over 4
179              
180             =item o Use the L script
181              
182             Unpack the distro and copy http/cgi-bin/cgi.snapp.four.cgi to your web server's cgi-bin/ directory, and make it executable.
183              
184             Then browse to http://127.0.0.1/cgi-bin/cgi.snapp.four.cgi.
185              
186             =item o Use the L script
187              
188             Note: In order to not require users to install L or L, they have been commented out in Build.PL and Makefile.PL.
189              
190             Edit httpd/cgi-bin/cgi.snapp.four.psgi and change my value for the web server's doc root from /dev/shm/html to match your set up.
191              
192             /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/.
193              
194             Then, install L and L and then do one or both of:
195              
196             =over 4
197              
198             =item o Use L
199              
200             Start starman with: starman -l 127.0.0.1:5174 --workers 1 httpd/cgi-bin/cgi.snapp.four.psgi &
201              
202             =item o Use L
203              
204             Start plackup with: plackup -l 127.0.0.1:5174 httpd/cgi-bin/cgi.snapp.four.psgi &
205              
206             =back
207              
208             Then, with either starman or plackup, direct your browser to hit 127.0.0.1:5174/.
209              
210             These commands are copied from comments within httpd/cgi-bin/cgi.snapp.four.psgi. The value 5174 is of course just a suggestion. All demos in this series use port 5171 and up.
211              
212             =back
213              
214             =head1 Description
215              
216             This is a version of L which shows how to use a plugin such as L within a CGI script based on L.
217              
218             The output reports which methods were and were not entered per run mode.
219              
220             Using a plugin easily requires a wrapper class, which here is L. That's why httpd/cgi-bin/cgi.snapp.demo.four.cgi uses the wrapper instead
221             of using this module directly.
222              
223             =head1 Distributions
224              
225             This module is available as a Unix-style distro (*.tgz).
226              
227             See L
228             for help on unpacking and installing distros.
229              
230             =head1 Installation
231              
232             =head2 Installing the module
233              
234             Install L as you would for any C module:
235              
236             Run:
237              
238             cpanm CGI::Snapp::Demo::Four
239              
240             or run:
241              
242             sudo cpan CGI::Snapp::Demo::Four
243              
244             or unpack the distro, and then either:
245              
246             perl Build.PL
247             ./Build
248             ./Build test
249             sudo ./Build install
250              
251             or:
252              
253             perl Makefile.PL
254             make (or dmake or nmake)
255             make test
256             make install
257              
258             =head2 Configuring the L script's source code and the logger's config file
259              
260             You I edit both the source code of httpd/cgi-bin/cgi.snapp.demo.four.cgi and the config (text) file, to make this demo work.
261              
262             Details:
263              
264             =over 4
265              
266             =item o The L script's source code
267              
268             In cgi.snapp.demo.four.cgi you'll see this code (which is my default set up, /dev/shm/ being Debian's RAM disk):
269              
270             my($doc_root) = $ENV{DOC_ROOT} || '/dev/shm';
271             my($config_dir) = "$doc_root/assets/config/cgi/snapp/demo/four";
272             my($config_file) = "$config_dir/config.logger.conf";
273              
274             Adjust those 3 lines to suit your environment.
275              
276             Then copy cgi.snapp.demo.four.cgi to your web server's cgi-bin/ directory, and make it executable.
277              
278             =item o The logger's config file
279              
280             This module ships with t/config.logger.conf, which is a copy of the same file from L.
281              
282             So, copy the file t/config.logger.conf to $config_file, as above, and edit it as desired.
283              
284             L ships with a program, scripts/create.table.pl, which can be used to create the 'log' table, using this very config file.
285              
286             That module's L describes the expected structure of the 'log' table.
287              
288             =back
289              
290             With everything in place, and having run the L script from the command line (as recommended in L), continue with the procedure suggested in the L.
291              
292             =head1 Constructor and Initialization
293              
294             C is called as C<< my($app) = CGI::Snapp::Demo::Four -> new(k1 => v1, k2 => v2, ...) >>.
295              
296             It returns a new object of type C.
297              
298             See http/cgi-bin/cgi.snapp.four.cgi.
299              
300             =head1 Methods
301              
302             =head2 run()
303              
304             Runs the code which responds to HTTP requests.
305              
306             See http/cgi-bin/cgi.snapp.four.cgi.
307              
308             =head1 Troubleshooting
309              
310             =head2 It doesn't work!
311              
312             Hmmm. Things to consider:
313              
314             =over 4
315              
316             =item o Run the *.cgi script from the command line
317              
318             shell> perl httpd/cgi-bin/cgi.snapp.four.cgi
319              
320             If that doesn't work, you're in b-i-g trouble. Keep reading for suggestions as to what to do next.
321              
322             =item o Check your edits to Four.pm and config.logger.conf
323              
324             Most likely the edits are wrong, or the files are installed in the wrong directories, or the file permissions are wrong.
325              
326             =item o The system Perl 'v' perlbrew
327              
328             Are you using perlbrew? If so, recall that your web server will use the first line of http/cgi-bin/cgi.snapp.four.cgi to find a Perl, and that line says #!/usr/bin/env perl.
329              
330             So, you'd better turn perlbrew off and install this module under the system Perl, before trying again.
331              
332             =item o Generic advice
333              
334             L.
335              
336             =back
337              
338             =head1 See Also
339              
340             L
341              
342             The following are all part of this set of distros:
343              
344             L - A almost back-compat fork of CGI::Application
345              
346             L - A template-free demo of CGI::Snapp using just 1 run mode
347              
348             L - A template-free demo of CGI::Snapp using N run modes
349              
350             L - A template-free demo of CGI::Snapp using the forward() method
351              
352             L - A template-free demo of CGI::Snapp using Log::Handler::Plugin::DBI
353              
354             L - A wrapper around CGI::Snapp::Demo::Four, to simplify using Log::Handler::Plugin::DBI
355              
356             L - A plugin which uses Config::Tiny
357              
358             L - A plugin which uses Config::Tiny with 1 of N sections
359              
360             L - Persistent session data management
361              
362             L - A plugin for Log::Handler using Log::Hander::Output::DBI
363              
364             L - A helper for Log::Hander::Output::DBI to create your 'log' table
365              
366             =head1 Machine-Readable Change Log
367              
368             The file CHANGES was converted into Changelog.ini by L.
369              
370             =head1 Version Numbers
371              
372             Version numbers < 1.00 represent development versions. From 1.00 up, they are production versions.
373              
374             =head1 Support
375              
376             Email the author, or log a bug on RT:
377              
378             L.
379              
380             =head1 Author
381              
382             L was written by Ron Savage Iron@savage.net.auE> in 2012.
383              
384             Home page: L.
385              
386             =head1 Copyright
387              
388             Australian copyright (c) 2012, Ron Savage.
389              
390             All Programs of mine are 'OSI Certified Open Source Software';
391             you can redistribute them and/or modify them under the terms of
392             The Artistic License, a copy of which is available at:
393             http://www.opensource.org/licenses/index.html
394              
395             =cut