line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Spike::Site::Handler; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
21
|
|
4
|
1
|
|
|
1
|
|
2
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
19
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
2
|
use base qw(Spike::Object); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
282
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
4
|
use feature 'state'; |
|
1
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
66
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
378
|
use FindBin; |
|
1
|
|
|
|
|
698
|
|
|
1
|
|
|
|
|
34
|
|
11
|
1
|
|
|
1
|
|
4
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
37
|
|
12
|
1
|
|
|
1
|
|
364
|
use HTTP::Status qw(:constants); |
|
1
|
|
|
|
|
3214
|
|
|
1
|
|
|
|
|
296
|
|
13
|
1
|
|
|
1
|
|
5
|
use Scalar::Util qw(blessed); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
57
|
|
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
1
|
|
280
|
use Spike::Error; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
18
|
|
16
|
1
|
|
|
1
|
|
266
|
use Spike::Log; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
22
|
|
17
|
1
|
|
|
1
|
|
295
|
use Spike::Site::Request; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
18
|
1
|
|
|
1
|
|
306
|
use Spike::Config; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
403
|
|
19
|
|
|
|
|
|
|
|
20
|
0
|
|
0
|
0
|
0
|
|
sub debug { state $debug //= $ENV{PLACK_ENV} =~ /devel/ } |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub run { |
23
|
0
|
|
|
0
|
0
|
|
my $proto = shift; |
24
|
0
|
|
0
|
|
|
|
my $class = ref $proto || $proto; |
25
|
|
|
|
|
|
|
|
26
|
0
|
|
0
|
|
|
|
state $self ||= $class->new(@_); |
27
|
|
|
|
|
|
|
|
28
|
0
|
|
|
0
|
|
|
return sub { $self->request(@_) }; |
|
0
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub _error_page { |
32
|
0
|
|
|
0
|
|
|
my ($self, $status) = @_; |
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
return ''. |
35
|
|
|
|
|
|
|
HTTP::Status::status_message($status). |
36
|
|
|
|
|
|
|
''. |
37
|
|
|
|
|
|
|
$status.' '.HTTP::Status::status_message($status). |
38
|
|
|
|
|
|
|
' Spike-'.$Spike::VERSION. |
39
|
|
|
|
|
|
|
''; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub request { |
43
|
0
|
|
|
0
|
0
|
|
my ($self, $env) = @_; |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
$Spike::Log::bind_values = [ $$, $env->{REMOTE_ADDR} ]; |
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
my $req = Spike::Site::Request->new($env); |
48
|
0
|
|
|
|
|
|
my $res = $req->new_response(HTTP_OK); |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
eval { |
51
|
0
|
|
|
|
|
|
$self->handler($req, $res); |
52
|
|
|
|
|
|
|
}; |
53
|
0
|
0
|
|
|
|
|
if (my $error = $@) { |
54
|
0
|
0
|
|
|
|
|
if (blessed $error) { |
55
|
0
|
0
|
|
|
|
|
if ($error->isa('Spike::Error::HTTP_OK')) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# do nothing |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
elsif ($error->isa('Spike::Error::HTTP')) { |
59
|
0
|
|
|
|
|
|
carp "HTTP error: status=".$error->value.", text=\"".$error->text."\""; |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
$res = $req->new_response($error->value, $error->headers, |
62
|
|
|
|
|
|
|
$self->_error_page($error->value)); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
elsif ($error->isa('Spike::Error')) { |
65
|
0
|
|
|
|
|
|
carp "Error: class=".ref($error).", text=\"".$error->text."\""; |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
$res = $req->new_response(HTTP_INTERNAL_SERVER_ERROR, undef, |
68
|
|
|
|
|
|
|
$self->_error_page(HTTP_INTERNAL_SERVER_ERROR)); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
else { |
71
|
0
|
0
|
|
|
|
|
carp "Error: class=".ref($error).", text=\"".($error->can('text') ? $error->text : "$error")."\""; |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
$res = $req->new_response(HTTP_INTERNAL_SERVER_ERROR, undef, |
74
|
|
|
|
|
|
|
$self->_error_page(HTTP_INTERNAL_SERVER_ERROR)); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
else { |
78
|
0
|
|
|
|
|
|
carp $error; |
79
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
$res = $req->new_response(HTTP_INTERNAL_SERVER_ERROR, undef, |
81
|
|
|
|
|
|
|
$self->_error_page(HTTP_INTERNAL_SERVER_ERROR)); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
$self->clean; |
86
|
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
$Spike::Log::bind_values = undef; |
88
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
return $res->finalize; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
0
|
0
|
|
sub handler {} |
93
|
|
|
|
0
|
0
|
|
sub clean {} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
1; |