line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# Nes by Skriptke |
4
|
|
|
|
|
|
|
# Copyright 2009 - 2010 Enrique F. Castañón Barbero |
5
|
|
|
|
|
|
|
# Licensed under the GNU GPL. |
6
|
|
|
|
|
|
|
# |
7
|
|
|
|
|
|
|
# CPAN: |
8
|
|
|
|
|
|
|
# http://search.cpan.org/dist/Nes/ |
9
|
|
|
|
|
|
|
# |
10
|
|
|
|
|
|
|
# Sample: |
11
|
|
|
|
|
|
|
# http://nes.sourceforge.net/ |
12
|
|
|
|
|
|
|
# |
13
|
|
|
|
|
|
|
# Repository: |
14
|
|
|
|
|
|
|
# http://github.com/Skriptke/nes |
15
|
|
|
|
|
|
|
# |
16
|
|
|
|
|
|
|
# Version 1.04 |
17
|
|
|
|
|
|
|
# |
18
|
|
|
|
|
|
|
# Singleton.pm |
19
|
|
|
|
|
|
|
# |
20
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
package Nes::Singleton; |
23
|
|
|
|
|
|
|
|
24
|
3
|
|
|
3
|
|
15
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
97
|
|
25
|
3
|
|
|
3
|
|
14
|
use warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
2350
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my $instance; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub new { |
30
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
31
|
0
|
|
0
|
|
|
|
my $self = $instance || bless {}, $class; |
32
|
0
|
|
|
|
|
|
my $params = shift; |
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
$self->{'params'} = (); |
35
|
0
|
0
|
|
|
|
|
if ( ref( $params ) eq 'HASH' ) { |
36
|
0
|
|
|
|
|
|
$self->{'params'} = $params; |
37
|
|
|
|
|
|
|
} else { |
38
|
|
|
|
|
|
|
( |
39
|
0
|
|
|
|
|
|
$self->{'params'}{'template'}, |
40
|
|
|
|
|
|
|
$self->{'params'}{'nes_top_dir'}, |
41
|
|
|
|
|
|
|
$self->{'params'}{'nes_dir'}, |
42
|
|
|
|
|
|
|
$self->{'params'}{'no_init'}, |
43
|
|
|
|
|
|
|
$self->{'params'}{'no_exit'} |
44
|
|
|
|
|
|
|
) = $params; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
0
|
0
|
|
|
|
|
if ( $instance ) { |
48
|
0
|
|
|
|
|
|
$self->{'container'} = nes_container->get_obj(); |
49
|
0
|
|
|
|
|
|
$self->{'this_template_name'} = $self->{'container'}->{'file_name'}; |
50
|
0
|
|
|
|
|
|
$self->{'top_template_name'} = $self->{'top_container'}->{'file'}; |
51
|
0
|
|
|
|
|
|
return $self; |
52
|
|
|
|
|
|
|
} else { |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# Compatibility by older version and call by .cgi or command line |
55
|
0
|
|
|
|
|
|
$self->{'already_init'} = 0; |
56
|
0
|
|
|
|
|
|
$self->{'already_running'} = 0; |
57
|
|
|
|
|
|
|
# --------------------------------------------------------------- |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
$instance = $self; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
0
|
0
|
|
|
|
|
if ( $self->{'params'}{'template'} ) { |
63
|
|
|
|
|
|
|
# the template is in parameter, call by .cgi or command line |
64
|
0
|
|
|
|
|
|
$self->init_by_cgi(); |
65
|
|
|
|
|
|
|
} else { |
66
|
|
|
|
|
|
|
# the template is in $ENV{'PATH_TRANSLATED'}, call by dispatch.cgi |
67
|
0
|
|
|
|
|
|
$self->init(); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
return $self; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub run { |
74
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
# Compatibility by older version and call by .cgi or command line |
77
|
0
|
0
|
|
|
|
|
return if $self->{'already_running'}; |
78
|
0
|
|
|
|
|
|
$self->{'already_running'} = 1; |
79
|
|
|
|
|
|
|
# ---------------------------------------------------------------- |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
$self->{'container'}->go(); |
82
|
0
|
|
|
|
|
|
$self->{'top_container'}->{'container'}->out(); |
83
|
0
|
|
|
|
|
|
$self->{'container'}->forget(); |
84
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
return; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub out { |
89
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
90
|
0
|
|
|
|
|
|
my %tags; |
91
|
0
|
|
|
|
|
|
(%tags) = @_; |
92
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
$self->{'container'}->set_tags(%tags); |
94
|
0
|
|
|
|
|
|
$self->{'container'}->interpret(); |
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
return; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub add { |
100
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
101
|
0
|
|
|
|
|
|
my %tags; |
102
|
0
|
|
|
|
|
|
(%tags) = @_; |
103
|
|
|
|
|
|
|
|
104
|
0
|
|
|
|
|
|
$self->{'container'}->add_tags(%tags); |
105
|
|
|
|
|
|
|
|
106
|
0
|
|
|
|
|
|
return; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub start { |
110
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
111
|
|
|
|
|
|
|
|
112
|
0
|
0
|
|
|
|
|
utl::cleanup(\$instance) if $ENV{'MOD_PERL'}; |
113
|
|
|
|
|
|
|
|
114
|
0
|
|
|
|
|
|
return $class->new(); |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub instance { |
118
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
119
|
|
|
|
|
|
|
|
120
|
0
|
|
|
|
|
|
return $instance; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub init_by_cgi { |
124
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
125
|
|
|
|
|
|
|
|
126
|
0
|
0
|
|
|
|
|
return if $self->{'params'}{'no_init'}; |
127
|
0
|
0
|
|
|
|
|
$self->init() if !$self->{'already_init'}; |
128
|
0
|
0
|
|
|
|
|
$self->run() if !$self->{'already_running'}; |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
# mod_perl muestra un error cuando se usa exit |
131
|
0
|
0
|
|
|
|
|
CORE::exit(0) if !$self->{'params'}{'no_exit'}; |
132
|
|
|
|
|
|
|
|
133
|
0
|
|
|
|
|
|
return; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub init { |
137
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
138
|
|
|
|
|
|
|
|
139
|
0
|
|
0
|
|
|
|
$self->{'file'} = $ENV{'PATH_TRANSLATED'} || $self->{'params'}{'template'}; |
140
|
0
|
0
|
|
|
|
|
die "No template defined: $@" if !$self->{'file'}; |
141
|
|
|
|
|
|
|
|
142
|
0
|
|
|
|
|
|
my $dir = $self->{'file'}; |
143
|
0
|
|
|
|
|
|
$dir =~ s/[^\/]*$//; |
144
|
0
|
|
|
|
|
|
chdir $dir; |
145
|
3
|
|
|
3
|
|
20
|
use Cwd; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
749
|
|
146
|
0
|
|
|
|
|
|
$dir = getcwd; |
147
|
|
|
|
|
|
|
|
148
|
0
|
|
|
|
|
|
$self->{'CFG'} = Nes::Setting->new( |
149
|
|
|
|
|
|
|
$self->{'params'}{'nes_top_dir'}, |
150
|
|
|
|
|
|
|
$self->{'params'}{'nes_dir'} |
151
|
|
|
|
|
|
|
); |
152
|
0
|
|
|
|
|
|
$self->{'top_container'} = nes_top_container->new( $self->{'file'}, $dir ); |
153
|
0
|
|
|
|
|
|
$self->{'container'} = nes_container->get_obj(); |
154
|
0
|
|
|
|
|
|
$self->{'cookies'} = nes_cookie->get_obj(); |
155
|
0
|
|
|
|
|
|
$self->{'session'} = nes_session->get_obj(); |
156
|
0
|
|
|
|
|
|
$self->{'query'} = nes_query->get_obj(); |
157
|
0
|
|
|
|
|
|
$self->{'register'} = nes_register->get_obj(); |
158
|
0
|
|
|
|
|
|
$self->{'nes'} = $self->{'top_container'}->{'nes'}; |
159
|
0
|
|
|
|
|
|
$self->{'this_template_name'} = $self->{'container'}->{'file_name'}; |
160
|
0
|
|
|
|
|
|
$self->{'top_template_name'} = $self->{'top_container'}->{'file'}; |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
# todo, comprobar que existe el juego de caracteres antes |
163
|
3
|
|
|
3
|
|
3000
|
use POSIX qw(locale_h); |
|
3
|
|
|
|
|
21949
|
|
|
3
|
|
|
|
|
23
|
|
164
|
0
|
0
|
|
|
|
|
POSIX::setlocale(LC_ALL, "$self->{'CFG'}{'locale'}") if $self->{'CFG'}{'locale'}; |
165
|
|
|
|
|
|
|
|
166
|
0
|
|
|
|
|
|
$self->{'already_init'} = 1; |
167
|
|
|
|
|
|
|
|
168
|
0
|
|
|
|
|
|
return $self->{'container'}; |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
1; |