line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Alien::Build::Plugin::Decode::Mojo; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
222133
|
use strict; |
|
2
|
|
|
|
|
10
|
|
|
2
|
|
|
|
|
76
|
|
4
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
45
|
|
5
|
2
|
|
|
2
|
|
42
|
use 5.008004; |
|
2
|
|
|
|
|
7
|
|
6
|
2
|
|
|
2
|
|
444
|
use Alien::Build::Plugin; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
13
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# ABSTRACT: Plugin to extract links from HTML using Mojo::DOM or Mojo::DOM58 |
9
|
|
|
|
|
|
|
our $VERSION = '2.46'; # VERSION |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub _load ($;$) |
13
|
|
|
|
|
|
|
{ |
14
|
2
|
|
|
2
|
|
6
|
my($class, $version) = @_; |
15
|
2
|
|
|
|
|
6
|
my $pm = "$class.pm"; |
16
|
2
|
|
|
|
|
8
|
$pm =~ s/::/\//g; |
17
|
2
|
|
|
|
|
5
|
eval { require $pm }; |
|
2
|
|
|
|
|
260
|
|
18
|
2
|
50
|
|
|
|
17
|
return 0 if $@; |
19
|
0
|
0
|
|
|
|
0
|
if(defined $version) |
20
|
|
|
|
|
|
|
{ |
21
|
0
|
|
|
|
|
0
|
eval { $class->VERSION($version) }; |
|
0
|
|
|
|
|
0
|
|
22
|
0
|
0
|
|
|
|
0
|
return 0 if $@; |
23
|
|
|
|
|
|
|
} |
24
|
0
|
|
|
|
|
0
|
return 1; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
has _class => sub { |
28
|
|
|
|
|
|
|
return 'Mojo::DOM58' if _load 'Mojo::DOM58'; |
29
|
|
|
|
|
|
|
return 'Mojo::DOM' if _load 'Mojo::DOM' and _load 'Mojolicious', 7.00; |
30
|
|
|
|
|
|
|
return 'Mojo::DOM58'; |
31
|
|
|
|
|
|
|
}; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub init |
34
|
|
|
|
|
|
|
{ |
35
|
3
|
|
|
3
|
1
|
8
|
my($self, $meta) = @_; |
36
|
|
|
|
|
|
|
|
37
|
3
|
|
|
|
|
11
|
$meta->add_requires('share' => 'URI' => 0); |
38
|
3
|
|
|
|
|
11
|
$meta->add_requires('share' => 'URI::Escape' => 0); |
39
|
|
|
|
|
|
|
|
40
|
3
|
|
33
|
|
|
8
|
my $class = $meta->prop->{plugin_decode_mojo_class} ||= $self->_class; |
41
|
|
|
|
|
|
|
|
42
|
3
|
100
|
|
|
|
11
|
if($class eq 'Mojo::DOM58') |
|
|
50
|
|
|
|
|
|
43
|
|
|
|
|
|
|
{ |
44
|
2
|
|
|
|
|
6
|
$meta->add_requires('share' => 'Mojo::DOM58' => '1.00'); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
elsif($class eq 'Mojo::DOM') |
47
|
|
|
|
|
|
|
{ |
48
|
1
|
|
|
|
|
4
|
$meta->add_requires('share' => 'Mojolicious' => '7.00'); |
49
|
1
|
|
|
|
|
4
|
$meta->add_requires('share' => 'Mojo::DOM' => '0'); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
else |
52
|
|
|
|
|
|
|
{ |
53
|
0
|
|
|
|
|
0
|
die "bad class"; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
$meta->register_hook( decode => sub { |
57
|
0
|
|
|
0
|
|
|
my(undef, $res) = @_; |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
die "do not know how to decode @{[ $res->{type} ]}" |
60
|
0
|
0
|
|
|
|
|
unless $res->{type} eq 'html'; |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
my $dom = $class->new($res->{content}); |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
my $base = URI->new($res->{base}); |
65
|
|
|
|
|
|
|
|
66
|
0
|
0
|
|
|
|
|
if(my $base_element = $dom->find('head base')->first) |
67
|
|
|
|
|
|
|
{ |
68
|
0
|
|
|
|
|
|
my $href = $base_element->attr('href'); |
69
|
0
|
0
|
|
|
|
|
$base = URI->new($href) if defined $href; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
my @list = map { |
73
|
0
|
|
|
|
|
|
my $url = URI->new_abs($_, $base); |
74
|
0
|
|
|
|
|
|
my $path = $url->path; |
75
|
0
|
|
|
|
|
|
$path =~ s{/$}{}; # work around for Perl 5.8.7- gh#8 |
76
|
|
|
|
|
|
|
{ |
77
|
0
|
|
|
|
|
|
filename => URI::Escape::uri_unescape(File::Basename::basename($path)), |
78
|
|
|
|
|
|
|
url => URI::Escape::uri_unescape($url->as_string), |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
grep !/^\.\.?\/?$/, |
82
|
0
|
0
|
|
|
|
|
map { $_->attr('href') || () } |
83
|
0
|
|
|
|
|
|
@{ $dom->find('a')->to_array }; |
|
0
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
return { |
86
|
0
|
|
|
|
|
|
type => 'list', |
87
|
|
|
|
|
|
|
list => \@list, |
88
|
|
|
|
|
|
|
}; |
89
|
|
|
|
|
|
|
}) |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
|
92
|
3
|
|
|
|
|
21
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
1; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
__END__ |