| 1 | package Alien::Build::Plugin::Decode::HTML; | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use 5.008004; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use Alien::Build::Plugin; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use File::Basename (); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||
| 9 | # ABSTRACT: Plugin to extract links from HTML | ||||||||||||||||||||||||||||||||
| 10 | 3 | our $VERSION = '2.88'; # VERSION | |||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||
| 13 | sub init | ||||||||||||||||||||||||||||||||
| 14 | 4 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 15 | 4 | my($self, $meta) = @_; | |||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||
| 17 | 4 | $meta->add_requires('share' => 'HTML::LinkExtor' => 0); | |||||||||||||||||||||||||||||||
| 18 | 4 | $meta->add_requires('share' => 'URI' => 0); | |||||||||||||||||||||||||||||||
| 19 | 4 | $meta->add_requires('share' => 'URI::Escape' => 0); | |||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||
| 21 | 5 | ▶ | $meta->register_hook( decode => sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||
| 22 | 5 | my(undef, $res) = @_; | |||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||
| 24 | 0 | die "do not know how to decode @{[ $res->{type} ]}" | |||||||||||||||||||||||||||||||
| 25 | 5 | ▶ | unless $res->{type} eq 'html'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||
| 27 | 5 | my $base = URI->new($res->{base}); | |||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||
| 29 | 5 | my @list; | |||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||
| 31 | 33 | ▶ | my $p = HTML::LinkExtor->new(sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=18.3
| |||||||||||||||||||||||||||||||||
| 32 | 33 | my($tag, %links) = @_; | |||||||||||||||||||||||||||||||
| 33 | 33 | ▶ | if($tag eq 'base' && $links{href}) | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
$tag eq "base" and $links{"href"}
MC/DC50%1/2
$tag eq "base" and $links{"href"}
$tag eq "base"
$links{"href"}
Truth table66%2/3
A and B
A= $tag eq "base"B= $links{"href"}
| |||||||||||||||||||||||||||||||||
| 34 | { | ||||||||||||||||||||||||||||||||
| 35 | 1 | $base = URI->new($links{href}); | |||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||
| 37 | ▶ | elsif($tag eq 'a' && $links{href}) | |||||||||||||||||||||||||||||||
|
Condition33%1/3
$tag eq "a" and $links{"href"}
MC/DC0%0/2
$tag eq "a" and $links{"href"}
$tag eq "a"
$links{"href"}
Truth table33%1/3
A and B
A= $tag eq "a"B= $links{"href"}
| |||||||||||||||||||||||||||||||||
| 38 | { | ||||||||||||||||||||||||||||||||
| 39 | 32 | my $href = $links{href}; | |||||||||||||||||||||||||||||||
| 40 | 32 | ▶ | return if $href =~ m!^\.\.?/?$!; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 41 | 28 | my $url = URI->new_abs($href, $base); | |||||||||||||||||||||||||||||||
| 42 | 28 | my $path = $url->path; | |||||||||||||||||||||||||||||||
| 43 | 28 | $path =~ s{/$}{}; # work around for Perl 5.8.7- gh#8 | |||||||||||||||||||||||||||||||
| 44 | 28 | push @list, { | |||||||||||||||||||||||||||||||
| 45 | filename => URI::Escape::uri_unescape(File::Basename::basename($path)), | ||||||||||||||||||||||||||||||||
| 46 | url => URI::Escape::uri_unescape($url->as_string), | ||||||||||||||||||||||||||||||||
| 47 | }; | ||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||
| 49 | 5 | }); | |||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||
| 51 | 5 | $p->parse($res->{content}); | |||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||
| 53 | return { | ||||||||||||||||||||||||||||||||
| 54 | 5 | type => 'list', | |||||||||||||||||||||||||||||||
| 55 | list => \@list, | ||||||||||||||||||||||||||||||||
| 56 | }; | ||||||||||||||||||||||||||||||||
| 57 | 4 | }); | |||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||
| 59 | 4 | $self; | |||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||
| 62 | 3 | 1; | |||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||
| 64 | __END__ | ||||||||||||||||||||||||||||||||