line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::Feature::Engine; |
2
|
6
|
|
|
6
|
|
37
|
use strict; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
206
|
|
3
|
6
|
|
|
6
|
|
32
|
use warnings; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
157
|
|
4
|
6
|
|
|
6
|
|
3613
|
use HTML::Feature::Engine::TagStructure; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
use HTML::Feature::Engine::LDRFullFeed; |
6
|
|
|
|
|
|
|
use HTML::Feature::Engine::GoogleADSection; |
7
|
|
|
|
|
|
|
use UNIVERSAL::require; |
8
|
|
|
|
|
|
|
use Encode; |
9
|
|
|
|
|
|
|
use Carp; |
10
|
|
|
|
|
|
|
use base qw(HTML::Feature::Base); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
|
|
|
|
|
|
my $class = shift; |
14
|
|
|
|
|
|
|
my $self = $class->SUPER::new(@_); |
15
|
|
|
|
|
|
|
$self->_setup; |
16
|
|
|
|
|
|
|
return $self; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub run { |
20
|
|
|
|
|
|
|
my $self = shift; |
21
|
|
|
|
|
|
|
my $html_ref = shift; |
22
|
|
|
|
|
|
|
my $url = shift; |
23
|
|
|
|
|
|
|
my $c = $self->context; |
24
|
|
|
|
|
|
|
my $result = HTML::Feature::Result->new; |
25
|
|
|
|
|
|
|
eval { |
26
|
|
|
|
|
|
|
LABEL: for my $engine ( @{ $self->{engines} } ) |
27
|
|
|
|
|
|
|
{ |
28
|
|
|
|
|
|
|
$result = $engine->run( $html_ref, $url, $result ); |
29
|
|
|
|
|
|
|
if ( $result->{matched_engine} ) { |
30
|
|
|
|
|
|
|
if ( defined $c->{enc_type} ) { |
31
|
|
|
|
|
|
|
$result->title( |
32
|
|
|
|
|
|
|
Encode::encode( $c->{enc_type}, $result->title ) ); |
33
|
|
|
|
|
|
|
$result->desc( |
34
|
|
|
|
|
|
|
Encode::encode( $c->{enc_type}, $result->desc ) ); |
35
|
|
|
|
|
|
|
$result->text( |
36
|
|
|
|
|
|
|
Encode::encode( $c->{enc_type}, $result->text ) ); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
last LABEL; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
}; |
42
|
|
|
|
|
|
|
if ($@) { |
43
|
|
|
|
|
|
|
carp("can not parse data"); |
44
|
|
|
|
|
|
|
return HTML::Feature::Result->new; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
return $result; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub _setup { |
50
|
|
|
|
|
|
|
my $self = shift; |
51
|
|
|
|
|
|
|
my $c = $self->context; |
52
|
|
|
|
|
|
|
my $config = $c->config; |
53
|
|
|
|
|
|
|
if ( !defined $config->{engines} || @{ $config->{engines} } < 1 ) { |
54
|
|
|
|
|
|
|
my $engine = HTML::Feature::Engine::TagStructure->new( context => $c ); |
55
|
|
|
|
|
|
|
push( @{ $self->{engines} }, $engine ); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
else { |
58
|
|
|
|
|
|
|
for my $class ( @{ $config->{engines} } ) { |
59
|
|
|
|
|
|
|
unless ( $class->can('new') ) { |
60
|
|
|
|
|
|
|
$class->require or die $@; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
my $engine = $class->new( context => $c ); |
63
|
|
|
|
|
|
|
push( @{ $self->{engines} }, $engine ); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
1; |
69
|
|
|
|
|
|
|
__END__ |