line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CGI::Builder ; |
2
|
|
|
|
|
|
|
$VERSION = 1.36 ; |
3
|
3
|
|
|
3
|
|
22603
|
use strict ; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
79
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
# This file uses the "Perlish" coding style |
6
|
|
|
|
|
|
|
# please read http://perl.4pro.net/perlish_coding_style.html |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
; use 5.006_001 |
9
|
3
|
|
|
3
|
|
52
|
; use Carp |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
90
|
|
10
|
3
|
|
|
3
|
|
16
|
; $Carp::Internal{+__PACKAGE__}++ |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
236
|
|
11
|
|
|
|
|
|
|
; $Carp::Internal{__PACKAGE__.'::_'}++ |
12
|
|
|
|
|
|
|
; use IO::Util |
13
|
3
|
|
|
3
|
|
6989
|
; use Class::Util |
|
3
|
|
|
|
|
6678
|
|
|
3
|
|
|
|
|
21
|
|
14
|
3
|
|
|
3
|
|
2048
|
; use warnings::register |
|
3
|
|
|
|
|
1929
|
|
|
3
|
|
|
|
|
18
|
|
15
|
|
|
|
|
|
|
|
16
|
3
|
|
|
3
|
|
224
|
; my @phase |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
482
|
|
17
|
|
|
|
|
|
|
; BEGIN |
18
|
2
|
|
|
2
|
|
9
|
{ @phase = qw | CB_INIT |
19
|
|
|
|
|
|
|
GET_PAGE |
20
|
|
|
|
|
|
|
PRE_PROCESS |
21
|
|
|
|
|
|
|
SWITCH_HANDLER |
22
|
|
|
|
|
|
|
PRE_PAGE |
23
|
|
|
|
|
|
|
PAGE_HANDLER |
24
|
|
|
|
|
|
|
FIXUP |
25
|
|
|
|
|
|
|
RESPONSE |
26
|
|
|
|
|
|
|
REDIR |
27
|
|
|
|
|
|
|
CLEANUP |
28
|
|
|
|
|
|
|
| |
29
|
3
|
|
|
|
|
176
|
; no strict 'refs' |
30
|
3
|
|
|
3
|
|
17
|
; foreach my $i (0..$#phase) |
|
3
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
8
|
|
31
|
20
|
|
|
|
|
384
|
{ *{$phase[$i]} = sub(){$i} |
|
0
|
|
|
|
|
0
|
|
32
|
20
|
|
|
|
|
108
|
} |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
; sub phase |
36
|
0
|
|
0
|
0
|
1
|
0
|
{ $phase[$_[1]||$_[0]->PHASE] |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
; sub capture |
40
|
11
|
|
|
11
|
1
|
1259
|
{ my ($s, $h, @args) = @_ |
41
|
11
|
|
|
11
|
|
314
|
; IO::Util::capture{ $s->$h(@args) } |
42
|
11
|
|
|
|
|
60
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
; sub import |
45
|
11
|
|
|
11
|
|
20891
|
{ my ($cbb, $CB, @ext) = (scalar caller, @_) |
46
|
11
|
|
|
|
|
38
|
; Class::Util::load for @ext |
47
|
2
|
|
|
|
|
660
|
; no strict 'refs' |
48
|
2
|
|
|
2
|
|
10
|
; foreach my $c (reverse @_) |
|
2
|
|
|
|
|
2
|
|
|
11
|
|
|
|
|
1577
|
|
49
|
15
|
50
|
|
|
|
160
|
{ push @{$cbb.'::ISA'}, $c unless $cbb->isa($c) |
|
15
|
|
|
|
|
172
|
|
50
|
|
|
|
|
|
|
} |
51
|
11
|
0
|
33
|
|
|
121
|
; $cbb->isa('Apache::CGI::Builder') && $Apache::CGI::Builder::usage |
52
|
|
|
|
|
|
|
&& carp $Apache::CGI::Builder::usage |
53
|
|
|
|
|
|
|
; my $sub = sub |
54
|
125
|
|
|
|
|
160
|
{ +{ map |
55
|
25
|
|
|
25
|
|
1409
|
{ my $h = $_ |
56
|
275
|
|
|
|
|
1251
|
; my @op = grep |
57
|
125
|
100
|
|
|
|
385
|
{ defined &{$_.'::OH_'.$h} |
|
275
|
|
|
|
|
268
|
|
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
$h =~ /up$/ # ;-) |
60
|
|
|
|
|
|
|
? reverse ($CB, @ext, $cbb) |
61
|
|
|
|
|
|
|
: ($CB, @ext, $cbb) |
62
|
125
|
100
|
|
|
|
388
|
; @op ? ($h => \@op) : () |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
qw| init pre_process pre_page fixup cleanup | |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
} |
67
|
11
|
|
|
|
|
62
|
; eval qq |
68
|
2
|
|
|
2
|
|
13
|
! package $cbb |
|
2
|
|
|
2
|
|
3
|
|
|
2
|
|
|
0
|
|
16
|
|
|
2
|
|
|
|
|
15
|
|
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
19
|
|
|
11
|
|
|
|
|
913
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
69
|
|
|
|
|
|
|
; use Class::groups |
70
|
|
|
|
|
|
|
{ name => 'overrun_handler_map' |
71
|
|
|
|
|
|
|
, default => \$sub |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
; *import = sub{} unless defined &import |
74
|
|
|
|
|
|
|
! |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
; my $exec = \&CGI::Builder::_::exec |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
; sub CGI::Builder::_::exec |
80
|
65
|
|
|
65
|
|
5924
|
{ my $s = shift |
81
|
65
|
|
|
|
|
88
|
; my $h = shift |
82
|
65
|
|
|
32
|
|
385
|
; Class::Util::gather { $s->$_(@_) } '&OH_'.$h |
|
32
|
|
|
|
|
1328
|
|
83
|
|
|
|
|
|
|
, $s->overrun_handler_map($h) |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
; use Class::constr |
87
|
2
|
|
|
|
|
21
|
( { init => \&CGI::Builder::_::init |
88
|
|
|
|
|
|
|
, no_strict => 1 |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
) |
91
|
|
|
|
|
|
|
|
92
|
2
|
|
|
2
|
|
1776
|
; sub CGI::Builder::_::init |
|
2
|
|
|
|
|
1412
|
|
93
|
16
|
|
|
16
|
|
11168
|
{ my $s = shift |
94
|
0
|
|
|
0
|
|
0
|
; local $SIG{__DIE__} = sub{$s->die_handler(@_)} |
95
|
16
|
|
|
|
|
110
|
; $s->$exec('init', @_) |
|
16
|
|
|
|
|
49
|
|
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
2
|
|
|
|
|
14
|
; use Class::groups qw | overrun_handler_map |
99
|
|
|
|
|
|
|
switch_handler_map |
100
|
|
|
|
|
|
|
page_handler_map |
101
|
|
|
|
|
|
|
| |
102
|
2
|
|
|
2
|
|
1976
|
; use Object::groups qw | param |
|
2
|
|
|
|
|
7064
|
|
|
2
|
|
|
|
|
19
|
|
103
|
|
|
|
|
|
|
header |
104
|
|
|
|
|
|
|
page_error |
105
|
|
|
|
|
|
|
| |
106
|
2
|
|
|
2
|
|
1977
|
; use Class::props |
|
2
|
|
|
|
|
319
|
|
107
|
2
|
|
|
|
|
22
|
( { name => 'no_page_content_status' |
108
|
|
|
|
|
|
|
, default => '204 No Content' |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
) |
111
|
|
|
|
|
|
|
|
112
|
2
|
|
|
2
|
|
230
|
; use Object::props |
|
2
|
|
|
|
|
3
|
|
113
|
|
|
|
|
|
|
( { name => 'PHASE' |
114
|
|
|
|
|
|
|
, default => CB_INIT |
115
|
|
|
|
|
|
|
, allowed => qr/^CGI::Builder/ # only settable from CBF |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
, { name => 'cgi_page_param' |
118
|
|
|
|
|
|
|
, default => 'p' |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
, { name => 'cgi' |
121
|
6
|
|
|
|
|
238
|
, default => sub{ shift()->cgi_new } |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
, { name => 'page_name' |
124
|
|
|
|
|
|
|
, default => 'index' |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
, { name => 'requested_page' |
127
|
|
|
|
|
|
|
, allowed => qw/^CGI::Builder::process$/ |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
, { name => 'page_path' |
130
|
|
|
|
|
|
|
, default => './tm' |
131
|
|
|
|
|
|
|
, no_strict => 1 # doesn't croak if ./tm is not a directory |
132
|
0
|
0
|
|
|
|
0
|
, validation => sub { -d or croak "'$_' is not a directory, died" } |
133
|
|
|
|
|
|
|
} |
134
|
2
|
|
|
|
|
50
|
, { name => [ qw| page_content page_suffix | ] |
135
|
|
|
|
|
|
|
, default => '' |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
, 'dont_send_header' |
138
|
|
|
|
|
|
|
) |
139
|
|
|
|
|
|
|
|
140
|
2
|
|
|
2
|
|
6254
|
; our $AUTOLOAD |
|
2
|
|
|
|
|
312
|
|
141
|
|
|
|
|
|
|
; sub AUTOLOAD : lvalue # param AUTOLOADING |
142
|
8
|
|
|
8
|
|
1881
|
{ (my $n = $AUTOLOAD) =~ s/.*:// |
143
|
8
|
50
|
33
|
|
|
724
|
; carp qq(Use of unprefixed autoloaded parameter "$n". ) |
144
|
|
|
|
|
|
|
. qq(Autoloaded parameters should start with 'my_' or '_') |
145
|
|
|
|
|
|
|
if warnings::enabled && $n !~ /^(?:my)?_/ |
146
|
8
|
100
|
|
|
|
67
|
; @_ == 2 |
147
|
|
|
|
|
|
|
? ( $_[0]{param}{$n} = $_[1] ) |
148
|
|
|
|
|
|
|
: $_[0]{param}{$n} |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
0
|
|
|
0
|
|
0
|
; sub DESTROY {} |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
; sub cgi_new |
154
|
|
|
|
|
|
|
{ require CGI |
155
|
6
|
|
|
6
|
1
|
49
|
; CGI->new |
|
6
|
|
|
|
|
30
|
|
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
; sub process |
159
|
11
|
|
|
11
|
1
|
21
|
{ my ($s, $p) = @_ |
160
|
4
|
|
|
4
|
|
212
|
; local $SIG{__DIE__} = sub{$s->die_handler(@_)} |
161
|
11
|
|
|
|
|
65
|
; $s->PHASE(GET_PAGE) |
|
11
|
|
|
|
|
67
|
|
162
|
11
|
100
|
66
|
|
|
955
|
; if ( defined $p && length $p ) |
163
|
3
|
|
|
|
|
16
|
{ $s->requested_page($p) |
164
|
3
|
|
|
|
|
269
|
; $s->page_name($p) |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
else |
167
|
8
|
|
|
|
|
55
|
{ $s->requested_page( $s->get_page_name() ) |
168
|
|
|
|
|
|
|
} |
169
|
11
|
50
|
|
|
|
1077
|
; if ($s->PHASE < PRE_PROCESS) |
170
|
11
|
|
|
|
|
295
|
{ $s->PHASE(PRE_PROCESS) |
171
|
11
|
|
|
|
|
832
|
; $s->$exec('pre_process') |
172
|
|
|
|
|
|
|
} |
173
|
11
|
100
|
|
|
|
688
|
; if ($s->PHASE < SWITCH_HANDLER) |
174
|
9
|
|
|
|
|
254
|
{ $s->switch_to( $s->page_name ) |
175
|
|
|
|
|
|
|
} |
176
|
11
|
100
|
|
|
|
334
|
; if ($s->PHASE < FIXUP) |
177
|
10
|
|
|
|
|
256
|
{ $s->PHASE(FIXUP) |
178
|
10
|
|
|
|
|
746
|
; $s->$exec('fixup') |
179
|
|
|
|
|
|
|
} |
180
|
11
|
100
|
|
|
|
640
|
; if ($s->PHASE < RESPONSE) |
181
|
10
|
|
|
|
|
259
|
{ $s->PHASE(RESPONSE) |
182
|
10
|
|
|
|
|
763
|
; my $has_content = $s->page_content_check |
183
|
10
|
100
|
66
|
|
|
295
|
; $s->header( -status => $s->no_page_content_status ) |
184
|
|
|
|
|
|
|
unless $has_content || defined $s->header->{-status} |
185
|
10
|
50
|
|
|
|
346
|
; $s->send_header() unless $s->dont_send_header |
186
|
10
|
100
|
|
|
|
19517
|
; $s->send_content() if $has_content |
187
|
|
|
|
|
|
|
} |
188
|
11
|
|
|
|
|
113
|
; $s->PHASE(CLEANUP) |
189
|
11
|
|
|
|
|
902
|
; $s->$exec('cleanup') # done however |
190
|
|
|
|
|
|
|
} |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
; sub switch_to |
193
|
15
|
|
|
15
|
1
|
273
|
{ my ($s, $p) = splice @_, 0, 2 |
194
|
15
|
50
|
|
|
|
135
|
; $s->PHASE < PRE_PROCESS && croak 'Too early to call switch_to(), died' |
195
|
15
|
50
|
|
|
|
398
|
; $s->PHASE > FIXUP && croak 'Too late to call switch_to(), died' |
196
|
15
|
50
|
33
|
|
|
447
|
; defined $p && length $p || croak 'No page_name name passed, died' |
197
|
15
|
|
|
|
|
211
|
; $s->page_name($p) |
198
|
15
|
|
|
|
|
532
|
; $s->PHASE(SWITCH_HANDLER) |
199
|
15
|
|
|
|
|
1182
|
; my $shm = $s->switch_handler_map |
200
|
15
|
|
66
|
|
|
365
|
; my $SH = $$shm{$p} || $s->can("SH_$p") |
201
|
15
|
100
|
|
|
|
52
|
; $s->$SH(@_) if $SH |
202
|
15
|
100
|
|
|
|
1952
|
; if ($s->PHASE < PRE_PAGE) |
203
|
13
|
|
|
|
|
340
|
{ $s->PHASE(PRE_PAGE) |
204
|
13
|
|
|
|
|
1001
|
; $s->$exec('pre_page') |
205
|
|
|
|
|
|
|
} |
206
|
15
|
100
|
|
|
|
791
|
; if ($s->PHASE < PAGE_HANDLER) |
207
|
13
|
|
|
|
|
354
|
{ $s->PHASE(PAGE_HANDLER) |
208
|
13
|
|
|
|
|
1039
|
; my $phm = $s->page_handler_map |
209
|
13
|
|
66
|
|
|
301
|
; my $PH = $$phm{$p} || $s->can("PH_$p") |
210
|
|
|
|
|
|
|
|| ! $s->page_content_check |
211
|
|
|
|
|
|
|
&& ($$phm{AUTOLOAD} || $s->can('PH_AUTOLOAD')) |
212
|
13
|
100
|
|
|
|
176
|
; $s->$PH(@_) if $PH |
213
|
|
|
|
|
|
|
} |
214
|
|
|
|
|
|
|
} |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
; sub get_page_name |
217
|
8
|
|
|
8
|
1
|
13
|
{ my $s = shift |
218
|
8
|
|
|
|
|
33
|
; my $p = $s->cgi->param($s->cgi_page_param) |
219
|
8
|
100
|
66
|
|
|
2874
|
; $s->page_name($p) if defined($p) && length($p) |
220
|
|
|
|
|
|
|
} |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
; sub page_content_check |
223
|
12
|
|
|
12
|
1
|
37
|
{ length $_[0]->page_content |
224
|
|
|
|
|
|
|
} |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
; sub send_header |
227
|
10
|
|
|
10
|
1
|
181
|
{ print $_[0]->cgi->header( %{$_[0]->header} ) |
|
10
|
|
|
|
|
187
|
|
228
|
|
|
|
|
|
|
} |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
; sub send_content |
231
|
7
|
|
|
7
|
1
|
27
|
{ my $pc = $_[0]->page_content |
232
|
7
|
50
|
|
|
|
223
|
; if ( ref $pc eq 'CODE' ) |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
233
|
0
|
|
|
|
|
0
|
{ $_[0]->$pc |
234
|
|
|
|
|
|
|
} |
235
|
|
|
|
|
|
|
elsif ( ref $pc eq 'SCALAR' ) |
236
|
0
|
|
|
|
|
0
|
{ print $$pc |
237
|
|
|
|
|
|
|
} |
238
|
|
|
|
|
|
|
elsif ( not ref $pc ) |
239
|
7
|
|
|
|
|
19
|
{ print $pc |
240
|
|
|
|
|
|
|
} |
241
|
|
|
|
|
|
|
} |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
; sub redirect |
244
|
1
|
|
|
1
|
1
|
11
|
{ my ($s, $url) = @_ |
245
|
1
|
50
|
|
|
|
15
|
; $s->PHASE < GET_PAGE && croak 'Too early to call redirect(), died' |
246
|
1
|
50
|
|
|
|
34
|
; $s->PHASE > RESPONSE && croak 'Too late to call redirect(), died' |
247
|
1
|
50
|
33
|
|
|
37
|
; defined $url && length $url || croak 'No URL passed, died' |
248
|
1
|
|
|
|
|
5
|
; $s->PHASE(REDIR) |
249
|
1
|
|
|
|
|
90
|
; $s->header(-url => $url) |
250
|
1
|
|
|
|
|
43
|
; print $s->cgi->redirect( %{$s->header} ) |
|
1
|
|
|
|
|
21
|
|
251
|
|
|
|
|
|
|
} |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
; sub die_handler |
254
|
4
|
|
|
4
|
1
|
9
|
{ my ( $s, $msg ) = @_ |
255
|
4
|
|
|
|
|
32
|
; for ( my $i = 1 |
256
|
|
|
|
|
|
|
; my $sub = (caller($i))[3] |
257
|
|
|
|
|
|
|
; $i++ |
258
|
|
|
|
|
|
|
) |
259
|
8
|
100
|
66
|
|
|
96
|
{ die $msg if $sub eq '(eval)' && (caller($i+1))[3] |
260
|
|
|
|
|
|
|
} |
261
|
0
|
|
|
|
|
|
; die sprintf 'Fatal error in phase %s for page "%s": %s' |
262
|
|
|
|
|
|
|
, $s->phase |
263
|
|
|
|
|
|
|
, $s->page_name |
264
|
|
|
|
|
|
|
, $msg |
265
|
|
|
|
|
|
|
} |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
; 1 |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
__END__ |