line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# This file is part of Plack-Middleware-Pjax |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# This software is copyright (c) 2011 by Matthew Phillips. |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
# This is free software; you can redistribute it and/or modify it under |
7
|
|
|
|
|
|
|
# the same terms as the Perl 5 programming language system itself. |
8
|
|
|
|
|
|
|
# |
9
|
1
|
|
|
1
|
|
79252
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
35
|
|
10
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
56
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
package Plack::Middleware::Pjax; |
13
|
|
|
|
|
|
|
{ |
14
|
|
|
|
|
|
|
$Plack::Middleware::Pjax::VERSION = '1.113400'; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
# ABSTRACT: PJAX for your Plack |
17
|
1
|
|
|
1
|
|
5
|
use parent qw/Plack::Middleware/; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
9
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
1
|
|
|
1
|
|
66
|
use Plack::Util; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
22
|
|
21
|
1
|
|
|
1
|
|
913
|
use Plack::Request; |
|
1
|
|
|
|
|
41538
|
|
|
1
|
|
|
|
|
37
|
|
22
|
1
|
|
|
1
|
|
1067
|
use Marpa::HTML; |
|
1
|
|
|
|
|
132096
|
|
|
1
|
|
|
|
|
539
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub call { |
25
|
7
|
|
|
7
|
1
|
49798
|
my ($self, $env) = @_; |
26
|
|
|
|
|
|
|
|
27
|
7
|
|
|
|
|
44
|
my $res = $self->app->($env); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
Plack::Util::response_cb($res, sub { |
30
|
7
|
|
|
7
|
|
133
|
my $req = Plack::Request->new($env); |
31
|
7
|
|
|
|
|
67
|
my $res = shift; |
32
|
|
|
|
|
|
|
|
33
|
7
|
100
|
|
|
|
30
|
return unless defined $req->header('x-pjax'); |
34
|
6
|
|
100
|
|
|
1127
|
my $tag = $req->header('x-pjax-container') || 'data-pjax-container'; |
35
|
|
|
|
|
|
|
|
36
|
6
|
|
|
|
|
258
|
my $body = []; |
37
|
6
|
|
|
|
|
48
|
Plack::Util::foreach($res->[2], sub { push @$body, $_[0]; }); |
|
6
|
|
|
|
|
61
|
|
38
|
6
|
|
|
|
|
57
|
$body = join '', @$body; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
my $stripped = Marpa::HTML::html( \$body,{ |
41
|
|
|
|
|
|
|
q{*} => sub { |
42
|
27
|
100
|
|
|
|
1022279
|
if (Marpa::HTML::attributes()->{$tag}) { |
43
|
5
|
|
|
|
|
89
|
push @{$Marpa::HTML::INSTANCE->{stripped}}, Marpa::HTML::contents(); |
|
5
|
|
|
|
|
31
|
|
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
}, |
46
|
|
|
|
|
|
|
q{title} => sub { |
47
|
2
|
|
|
|
|
533555
|
unshift @{$Marpa::HTML::INSTANCE->{stripped}}, Marpa::HTML::original(); |
|
2
|
|
|
|
|
20
|
|
48
|
|
|
|
|
|
|
}, |
49
|
|
|
|
|
|
|
':TOP' => sub { |
50
|
6
|
100
|
|
|
|
1009
|
$Marpa::HTML::INSTANCE->{stripped} || []; |
51
|
|
|
|
|
|
|
} |
52
|
6
|
|
|
|
|
78
|
}); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# if length is 0 or 1, there was no pjax container in the body, |
55
|
|
|
|
|
|
|
# so just return the original |
56
|
6
|
100
|
|
|
|
8566
|
if (@$stripped > 0) { |
57
|
5
|
|
|
|
|
26
|
$res->[2] = [join '', @$stripped]; |
58
|
5
|
|
|
|
|
43
|
my $h = Plack::Util::headers($res->[1]); |
59
|
|
|
|
|
|
|
# recalculate content length after changing it |
60
|
5
|
|
|
|
|
216
|
$h->set('Content-Length', Plack::Util::content_length($res->[2])); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
6
|
|
|
|
|
490
|
return $res; |
64
|
7
|
|
|
|
|
235
|
}); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
1; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
__END__ |