| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package HTML::Feature::FrontParser; |
|
2
|
7
|
|
|
7
|
|
728
|
use strict; |
|
|
7
|
|
|
|
|
11
|
|
|
|
7
|
|
|
|
|
209
|
|
|
3
|
7
|
|
|
7
|
|
36
|
use warnings; |
|
|
7
|
|
|
|
|
10
|
|
|
|
7
|
|
|
|
|
150
|
|
|
4
|
7
|
|
|
7
|
|
32
|
use Carp; |
|
|
7
|
|
|
|
|
13
|
|
|
|
7
|
|
|
|
|
582
|
|
|
5
|
7
|
|
|
7
|
|
7023
|
use URI; |
|
|
7
|
|
|
|
|
58202
|
|
|
|
7
|
|
|
|
|
233
|
|
|
6
|
7
|
|
|
7
|
|
68
|
use Scalar::Util qw(blessed); |
|
|
7
|
|
|
|
|
13
|
|
|
|
7
|
|
|
|
|
881
|
|
|
7
|
7
|
|
|
7
|
|
6995
|
use UNIVERSAL::require; |
|
|
7
|
|
|
|
|
12282
|
|
|
|
7
|
|
|
|
|
85
|
|
|
8
|
7
|
|
|
7
|
|
219
|
use base qw(HTML::Feature::Base); |
|
|
7
|
|
|
|
|
15
|
|
|
|
7
|
|
|
|
|
4710
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors($_) for qw( _fetcher _decoder); |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub parse { |
|
13
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
14
|
0
|
|
|
|
|
|
my $arg = shift; |
|
15
|
0
|
0
|
|
|
|
|
if ( !$arg ) { |
|
16
|
0
|
|
|
|
|
|
croak('Usage: parse( $uri | $http_response | $html_ref )'); |
|
17
|
|
|
|
|
|
|
} |
|
18
|
0
|
|
|
|
|
|
my $pkg = blessed($arg); |
|
19
|
0
|
0
|
|
|
|
|
if ( !$pkg ) { |
|
20
|
0
|
0
|
|
|
|
|
if ( my $ref = ref $arg ) { |
|
21
|
0
|
0
|
|
|
|
|
if ( $ref eq 'SCALAR' ) { |
|
22
|
0
|
|
|
|
|
|
my $html = $$arg; |
|
23
|
0
|
0
|
|
|
|
|
unless ( $self->context->config->{not_decode} ) { |
|
24
|
0
|
0
|
|
|
|
|
if(utf8::is_utf8($html)){ |
|
25
|
0
|
|
|
|
|
|
utf8::encode($html); |
|
26
|
|
|
|
|
|
|
} |
|
27
|
0
|
|
|
|
|
|
$html = $self->decoder->decode($html); |
|
28
|
|
|
|
|
|
|
} |
|
29
|
0
|
|
|
|
|
|
return $html; |
|
30
|
|
|
|
|
|
|
} |
|
31
|
0
|
|
|
|
|
|
croak('Usage: parse( $uri | $http_response | $html_ref )'); |
|
32
|
|
|
|
|
|
|
} |
|
33
|
0
|
|
|
|
|
|
$pkg = 'URI'; |
|
34
|
0
|
|
|
|
|
|
$arg = URI->new($arg); |
|
35
|
|
|
|
|
|
|
} |
|
36
|
0
|
0
|
|
|
|
|
if ( $pkg->isa('URI') ) { |
|
|
|
0
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
return $self->_parse_url( $arg, @_ ); |
|
38
|
|
|
|
|
|
|
} |
|
39
|
|
|
|
|
|
|
elsif ( $pkg->isa('HTTP::Response') ) { |
|
40
|
0
|
|
|
|
|
|
return $self->_parse_response( $arg, @_ ); |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
else { |
|
43
|
0
|
|
|
|
|
|
croak('Usage: parse( $uri | $http_response | $html_ref )'); |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub _parse_url { |
|
48
|
0
|
|
|
0
|
|
|
my $self = shift; |
|
49
|
0
|
|
|
|
|
|
my $url = shift; |
|
50
|
0
|
|
|
|
|
|
my $res = $self->fetcher->request($url); |
|
51
|
0
|
|
|
|
|
|
$self->_parse_response( $res, @_ ); |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub _parse_response { |
|
55
|
0
|
|
|
0
|
|
|
my $self = shift; |
|
56
|
0
|
|
|
|
|
|
my $http_response = shift; |
|
57
|
0
|
|
|
|
|
|
my $args = shift; |
|
58
|
0
|
|
|
|
|
|
my $c = $self->context; |
|
59
|
0
|
0
|
|
|
|
|
if ( $args->{element_flag} ) { |
|
60
|
0
|
|
|
|
|
|
$self->{element_flag} = $args->{element_flag}; |
|
61
|
|
|
|
|
|
|
} |
|
62
|
0
|
|
|
|
|
|
$c->{base_url} = $http_response->base; |
|
63
|
0
|
|
|
|
|
|
my $html = $http_response->content; |
|
64
|
0
|
0
|
|
|
|
|
unless ( $c->config->{not_decode} ) { |
|
65
|
0
|
|
|
|
|
|
$html = $self->decoder->decode( $html, { response => $http_response } ); |
|
66
|
|
|
|
|
|
|
} |
|
67
|
0
|
|
|
|
|
|
return $html; |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
#--- |
|
71
|
|
|
|
|
|
|
# accessor methods |
|
72
|
|
|
|
|
|
|
#--- |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub fetcher { |
|
75
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
76
|
0
|
|
|
|
|
|
my $args = shift; |
|
77
|
0
|
0
|
|
|
|
|
if ( !$args ) { |
|
78
|
|
|
|
|
|
|
$self->_fetcher or sub { |
|
79
|
0
|
0
|
|
0
|
|
|
HTML::Feature::Fetcher->require or die $@; |
|
80
|
0
|
|
|
|
|
|
my $fetcher = HTML::Feature::Fetcher->new( context => $self->context ); |
|
81
|
0
|
|
|
|
|
|
$self->_fetcher($fetcher); |
|
82
|
|
|
|
|
|
|
} |
|
83
|
0
|
0
|
|
|
|
|
->(); |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
else { |
|
86
|
0
|
|
|
|
|
|
$self->_fetcher($args); |
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub decoder { |
|
91
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
92
|
0
|
|
|
|
|
|
my $args = shift; |
|
93
|
0
|
0
|
|
|
|
|
if ( !$args ) { |
|
94
|
|
|
|
|
|
|
$self->_decoder or sub { |
|
95
|
0
|
0
|
|
0
|
|
|
HTML::Feature::Decoder->require or die $@; |
|
96
|
0
|
|
|
|
|
|
$self->_decoder( HTML::Feature::Decoder->new( context => $self->context ) ); |
|
97
|
|
|
|
|
|
|
} |
|
98
|
0
|
0
|
|
|
|
|
->(); |
|
99
|
|
|
|
|
|
|
} |
|
100
|
|
|
|
|
|
|
else { |
|
101
|
0
|
|
|
|
|
|
$self->_decoder($args); |
|
102
|
|
|
|
|
|
|
} |
|
103
|
|
|
|
|
|
|
} |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
1; |
|
106
|
|
|
|
|
|
|
__END__ |