| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
################################################################################ |
|
2
|
|
|
|
|
|
|
# |
|
3
|
|
|
|
|
|
|
# Apache::Voodoo::Handler - Main interface between mod_perl and Voodoo |
|
4
|
|
|
|
|
|
|
# |
|
5
|
|
|
|
|
|
|
# This is the main generic presentation module that interfaces with apache, |
|
6
|
|
|
|
|
|
|
# handles session control, database connections, and interfaces with the |
|
7
|
|
|
|
|
|
|
# application's page handling modules. |
|
8
|
|
|
|
|
|
|
# |
|
9
|
|
|
|
|
|
|
################################################################################ |
|
10
|
|
|
|
|
|
|
package Apache::Voodoo::Handler; |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
$VERSION = "3.0200"; |
|
13
|
|
|
|
|
|
|
|
|
14
|
1
|
|
|
1
|
|
2672
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
36
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
1
|
|
|
1
|
|
6
|
use Time::HiRes; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
8
|
|
|
17
|
|
|
|
|
|
|
|
|
18
|
1
|
|
|
1
|
|
680
|
use Apache::Voodoo::MP; |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
28
|
|
|
19
|
1
|
|
|
1
|
|
8
|
use Apache::Voodoo::Constants; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
21
|
|
|
20
|
1
|
|
|
1
|
|
5
|
use Apache::Voodoo::Engine; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
1109
|
|
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub new { |
|
23
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
|
24
|
0
|
|
|
|
|
|
my $self = {}; |
|
25
|
0
|
|
|
|
|
|
bless $self, $class; |
|
26
|
|
|
|
|
|
|
|
|
27
|
0
|
|
|
|
|
|
$self->{'mp'} = Apache::Voodoo::MP->new(); |
|
28
|
0
|
|
|
|
|
|
$self->{'constants'} = Apache::Voodoo::Constants->new(); |
|
29
|
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
$self->{'engine'} = Apache::Voodoo::Engine->new('mp' => $self->{'mp'}); |
|
31
|
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
return $self; |
|
33
|
|
|
|
|
|
|
} |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub handler { |
|
36
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
37
|
0
|
|
|
|
|
|
my $r = shift; |
|
38
|
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
$self->{'mp'}->set_request($r); |
|
40
|
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
$self->{'engine'}->set_request($r); |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
#################### |
|
44
|
|
|
|
|
|
|
# URI translation jazz to get down to a proper filename |
|
45
|
|
|
|
|
|
|
#################### |
|
46
|
0
|
|
|
|
|
|
my $uri = $self->{'mp'}->uri(); |
|
47
|
0
|
0
|
|
|
|
|
if ($uri =~ /\/$/o) { |
|
48
|
0
|
|
|
|
|
|
return $self->{'mp'}->redirect($uri."index"); |
|
49
|
|
|
|
|
|
|
} |
|
50
|
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
my $filename = $self->{'mp'}->filename(); |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# remove the optional trailing .tmpl |
|
54
|
0
|
|
|
|
|
|
$filename =~ s/\.tmpl$//o; |
|
55
|
0
|
|
|
|
|
|
$uri =~ s/\.tmpl$//o; |
|
56
|
|
|
|
|
|
|
|
|
57
|
0
|
0
|
|
|
|
|
unless (-e "$filename.tmpl") { return $self->{mp}->declined; } |
|
|
0
|
|
|
|
|
|
|
|
58
|
0
|
0
|
|
|
|
|
unless (-r "$filename.tmpl") { return $self->{mp}->forbidden; } |
|
|
0
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
######################################## |
|
61
|
|
|
|
|
|
|
# We now know we have a valid request that we need to handle, |
|
62
|
|
|
|
|
|
|
# Get the engine ready to serve it. |
|
63
|
|
|
|
|
|
|
######################################## |
|
64
|
0
|
|
|
|
|
|
eval { |
|
65
|
0
|
|
|
|
|
|
$self->{'engine'}->init_app(); |
|
66
|
0
|
|
|
|
|
|
$self->{'engine'}->begin_run(); |
|
67
|
|
|
|
|
|
|
}; |
|
68
|
0
|
0
|
|
|
|
|
if (my $e = Apache::Voodoo::Exception::Application::SessionTimeout->caught()) { |
|
|
|
0
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
return $self->{'mp'}->redirect($e->target()); |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
elsif ($e = Exception::Class->caught()) { |
|
72
|
0
|
|
|
|
|
|
warn "$e"; |
|
73
|
0
|
|
|
|
|
|
return $self->{'mp'}->server_error; |
|
74
|
|
|
|
|
|
|
} |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
#################### |
|
77
|
|
|
|
|
|
|
# Get paramaters |
|
78
|
|
|
|
|
|
|
#################### |
|
79
|
0
|
|
|
|
|
|
my $params; |
|
80
|
0
|
|
|
|
|
|
eval { |
|
81
|
0
|
|
|
|
|
|
$params = $self->{'engine'}->parse_params(); |
|
82
|
|
|
|
|
|
|
}; |
|
83
|
0
|
0
|
|
|
|
|
if ($@) { |
|
84
|
0
|
|
|
|
|
|
return $self->display_host_error($@); |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
#################### |
|
88
|
|
|
|
|
|
|
# History capture |
|
89
|
|
|
|
|
|
|
#################### |
|
90
|
0
|
0
|
0
|
|
|
|
if ($self->{mp}->is_get && |
|
|
|
|
0
|
|
|
|
|
|
91
|
|
|
|
|
|
|
!$params->{ajax_mode} && |
|
92
|
|
|
|
|
|
|
!$params->{return} |
|
93
|
|
|
|
|
|
|
) { |
|
94
|
0
|
|
|
|
|
|
$self->{'engine'}->history_capture($uri,$params); |
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
#################### |
|
98
|
|
|
|
|
|
|
# Execute the controllers |
|
99
|
|
|
|
|
|
|
#################### |
|
100
|
0
|
|
|
|
|
|
my $content; |
|
101
|
0
|
|
|
|
|
|
eval { |
|
102
|
0
|
|
|
|
|
|
$content = $self->{'engine'}->execute_controllers($uri,$params); |
|
103
|
|
|
|
|
|
|
}; |
|
104
|
0
|
0
|
|
|
|
|
if (my $e = Exception::Class->caught()) { |
|
105
|
0
|
0
|
|
|
|
|
if ($e->isa("Apache::Voodoo::Exception::Application::Redirect")) { |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
106
|
0
|
|
|
|
|
|
$self->{'engine'}->status($self->{mp}->redirect); |
|
107
|
0
|
|
|
|
|
|
return $self->{'mp'}->redirect($e->target()); |
|
108
|
|
|
|
|
|
|
} |
|
109
|
|
|
|
|
|
|
elsif ($e->isa("Apache::Voodoo::Exception::Application::RawData")) { |
|
110
|
0
|
0
|
|
|
|
|
$self->{mp}->header_out(each %{$e->headers}) if (ref($e->headers) eq "HASH"); |
|
|
0
|
|
|
|
|
|
|
|
111
|
0
|
|
|
|
|
|
$self->{mp}->content_type($e->content_type); |
|
112
|
0
|
|
|
|
|
|
$self->{mp}->print($e->data); |
|
113
|
|
|
|
|
|
|
|
|
114
|
0
|
|
|
|
|
|
$self->{'engine'}->status($self->{mp}->ok); |
|
115
|
0
|
|
|
|
|
|
return $self->{mp}->ok; |
|
116
|
|
|
|
|
|
|
} |
|
117
|
|
|
|
|
|
|
elsif ($e->isa("Apache::Voodoo::Exception::Application::Unauthorized")) { |
|
118
|
0
|
|
|
|
|
|
$self->{'engine'}->status($self->{mp}->unauthorized); |
|
119
|
0
|
|
|
|
|
|
return $self->{mp}->unauthorized; |
|
120
|
|
|
|
|
|
|
} |
|
121
|
|
|
|
|
|
|
elsif (! $e->isa("Apache::Voodoo::Exception::Application")) { |
|
122
|
|
|
|
|
|
|
# Apache::Voodoo::Exception::RunTime |
|
123
|
|
|
|
|
|
|
# Apache::Voodoo::Exception::RunTime::BadCommand |
|
124
|
|
|
|
|
|
|
# Apache::Voodoo::Exception::RunTime::BadReturn |
|
125
|
|
|
|
|
|
|
# Exception::Class::DBI |
|
126
|
0
|
0
|
|
|
|
|
unless ($self->{'engine'}->is_devel_mode()) { |
|
127
|
0
|
|
|
|
|
|
warn "$@"; |
|
128
|
0
|
|
|
|
|
|
$self->{'engine'}->status($self->{mp}->server_error); |
|
129
|
0
|
|
|
|
|
|
return $self->{mp}->server_error; |
|
130
|
|
|
|
|
|
|
} |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
} |
|
133
|
0
|
|
|
|
|
|
$content = $e; |
|
134
|
|
|
|
|
|
|
} |
|
135
|
|
|
|
|
|
|
|
|
136
|
0
|
|
|
|
|
|
my $view = $self->{'engine'}->execute_view($content); |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
# output content |
|
139
|
0
|
|
|
|
|
|
$self->{mp}->content_type($view->content_type()); |
|
140
|
0
|
|
|
|
|
|
$self->{mp}->print($view->output()); |
|
141
|
0
|
|
|
|
|
|
$self->{mp}->flush(); |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
#################### |
|
144
|
|
|
|
|
|
|
# Clean up |
|
145
|
|
|
|
|
|
|
#################### |
|
146
|
0
|
|
|
|
|
|
$self->{'engine'}->status($self->{mp}->ok); |
|
147
|
0
|
|
|
|
|
|
$view->finish(); |
|
148
|
|
|
|
|
|
|
|
|
149
|
0
|
|
|
|
|
|
return $self->{mp}->ok; |
|
150
|
|
|
|
|
|
|
} |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
sub display_host_error { |
|
153
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
154
|
0
|
|
|
|
|
|
my $error = shift; |
|
155
|
|
|
|
|
|
|
|
|
156
|
0
|
|
|
|
|
|
$self->{'mp'}->content_type("text/html"); |
|
157
|
0
|
|
|
|
|
|
$self->{'mp'}->print("The following error was encountered while processing this request:"); |
|
158
|
0
|
|
|
|
|
|
$self->{'mp'}->print("$error "); |
|
159
|
0
|
|
|
|
|
|
$self->{'mp'}->flush(); |
|
160
|
|
|
|
|
|
|
|
|
161
|
0
|
|
|
|
|
|
return $self->{mp}->ok; |
|
162
|
|
|
|
|
|
|
} |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
1; |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
################################################################################ |
|
167
|
|
|
|
|
|
|
# Copyright (c) 2005-2010 Steven Edwards (maverick@smurfbane.org). |
|
168
|
|
|
|
|
|
|
# All rights reserved. |
|
169
|
|
|
|
|
|
|
# |
|
170
|
|
|
|
|
|
|
# You may use and distribute Apache::Voodoo under the terms described in the |
|
171
|
|
|
|
|
|
|
# LICENSE file include in this package. The summary is it's a legalese version |
|
172
|
|
|
|
|
|
|
# of the Artistic License :) |
|
173
|
|
|
|
|
|
|
# |
|
174
|
|
|
|
|
|
|
################################################################################ |