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