blib/lib/Alien/Build/Plugin/Decode/HTML.pm

filter: Statementstmt 97.4% 38 / 39 Branchbran 75.0% 6 / 8 Conditioncond 50.0% 3 / 6 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 100% 8 / 8 Podpod 100% 1 / 1 totaltotal 86.3% 57 / 66 CC 7 SCAR 12.2
CC
7
Cov
89%
__ANON__
6.2
__ANON__
2.0
init
1.0
CRAP 3.4
« blib/lib/Alien/Build/Plugin/Build/Copy.pm ↑ Summary blib/lib/Alien/Build/Log.pm »
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
BranchTrueFalseTotal
unless $res->{"type"} eq "html" 0 5 5
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
BranchTrueFalseTotal
if ($tag eq 'base' and $links{'href'}) { } 1 32 33
elsif ($tag eq 'a' and $links{'href'}) { } 32 0 32
Condition66%2/3
$tag eq "base" and $links{"href"}
!ll&&!rl&&r
3201
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"}
ABresult
0X0
100
111
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"}
!ll&&!rl&&r
0032
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"}
ABresult
0X0
100
111
38 {
39 32 my $href = $links{href};
40 32 ▶ return if $href =~ m!^\.\.?/?$!;
Branch: 1 branch
BranchTrueFalseTotal
if $href =~ m[^\.\.?/?$] 4 28 32
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__
« blib/lib/Alien/Build/Plugin/Build/Copy.pm ↑ Summary blib/lib/Alien/Build/Log.pm »