line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
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
|
|
|
|
|
|
|
our $VERSION = '0.00_1'; |
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
1
|
|
36221
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
105
|
|
16
|
1
|
|
|
1
|
|
8
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
28
|
|
17
|
|
|
|
|
|
|
|
18
|
1
|
|
|
1
|
|
752
|
use Nes; |
|
1
|
|
|
|
|
53442
|
|
|
1
|
|
|
|
|
56
|
|
19
|
1
|
|
|
1
|
|
12
|
use base 'CGI::Application'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
915
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our $MOD_PERL = $ENV{'MOD_PERL'} || 0; |
22
|
|
|
|
|
|
|
our $MOD_PERL1 = $MOD_PERL =~ /mod_perl\/1/ || 0; |
23
|
|
|
|
|
|
|
our $MOD_PERL2 = $MOD_PERL =~ /mod_perl\/2/ || 0; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
&nes_init; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
if ( $MOD_PERL2 ) { |
28
|
|
|
|
|
|
|
require Apache2::RequestUtil; |
29
|
|
|
|
|
|
|
require Apache2::RequestIO; |
30
|
|
|
|
|
|
|
require APR::Pool; |
31
|
|
|
|
|
|
|
Apache2::RequestUtil->request->pool->cleanup_register(\&nes_init); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
if ( $MOD_PERL1 ) { |
35
|
|
|
|
|
|
|
require Apache; |
36
|
|
|
|
|
|
|
Apache->request->register_cleanup(\&nes_init); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub nes_init { |
40
|
|
|
|
|
|
|
|
41
|
1
|
|
|
1
|
0
|
10
|
$ENV{'CGI_APP_RETURN_ONLY'} = 1; |
42
|
1
|
|
|
|
|
5
|
$ENV{'CGI_APP_NES_BY_CGI'} = 0; |
43
|
1
|
|
|
|
|
6
|
$ENV{'CGI_APP_NES_DIR'} = ''; |
44
|
1
|
|
|
|
|
5
|
$ENV{'CGI_APP_NES_DIR_CGI'} = ''; |
45
|
|
|
|
|
|
|
|
46
|
1
|
|
50
|
|
|
8
|
$CGI::Application::Plugin::Nes::top_script = $ENV{'SCRIPT_FILENAME'} || ''; |
47
|
1
|
|
|
|
|
3
|
$CGI::Application::Plugin::Nes::top_dir = $CGI::Application::Plugin::Nes::top_script; |
48
|
1
|
|
|
|
|
3
|
$CGI::Application::Plugin::Nes::top_dir =~ s/\/[^\/]*\.cgi|pl$//; |
49
|
1
|
|
|
|
|
3
|
$CGI::Application::Plugin::Nes::top_template = $CGI::Application::Plugin::Nes::top_script; |
50
|
1
|
|
|
|
|
3
|
$CGI::Application::Plugin::Nes::top_template =~ s/\.cgi|pl$/\.nhtml/; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub cgiapp_init { |
55
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
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
|
|
|
0
|
1
|
|
my $self = shift; |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
my $q; |
72
|
|
|
|
|
|
|
|
73
|
0
|
0
|
|
|
|
|
if ( $ENV{'CGI_APP_NES_BY_CGI'} ) { |
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 templates in L. You can use any Nes |
105
|
|
|
|
|
|
|
object or plugin, PHP, SH, PYTHON, ... in CGI::Application. |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Live sample: L |
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
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
|
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 |
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, |
244
|
|
|
|
|
|
|
L, L |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
=cut |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
1; |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
|