« 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
| |||||||||||||||||||||||||||||
| 19 | 5 | ▶ | if(defined $version) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | { | ||||||||||||||||||||||||||||
| 21 | 0 | eval { $class->VERSION($version) }; | |||||||||||||||||||||||||||
| 22 | 0 | ▶ | return 0 if $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 29 | 0 | ▶ | return 'Mojo::DOM' if _load 'Mojo::DOM' and _load 'Mojolicious', 7.00; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
&_load("Mojo::DOM") and &_load("Mojolicious", 7)
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)
| |||||||||||||||||||||||||||||
| 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
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
| |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 7 | ▶ | if($class eq 'Mojo::DOM58') | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 67 | { | ||||||||||||||||||||||||||||
| 68 | 1 | my $href = $base_element->attr('href'); | |||||||||||||||||||||||||||
| 69 | 1 | ▶ | $base = URI->new($href) if defined $href; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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') || ()
MC/DC0%0/2
$_->attr('href') || ()
$_->attr('href')
()
Truth table33%1/3
A || B
A= $_->attr('href')B= ()
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||