LinkEmbedder/Link/Basic.pm

filter: Statementstmt 62.2% 33 / 53 Branchbran 31.2% 10 / 32 Conditioncond 28.2% 11 / 39 MC/DCmcdc 0.0% 0 / 20 Subroutinesub 83.3% 5 / 6 Podpod 100% 1 / 1 totaltotal 39.7% 60 / 151 CC 30 SCAR 40.4
CC
30
Cov
44%
_learn_from_dom
75.9
_learn_from_json_schema
72.0
learn_p
8.1
CRAP 57.0
↑ Summary LinkEmbedder/Link/Travis.pm »
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|webp)\b!i;
8 1 my $VIDEO_RE = qr!\.(?:mpg|mpeg|mov|mp4|ogv|webm)\b!i;
9  
10 5 ▶sub learn_p {
Subroutine learn_p: called CC=6 SCAR=20.9
Pod documented
11 5 my $self = shift;
12 5 my $url = $self->url;
13 5 ▶ my $type = $url =~ $PHOTO_RE ? 'photo' : $url =~ $VIDEO_RE ? 'video' : 'link';
Branch: 2 branches
BranchTrueFalseTotal
$url =~ /$PHOTO_RE/u ? : 0 5 5
$url =~ /$VIDEO_RE/u ? : 0 5 5
14  
15 5 $self->type($type);
16  
17 5 ▶ if ($type eq 'video' and $url =~ m/\.([^.]+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "video" and $url =~ /\.([^.]+)$/u) 0 5 5
Condition33%1/3
$type eq "video" and $url =~ /\.([^.]+)$/u
!ll&&!rl&&r
500
MC/DC0%0/2
$type eq "video" and $url =~ /\.([^.]+)$/u
$type eq "video" $url =~ /\.([^.]+)$/u
Truth table33%1/3
A and B
A= $type eq "video"B= $url =~ /\.([^.]+)$/u
ABresult
0X0
100
111
18 0 $self->mimetype(lc "video/$1");
19 }
20  
21 5 ▶ return $type eq 'link' ? $self->SUPER::learn_p : Mojo::Promise->new->resolve($self->_learn_from_url);
Branch: 1 branch
BranchTrueFalseTotal
$type eq 'link' ? : 5 0 5
22 }
23  
24 4 ▶sub _learn_from_dom {
Subroutine _learn_from_dom: called CC=18 SCAR=43.3
25 4 my ($self, $dom) = @_;
26 4 my $tmp;
27  
28 4 $self->SUPER::_learn_from_dom($dom);
29  
30 4 $tmp = $dom->at('script[type="application/ld+json"]');
31 4 ▶ $self->_learn_from_json_schema($tmp->text) if $tmp;
Branch: 1 branch
BranchTrueFalseTotal
if $tmp 0 4 4
32  
33 # Bitbucket hack
34 4 $tmp = $dom->at('div.codehilite');
35 4 ▶ if ($tmp) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tmp) 0 4 4
36 0 $self->{paste} = $tmp->all_text;
37 0 $self->template->[1] = 'paste.html.ep';
38 }
39  
40 # Mojopaste, Perlbot and other pages with <pre> tags
41 4 ▶ if ($tmp = $dom->at('pre#paste') || $dom->at('pre.paste') || $dom->at('body > pre') || $dom->at('body > div > pre') || $dom->at('.code')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tmp = $dom->at("pre#paste") || $dom->at("pre.paste") || $dom->at("body > pre") || $dom->at("body > div > pre") || $dom->at(".code")) 0 4 4
Condition33%4/12
$dom->at('pre#paste') || $dom->at('pre.paste') || $dom->at('body > pre') || $dom->at('body > div > pre') || $dom->at('.code')
l!l&&r!l&&!r
004
$dom->at("pre#paste") or $dom->at("pre.paste") or $dom->at("body > pre") or $dom->at("body > div > pre")
l!l&&r!l&&!r
004
$dom->at("pre#paste") or $dom->at("pre.paste") or $dom->at("body > pre")
l!l&&r!l&&!r
004
$dom->at("pre#paste") or $dom->at("pre.paste")
l!l&&r!l&&!r
004
MC/DC0%0/5
$dom->at('pre#paste') || $dom->at('pre.paste') || $dom->at('body > pre') || $dom->at('body > div > pre') || $dom->at('.code')
$dom->at("pre#paste") $dom->at("pre.paste") $dom->at("body > pre") $dom->at("body > div > pre") $dom->at('.code')
Truth table16%1/6
A or B or C or D || E
A= $dom->at("pre#paste")B= $dom->at("pre.paste")C= $dom->at("body > pre")D= $dom->at("body > div > pre")E= $dom->at('.code')
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
42 0 $self->{paste} = $tmp->all_text;
43 0 $self->template->[1] = 'paste.html.ep';
44 }
45  
46 # centos paste
47 4 $tmp = $dom->at('textarea#code');
48 0 ▶ if ($tmp and !@{$tmp->children}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tmp and not @{$tmp->children;}) 0 4 4
Condition33%1/3
$tmp and not @{$tmp->children;}
!ll&&!rl&&r
400
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;}
ABresult
0X0
100
111
49 0 $self->{paste} = $tmp->text;
50 0 $self->template->[1] = 'paste.html.ep';
51 }
52  
53 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"]')
l!l&&r!l&&!r
004
$dom->at(".author-pic > a > img") or $dom->at("link[rel=\"apple-touch-icon\"]")
l!l&&r!l&&!r
004
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"]')
ABCresult
1XX1
01X1
0011
0000
54 4 ▶ if (!$self->thumbnail_url and $tmp and $tmp->{src} ||= $tmp->{href}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->thumbnail_url and $tmp and $tmp->{"src"} ||= $tmp->{"href"}) 0 4 4
Condition22%2/9
not $self->thumbnail_url and $tmp and $tmp->{"src"} ||= $tmp->{"href"}
!ll&&!rl&&r
400
not $self->thumbnail_url and $tmp
!ll&&!rl&&r
040
$tmp->{"src"} ||= $tmp->{"href"}
l!l&&r!l&&!r
000
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"}
ABCDresult
0XXX0
10XX0
11000
111X1
11011
55 0 $self->thumbnail_url(Mojo::URL->new($tmp->{src})->to_abs(Mojo::URL->new($self->url))->to_string);
56 }
57  
58 4 $tmp = $dom->at('p.about');
59 4 ▶ if (!$self->description and $tmp) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->description and $tmp) 0 4 4
Condition33%1/3
not $self->description and $tmp
!ll&&!rl&&r
040
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
ABresult
0X0
100
111
60 0 $tmp = $tmp->all_text;
61 0 $tmp =~ s!\s+! !g;
62 0 $self->description(trim $tmp);
63 }
64  
65 4 return $self;
66 }
67  
68 0 ▶sub _learn_from_json_schema {
Subroutine _learn_from_json_schema: not called CC=8 SCAR=42.8
69 0 my ($self, $json) = @_;
70 0 ▶ eval { $json = Mojo::JSON::from_json($json) } unless ref $json eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $json eq "HASH" 0 0 0
71 0 ▶ return unless ref $json eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $json eq "HASH" 0 0 0
72  
73 0 ▶ my $author = ref $json->{author} eq 'ARRAY' ? $json->{author}[0] : $json->{author};
Branch: 1 branch
BranchTrueFalseTotal
ref $json->{'author'} eq 'ARRAY' ? : 0 0 0
74 0 ▶ $self->author_name($author->{name}) if ref $author eq 'HASH' and $author->{name};
Branch: 1 branch
BranchTrueFalseTotal
if ref $author eq "HASH" and $author->{"name"} 0 0 0
Condition0%0/3
ref $author eq "HASH" and $author->{"name"}
!ll&&!rl&&r
000
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"}
ABresult
0X0
100
111
75 0 ▶ $self->description($json->{description}) if $json->{description};
Branch: 1 branch
BranchTrueFalseTotal
if $json->{"description"} 0 0 0
76 0 ▶ $self->title($json->{headline}) if $json->{headline};
Branch: 1 branch
BranchTrueFalseTotal
if $json->{"headline"} 0 0 0
77 }
78  
79 1 1;
↑ Summary LinkEmbedder/Link/Travis.pm »