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

filter: Statementstmt 87.0% 47 / 54 Branchbran 50.0% 10 / 20 Conditioncond 22.2% 2 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 100% 8 / 8 Podpod 100% 1 / 1 totaltotal 69.3% 68 / 98 CC 14 SCAR 17.1
CC
14
Cov
71%
__ANON__
12.2
__ANON__
5.2
_load
5.1
CRAP 5.5
« blib/lib/Alien/Build/Plugin/Digest/Negotiate.pm ↑ Summary blib/lib/Alien/Build/Plugin/Gather/IsolateDynamic.pm »
1 package Alien::Build::Plugin::Decode::Mojo;
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  
8 # ABSTRACT: Plugin to extract links from HTML using Mojo::DOM or Mojo::DOM58
9 3 our $VERSION = '2.88'; # VERSION
10  
11  
12 sub _load ($;$)
13 5 ▶{
Subroutine _load: called CC=4 SCAR=16.3
14 5 my($class, $version) = @_;
15 5 my $pm = "$class.pm";
16 5 $pm =~ s/::/\//g;
17 5 eval { require $pm };
18 5 ▶ return 0 if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 5 5
19 5 ▶ if(defined $version)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $version) 0 5 5
20 {
21 0 eval { $class->VERSION($version) };
22 0 ▶ return 0 if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
23 }
24 5 return 1;
25 }
26  
27 5 ▶has _class => sub {
Subroutine __ANON__: called CC=4 SCAR=25.0
28 5 ▶ return 'Mojo::DOM58' if _load 'Mojo::DOM58';
Branch: 1 branch
BranchTrueFalseTotal
if &_load("Mojo::DOM58") 5 0 5
29 0 ▶ return 'Mojo::DOM' if _load 'Mojo::DOM' and _load 'Mojolicious', 7.00;
Branch: 1 branch
BranchTrueFalseTotal
if &_load("Mojo::DOM") and &_load("Mojolicious", 7) 0 0 0
Condition0%0/3
&_load("Mojo::DOM") and &_load("Mojolicious", 7)
!ll&&!rl&&r
000
MC/DC0%0/2
&_load("Mojo::DOM") and &_load("Mojolicious", 7)
&_load("Mojo::DOM") &_load("Mojolicious", 7)
Truth table0%0/3
A and B
A= &_load("Mojo::DOM")B= &_load("Mojolicious", 7)
ABresult
0X0
100
111
30 0 return 'Mojo::DOM58';
31 3 };
32  
33 sub init
34 7 ▶{
Subroutine init: called CC=4 SCAR=14.2
Pod documented
35 7 my($self, $meta) = @_;
36  
37 7 $meta->add_requires('share' => 'URI' => 0);
38 7 $meta->add_requires('share' => 'URI::Escape' => 0);
39  
40 7 ▶ my $class = $meta->prop->{plugin_decode_mojo_class} ||= $self->_class;
Condition33%1/3
$meta->prop->{"plugin_decode_mojo_class"} ||= $self->_class
l!l&&r!l&&!r
070
MC/DC0%0/2
$meta->prop->{"plugin_decode_mojo_class"} ||= $self->_class
$meta->prop->{"plugin_decode_mojo_class"} $self->_class
Truth table33%1/3
A ||= B
A= $meta->prop->{"plugin_decode_mojo_class"}B= $self->_class
ABresult
1X1
011
000
41  
42 7 ▶ if($class eq 'Mojo::DOM58')
Branch: 2 branches
BranchTrueFalseTotal
if ($class eq 'Mojo::DOM58') { } 6 1 7
elsif ($class eq 'Mojo::DOM') { } 1 0 1
43 {
44 6 $meta->add_requires('share' => 'Mojo::DOM58' => '1.00');
45 }
46 elsif($class eq 'Mojo::DOM')
47 {
48 1 $meta->add_requires('share' => 'Mojolicious' => '7.00');
49 1 $meta->add_requires('share' => 'Mojo::DOM' => '0');
50 }
51 else
52 {
53 0 die "bad class";
54 }
55  
56 3 ▶ $meta->register_hook( decode => sub {
Subroutine __ANON__: called CC=5 SCAR=16.5
57 3 my(undef, $res) = @_;
58  
59 0 die "do not know how to decode @{[ $res->{type} ]}"
60 3 ▶ unless $res->{type} eq 'html';
Branch: 1 branch
BranchTrueFalseTotal
unless $res->{"type"} eq "html" 0 3 3
61  
62 3 my $dom = $class->new($res->{content});
63  
64 3 my $base = URI->new($res->{base});
65  
66 3 ▶ if(my $base_element = $dom->find('head base')->first)
Branch: 1 branch
BranchTrueFalseTotal
if (my $base_element = $dom->find("head base")->first) 1 2 3
67 {
68 1 my $href = $base_element->attr('href');
69 1 ▶ $base = URI->new($href) if defined $href;
Branch: 1 branch
BranchTrueFalseTotal
if defined $href 1 0 1
70 }
71  
72 my @list = map {
73 24 my $url = URI->new_abs($_, $base);
74 24 my $path = $url->path;
75 24 $path =~ s{/$}{}; # work around for Perl 5.8.7- gh#8
76 {
77 24 filename => URI::Escape::uri_unescape(File::Basename::basename($path)),
78 url => URI::Escape::uri_unescape($url->as_string),
79 }
80 }
81 grep !/^\.\.?\/?$/,
82 28 ▶ map { $_->attr('href') || () }
Condition33%1/3
$_->attr('href') || ()
l!l&&r!l&&!r
2800
MC/DC0%0/2
$_->attr('href') || ()
$_->attr('href') ()
Truth table33%1/3
A || B
A= $_->attr('href')B= ()
ABresult
1X1
011
000
83 3 @{ $dom->find('a')->to_array };
84  
85 return {
86 3 type => 'list',
87 list => \@list,
88 };
89 })
90  
91  
92 7 }
93  
94 3 1;
95  
96 __END__
« blib/lib/Alien/Build/Plugin/Digest/Negotiate.pm ↑ Summary blib/lib/Alien/Build/Plugin/Gather/IsolateDynamic.pm »