line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Squatting::On::Mojo; |
2
|
1
|
|
|
1
|
|
25529
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
32
|
|
3
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
22
|
|
4
|
1
|
|
|
1
|
|
875
|
use CGI::Cookie; |
|
1
|
|
|
|
|
10205
|
|
|
1
|
|
|
|
|
392
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
7
|
|
|
|
|
|
|
our %p; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
$p{e} = sub { |
10
|
|
|
|
|
|
|
my $tx = shift; |
11
|
|
|
|
|
|
|
my $req = $tx->req; |
12
|
|
|
|
|
|
|
my $url = $req->url; |
13
|
|
|
|
|
|
|
my %env; |
14
|
|
|
|
|
|
|
$env{QUERY_STRING} = $url->query || ''; |
15
|
|
|
|
|
|
|
$env{REQUEST_PATH} = $url->path->to_string; |
16
|
|
|
|
|
|
|
$env{REQUEST_URI} = "$env{REQUEST_PATH}?$env{QUERY_STRING}"; |
17
|
|
|
|
|
|
|
$env{REQUEST_METHOD} = $req->method; |
18
|
|
|
|
|
|
|
my $h = $req->headers->{_headers}; |
19
|
|
|
|
|
|
|
for (keys %$h) { |
20
|
|
|
|
|
|
|
my $header = "HTTP_" . uc($_); |
21
|
|
|
|
|
|
|
$header =~ s/-/_/g; |
22
|
|
|
|
|
|
|
$env{$header} = $h->{$_}[0]; # FIXME: I need to handle multiple occurrences of a header. |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
\%env; |
25
|
|
|
|
|
|
|
}; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
$p{c} = sub { |
28
|
|
|
|
|
|
|
my $tx = shift; |
29
|
|
|
|
|
|
|
my $c = $tx->req->cookies; |
30
|
|
|
|
|
|
|
my %k; |
31
|
|
|
|
|
|
|
for (@$c) { $k{$_->name} = $_->value; } |
32
|
|
|
|
|
|
|
\%k; |
33
|
|
|
|
|
|
|
}; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
$p{init_cc} = sub { |
36
|
|
|
|
|
|
|
my ($c, $tx) = @_; |
37
|
|
|
|
|
|
|
my $cc = $c->clone; |
38
|
|
|
|
|
|
|
$cc->env = $p{e}->($tx); |
39
|
|
|
|
|
|
|
$cc->cookies = $p{c}->($tx); |
40
|
|
|
|
|
|
|
$cc->input = $tx->req->params->to_hash; |
41
|
|
|
|
|
|
|
$cc->headers = { 'Content-Type' => 'text/html' }; |
42
|
|
|
|
|
|
|
$cc->v = {}; |
43
|
|
|
|
|
|
|
# $cc->state = ? |
44
|
|
|
|
|
|
|
$cc->status = 200; |
45
|
|
|
|
|
|
|
$cc; |
46
|
|
|
|
|
|
|
}; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub mojo { |
49
|
1
|
|
|
1
|
|
7
|
no strict 'refs'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
269
|
|
50
|
0
|
|
|
0
|
1
|
|
my ($app, $mojo, $tx) = @_; |
51
|
0
|
|
|
|
|
|
my ($c, $p) = &{ $app . "::D" }($tx->req->url->path); |
|
0
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
my $cc = $p{init_cc}->($c, $tx); |
53
|
0
|
|
|
|
|
|
$cc->log = $mojo->log; |
54
|
0
|
|
|
|
|
|
my $content = $app->service($cc, @$p); |
55
|
0
|
|
|
|
|
|
my $h = $tx->res->headers; |
56
|
0
|
|
|
|
|
|
my $ch = $cc->headers; |
57
|
0
|
|
|
|
|
|
for my $header (keys %$ch) { |
58
|
0
|
0
|
|
|
|
|
if (ref $ch->{$header} eq 'ARRAY') { |
59
|
0
|
|
|
|
|
|
for my $item (@{ $ch->{$header} }) { |
|
0
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
$h->add($header => $item); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
} else { |
63
|
0
|
|
|
|
|
|
$h->add($header => $ch->{$header}); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
} |
66
|
0
|
|
|
|
|
|
$tx->res->code($cc->status); |
67
|
0
|
|
|
|
|
|
$tx->res->body($content); |
68
|
0
|
|
|
|
|
|
$tx; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
1; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
__END__ |