blib/lib/CGI/Application/Plugin/Nes.pm

filter: Statementstmt 64.4% 29 / 45 Branchbran 33.3% 2 / 6 Conditioncond 50.0% 4 / 8 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 71.4% 5 / 7 Podpod 66.6% 2 / 3 totaltotal 57.5% 42 / 73 SCAR 12.8
CC
3
Cov
59%
cgiapp_get_query
6.0
nes_init
2.0
cgiapp_init
2.0
CRAP 3.6
↑ Summary
1 # -----------------------------------------------------------------------------
2 #
3 # CGI::Application::Plugin::Nes by Skriptke
4 # Copyright 2009 - 2010 Enrique F. Castañón Barbero
5 #
6 # Plugin for use Nes in CGI::Application
7 # Requires Nes 1.03.3 or higher
8 #
9 # -----------------------------------------------------------------------------
10  
11 package CGI::Application::Plugin::Nes;
12  
13 1 our $VERSION = '0.00_1';
14  
15 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 1 ▶use Nes;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use base 'CGI::Application';
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 1 ▶our $MOD_PERL = $ENV{'MOD_PERL'} || 0;
Condition50%1/2
$ENV{'MOD_PERL'} || 0
l!l
01
MC/DC0%0/1
$ENV{'MOD_PERL'} || 0
$ENV{'MOD_PERL'}
Truth table50%1/2
A
A= $ENV{'MOD_PERL'}
Aresult
11
00
22 1 ▶our $MOD_PERL1 = $MOD_PERL =~ /mod_perl\/1/ || 0;
Condition50%1/2
$CGI::Application::Plugin::Nes::MOD_PERL =~ m[mod_perl/1] || 0
l!l
01
MC/DC0%0/1
$CGI::Application::Plugin::Nes::MOD_PERL =~ m[mod_perl/1] || 0
$CGI::Application::Plugin::Nes::MOD_PERL =~ m[mod_perl/1]
Truth table50%1/2
A
A= $CGI::Application::Plugin::Nes::MOD_PERL =~ m[mod_perl/1]
Aresult
11
00
23 1 ▶our $MOD_PERL2 = $MOD_PERL =~ /mod_perl\/2/ || 0;
Condition50%1/2
$CGI::Application::Plugin::Nes::MOD_PERL =~ m[mod_perl/2] || 0
l!l
01
MC/DC0%0/1
$CGI::Application::Plugin::Nes::MOD_PERL =~ m[mod_perl/2] || 0
$CGI::Application::Plugin::Nes::MOD_PERL =~ m[mod_perl/2]
Truth table50%1/2
A
A= $CGI::Application::Plugin::Nes::MOD_PERL =~ m[mod_perl/2]
Aresult
11
00
24  
25 1 &nes_init;
26  
27 1 ▶if ( $MOD_PERL2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($CGI::Application::Plugin::Nes::MOD_PERL2) 0 1 1
28 0 require Apache2::RequestUtil;
29 0 require Apache2::RequestIO;
30 0 require APR::Pool;
31 0 Apache2::RequestUtil->request->pool->cleanup_register(\&nes_init);
32 }
33
34 1 ▶if ( $MOD_PERL1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($CGI::Application::Plugin::Nes::MOD_PERL1) 0 1 1
35 0 require Apache;
36 0 Apache->request->register_cleanup(\&nes_init);
37 }
38  
39 sub nes_init {
40
41 1 ▶ $ENV{'CGI_APP_RETURN_ONLY'} = 1;
Subroutine nes_init: called CC=2 SCAR=6.9
Pod undocumented
42 1 $ENV{'CGI_APP_NES_BY_CGI'} = 0;
43 1 $ENV{'CGI_APP_NES_DIR'} = '';
44 1 $ENV{'CGI_APP_NES_DIR_CGI'} = '';
45
46 1 ▶ $CGI::Application::Plugin::Nes::top_script = $ENV{'SCRIPT_FILENAME'} || '';
Condition50%1/2
$ENV{'SCRIPT_FILENAME'} || ''
l!l
01
MC/DC0%0/1
$ENV{'SCRIPT_FILENAME'} || ''
$ENV{'SCRIPT_FILENAME'}
Truth table50%1/2
A
A= $ENV{'SCRIPT_FILENAME'}
Aresult
11
00
47 1 $CGI::Application::Plugin::Nes::top_dir = $CGI::Application::Plugin::Nes::top_script;
48 1 $CGI::Application::Plugin::Nes::top_dir =~ s/\/[^\/]*\.cgi|pl$//;
49 1 $CGI::Application::Plugin::Nes::top_template = $CGI::Application::Plugin::Nes::top_script;
50 1 $CGI::Application::Plugin::Nes::top_template =~ s/\.cgi|pl$/\.nhtml/;
51
52 }
53  
54 sub cgiapp_init {
55 0 ▶ my $self = shift;
Subroutine cgiapp_init: not called CC=1 SCAR=6.9
Pod documented
56 0 my @args = (@_);
57  
58 0 $self->SUPER::cgiapp_init(@args);
59
60 $self->{'nes_instance'} = Nes::Singleton->new(
61 $CGI::Application::Plugin::Nes::top_template,
62 $ENV{'CGI_APP_NES_DIR'},
63 0 $ENV{'CGI_APP_NES_DIR_CGI'}
64 );
65  
66 }
67  
68 sub cgiapp_get_query {
69 0 ▶ my $self = shift;
Subroutine cgiapp_get_query: not called CC=2 SCAR=17.9
Pod documented
70  
71 0 my $q;
72
73 0 ▶ if ( $ENV{'CGI_APP_NES_BY_CGI'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{'CGI_APP_NES_BY_CGI'}) { } 0 0 0
74  
75 0 $q = $self->{'nes_instance'}->{'query'}->by_CGI;
76  
77 } else {
78  
79 0 $q = $self->{'nes_instance'}->{'query'};
80  
81 }
82
83 0 return $q;
84
85 }
86  
87  
88 =head1 NAME
89  
90 CGI::Application::Plugin::Nes - Nes templates in CGI::Application
91  
92 =head1 SYNOPSIS
93  
94 use base 'CGI::Application::Plugin::Nes';
95  
96 # compatibility with CGI.pm (slightly slower)
97 # $ENV{CGI_APP_NES_BY_CGI} = 1;
98  
99 # require if exec by .cgi
100 # $ENV{CGI_APP_NES_DIR} = '/full/path/to/cgi-bin/nes';
101  
102 =head1 DESCRIPTION
103  
104 Plugin for use L<Nes> templates in L<CGI::Application>. You can use any Nes
105 object or plugin, PHP, SH, PYTHON, ... in CGI::Application.
106  
107 Live sample: L<http://nes.sourceforge.net/hello_nes/tests-cgiapp/index.nhtml>
108  
109 =head1 INPLEMENTATION
110  
111 In your .pm file instead of:
112  
113 use base 'CGI::Application';
114  
115 used:
116  
117 use base 'CGI::Application::Plugin::Nes';
118  
119 In addition to your myapp.cgi file, creates a nhtml file with the same name
120 for the Top Nes template:
121  
122 myapp.cgi:
123  
124 use MyApp;
125 my $app = MyApp->new();
126 $app->run();
127 1; # cgi should return 1 as the pm files.
128  
129 myapp.nhtml:
130  
131 {: NES 1.0 ('myapp.cgi') :}
132 <html>
133 <head>
134 ...
135  
136 If you run your application by the CGI, you need to put the following
137 variable the full path to Nes cgi-bin directory in your .pm or .cgi file:
138  
139 $ENV{CGI_APP_NES_DIR} = '/full/path/to/cgi-bin/nes';
140  
141 This is necessary for:
142  
143 http://example.com/myapp.cgi
144  
145 It is not necessary for:
146  
147 http://example.com/myapp.nhtml
148  
149 For compatibility with CGI.pm:
150  
151 $ENV{CGI_APP_NES_BY_CGI} = 1;
152  
153 It's a bit slower than letting to Nes handle the query.
154  
155 =head1 Compare
156  
157 See L<http://cgi-app.org/index.cgi?LoginLogoutExampleApp>
158  
159 Code in CGI::Application::Plugin::Nes for a similar result:
160  
161 package MinimalAppNes;
162 use base 'CGI::Application::Plugin::Nes';
163 use strict;
164  
165 # require if exec by .cgi
166 # $ENV{CGI_APP_NES_DIR} = '/full/path/to/cgi-bin/nes';
167  
168 sub setup {
169 my $self = shift;
170 $self->start_mode('index');
171 $self->mode_param('action');
172 $self->run_modes(
173 'index' => 'index',
174 'logout' => 'logout',
175 );
176 }
177  
178 sub index {
179 my $self = shift;
180 # only three lines of Perl script is necessary for generate form login
181 my %nes_tags;
182 $nes_tags{'action'} = 'login.nhtml';
183 Nes::Singleton->instance->out(%nes_tags);
184 }
185  
186 sub logout {
187 my $self = shift;
188 my %nes_tags;
189 $nes_tags{'action'} = 'logout.nhtml';
190 Nes::Singleton->instance->out(%nes_tags);
191 }
192  
193  
194 In the instalation package see share/examples/compare directory
195  
196 =head1 BUGS
197  
198  
199  
200 =head1 TODO
201  
202  
203  
204 =head1 AUTHOR
205  
206 Skriptke: Enrique Castañón
207  
208 =head1 VERSION
209  
210 Version 0.00_1
211  
212 =head1 COPYRIGHT
213  
214 Copyright (c) Enrique F. Castanon Barbero. All rights reserved.
215  
216 =head1 LICENSE
217  
218 This program is free software; you can redistribute it and/or modify it
219 under the same terms as Perl itself.
220  
221 See http://dev.perl.org/licenses/
222  
223 =head1 DISCLAIMER
224  
225 THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS
226 OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE
227 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
228 PARTICULAR PURPOSE.
229  
230 Use of this software in any way or in any form, source or binary,
231 is not allowed in any country which prohibits disclaimers of any
232 implied warranties of merchantability or fitness for a particular
233 purpose or any disclaimers of a similar nature.
234  
235 IN NO EVENT SHALL I BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
236 SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
237 USE OF THIS SOFTWARE AND ITS DOCUMENTATION (INCLUDING, BUT NOT
238 LIMITED TO, LOST PROFITS) EVEN IF I HAVE BEEN ADVISED OF THE
239 POSSIBILITY OF SUCH DAMAGE
240  
241 =head1 SEE ALSO
242  
243 Sample to use Nes; L<http://nes.sourceforge.net/>,
244 L<Nes>, L<CGI::Application>
245  
246  
247 =cut
248  
249  
250  
251 1 1;
252  
253  
↑ Summary