line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Plack::Middleware::JSONP; |
2
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
3
|
1
|
|
|
1
|
|
4
|
use parent qw(Plack::Middleware); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
3
|
|
4
|
1
|
|
|
1
|
|
52
|
use Plack::Util; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
15
|
|
5
|
1
|
|
|
1
|
|
389
|
use URI::Escape (); |
|
1
|
|
|
|
|
1226
|
|
|
1
|
|
|
|
|
34
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
5
|
use Plack::Util::Accessor qw/callback_key/; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
5
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub prepare_app { |
10
|
2
|
|
|
2
|
1
|
3
|
my $self = shift; |
11
|
2
|
100
|
|
|
|
4
|
unless (defined $self->callback_key) { |
12
|
1
|
|
|
|
|
3
|
$self->callback_key('callback'); |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub call { |
17
|
4
|
|
|
4
|
1
|
7
|
my($self, $env) = @_; |
18
|
4
|
|
|
|
|
12
|
my $res = $self->app->($env); |
19
|
|
|
|
|
|
|
$self->response_cb($res, sub { |
20
|
4
|
|
|
4
|
|
6
|
my $res = shift; |
21
|
4
|
50
|
|
|
|
10
|
if (defined $res->[2]) { |
22
|
4
|
|
|
|
|
9
|
my $h = Plack::Util::headers($res->[1]); |
23
|
4
|
|
|
|
|
17
|
my $callback_key = $self->callback_key; |
24
|
4
|
100
|
66
|
|
|
21
|
if ($h->get('Content-Type') =~ m!/(?:json|javascript)! && |
25
|
|
|
|
|
|
|
$env->{QUERY_STRING} =~ /(?:^|&)$callback_key=([^&]+)/) { |
26
|
2
|
|
|
|
|
6
|
my $cb = URI::Escape::uri_unescape($1); |
27
|
2
|
50
|
|
|
|
19
|
if ($cb =~ /^[\w\.\[\]]+$/) { |
28
|
2
|
|
|
|
|
3
|
my $body; |
29
|
2
|
|
|
|
|
10
|
Plack::Util::foreach($res->[2], sub { $body .= $_[0] }); |
|
3
|
|
|
|
|
7
|
|
30
|
2
|
|
|
|
|
9
|
my $jsonp = "/**/$cb($body)"; |
31
|
2
|
|
|
|
|
4
|
$res->[2] = [ $jsonp ]; |
32
|
2
|
|
|
|
|
22
|
$h->set('Content-Length', length $jsonp); |
33
|
2
|
|
|
|
|
8
|
$h->set('Content-Type', 'text/javascript'); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
} |
37
|
4
|
|
|
|
|
45
|
}); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
1; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
__END__ |