line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
59456
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
2
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
46
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package Plack::Middleware::Pjax; |
5
|
|
|
|
|
|
|
$Plack::Middleware::Pjax::VERSION = '1.114400'; |
6
|
|
|
|
|
|
|
# ABSTRACT: PJAX for your Plack |
7
|
1
|
|
|
1
|
|
4
|
use parent qw/Plack::Middleware/; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
7
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
52
|
use Plack::Util; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
20
|
|
11
|
1
|
|
|
1
|
|
457
|
use Plack::Request; |
|
1
|
|
|
|
|
29353
|
|
|
1
|
|
|
|
|
39
|
|
12
|
1
|
|
|
1
|
|
1025
|
use Marpa::R2::HTML; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub call { |
15
|
|
|
|
|
|
|
my ($self, $env) = @_; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my $res = $self->app->($env); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
Plack::Util::response_cb($res, sub { |
20
|
|
|
|
|
|
|
my $req = Plack::Request->new($env); |
21
|
|
|
|
|
|
|
my $res = shift; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
return unless defined $req->header('x-pjax'); |
24
|
|
|
|
|
|
|
my $tag = $req->header('x-pjax-container') || 'data-pjax-container'; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
my $body = []; |
27
|
|
|
|
|
|
|
Plack::Util::foreach($res->[2], sub { push @$body, $_[0]; }); |
28
|
|
|
|
|
|
|
$body = join '', @$body; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
my $stripped = Marpa::R2::HTML::html( \$body,{ |
31
|
|
|
|
|
|
|
q{*} => sub { |
32
|
|
|
|
|
|
|
if (Marpa::R2::HTML::attributes()->{$tag}) { |
33
|
|
|
|
|
|
|
push @{$Marpa::R2::HTML::INSTANCE->{stripped}}, Marpa::R2::HTML::contents(); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
}, |
36
|
|
|
|
|
|
|
q{title} => sub { |
37
|
|
|
|
|
|
|
unshift @{$Marpa::R2::HTML::INSTANCE->{stripped}}, Marpa::R2::HTML::original(); |
38
|
|
|
|
|
|
|
}, |
39
|
|
|
|
|
|
|
':TOP' => sub { |
40
|
|
|
|
|
|
|
$Marpa::R2::HTML::INSTANCE->{stripped} || []; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
}); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# if length is 0 or 1, there was no pjax container in the body, |
45
|
|
|
|
|
|
|
# so just return the original |
46
|
|
|
|
|
|
|
if (@$stripped > 0) { |
47
|
|
|
|
|
|
|
$res->[2] = [join '', @$stripped]; |
48
|
|
|
|
|
|
|
my $h = Plack::Util::headers($res->[1]); |
49
|
|
|
|
|
|
|
# recalculate content length after changing it |
50
|
|
|
|
|
|
|
$h->set('Content-Length', Plack::Util::content_length($res->[2])); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
return $res; |
54
|
|
|
|
|
|
|
}); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
1; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
__END__ |