| 1 | package LinkEmbedder::Link::Basic; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use Mojo::Base 'LinkEmbedder::Link'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Mojo::JSON; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Mojo::Util 'trim'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | my $PHOTO_RE = qr!\.(?:jpg|png|gif)\b!i; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | my $VIDEO_RE = qr!\.(?:mpg|mpeg|mov|mp4|ogv)\b!i; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | sub learn_p { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 5 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
learn_p: called CC=4 SCAR=14.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 5 | my $url = $self->url; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 5 | ▶ | my $type = $url =~ $PHOTO_RE ? 'photo' : $url =~ $VIDEO_RE ? 'video' : 'link'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 5 | $self->type($type); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 5 | ▶ | return $type eq 'link' ? $self->SUPER::learn_p : Mojo::Promise->new->resolve($self->_learn_from_url); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | sub _learn_from_dom { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 4 | ▶ | my ($self, $dom) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_learn_from_dom: called CC=17 SCAR=42.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 4 | my $tmp; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 4 | $self->SUPER::_learn_from_dom($dom); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 4 | $tmp = $dom->at('script[type="application/ld+json"]'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 4 | ▶ | $self->_learn_from_json_schema($tmp->text) if $tmp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | # Bitbucket hack | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 4 | $tmp = $dom->at('div.codehilite'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 4 | ▶ | if ($tmp) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | $self->{paste} = $tmp->all_text; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | $self->template->[1] = 'paste.html.ep'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | # Mojopaste, Perlbot and other pages with <pre> tags | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 4 | ▶ | if ($tmp = $dom->at('pre#paste') || $dom->at('pre.paste') || $dom->at('body > pre') || $dom->at('body > div > pre')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%3/9
$dom->at('pre#paste') || $dom->at('pre.paste') || $dom->at('body > pre') || $dom->at('body > div > pre')
$dom->at("pre#paste") or $dom->at("pre.paste") or $dom->at("body > pre")
$dom->at("pre#paste") or $dom->at("pre.paste")
MC/DC0%0/4
$dom->at('pre#paste') || $dom->at('pre.paste') || $dom->at('body > pre') || $dom->at('body > div > pre')
$dom->at("pre#paste")
$dom->at("pre.paste")
$dom->at("body > pre")
$dom->at('body > div > pre')
Truth table20%1/5
A or B or C || D
A= $dom->at("pre#paste")B= $dom->at("pre.paste")C= $dom->at("body > pre")D= $dom->at('body > div > pre')
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | $self->{paste} = $tmp->text; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | $self->template->[1] = 'paste.html.ep'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | # centos paste | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 4 | $tmp = $dom->at('textarea#code'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 4 | ▶ | if ($tmp and !@{$tmp->children}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$tmp and not @{$tmp->children;}
MC/DC0%0/2
$tmp and not @{$tmp->children;}
$tmp
not @{$tmp->children;}
Truth table33%1/3
A and not(B)
A= $tmpB= not @{$tmp->children;}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | $self->{paste} = $tmp->text; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | $self->template->[1] = 'paste.html.ep'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 4 | ▶ | $tmp = $dom->at('.author-pic > a > img') || $dom->at('link[rel="apple-touch-icon"]') || $dom->at('[rel="icon"]'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%2/6
$dom->at('.author-pic > a > img') || $dom->at('link[rel="apple-touch-icon"]') || $dom->at('[rel="icon"]')
$dom->at(".author-pic > a > img") or $dom->at("link[rel=\"apple-touch-icon\"]")
MC/DC0%0/3
$dom->at('.author-pic > a > img') || $dom->at('link[rel="apple-touch-icon"]') || $dom->at('[rel="icon"]')
$dom->at(".author-pic > a > img")
$dom->at("link[rel=\"apple-touch-icon\"]")
$dom->at('[rel="icon"]')
Truth table25%1/4
A or B || C
A= $dom->at(".author-pic > a > img")B= $dom->at("link[rel=\"apple-touch-icon\"]")C= $dom->at('[rel="icon"]')
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 4 | ▶ | if (!$self->thumbnail_url and $tmp and $tmp->{src} ||= $tmp->{href}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition22%2/9
not $self->thumbnail_url and $tmp and $tmp->{"src"} ||= $tmp->{"href"}
not $self->thumbnail_url and $tmp
$tmp->{"src"} ||= $tmp->{"href"}
MC/DC0%0/4
not $self->thumbnail_url and $tmp and $tmp->{"src"} ||= $tmp->{"href"}
not $self->thumbnail_url
$tmp
$tmp->{"src"}
$tmp->{"href"}
Truth table0%0/5
not(A) and B and C ||= D
A= not $self->thumbnail_urlB= $tmpC= $tmp->{"src"}D= $tmp->{"href"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | $self->thumbnail_url(Mojo::URL->new($tmp->{src})->to_abs(Mojo::URL->new($self->url))->to_string); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 4 | $tmp = $dom->at('p.about'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 4 | ▶ | if (!$self->description and $tmp) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $self->description and $tmp
MC/DC0%0/2
not $self->description and $tmp
not $self->description
$tmp
Truth table33%1/3
not(A) and B
A= not $self->descriptionB= $tmp
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | $tmp = $tmp->all_text; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | $tmp =~ s!\s+! !g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | $self->description(trim $tmp); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 4 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | sub _learn_from_json_schema { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | my ($self, $json) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_learn_from_json_schema: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | eval { $json = Mojo::JSON::from_json($json) } unless ref $json eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | return unless ref $json eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | my $author = ref $json->{author} eq 'ARRAY' ? $json->{author}[0] : $json->{author}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | ▶ | $self->author_name($author->{name}) if ref $author eq 'HASH' and $author->{name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $author eq "HASH" and $author->{"name"}
MC/DC0%0/2
ref $author eq "HASH" and $author->{"name"}
ref $author eq "HASH"
$author->{"name"}
Truth table0%0/3
A and B
A= ref $author eq "HASH"B= $author->{"name"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | $self->description($json->{description}) if $json->{description}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | $self->title($json->{headline}) if $json->{headline}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||