LinkEmbedder/Link/Basic.pm

filter: Statementstmt 62.7% 32 / 51 Branchbran 30.0% 9 / 30 Conditioncond 27.2% 9 / 33 MC/DCmcdc 0.0% 0 / 17 Subroutinesub 83.3% 5 / 6 Podpod 100% 1 / 1 totaltotal 40.5% 56 / 138 CC 27 SCAR 40.0
CC
27
Cov
44%
_learn_from_json_schema
72.0
_learn_from_dom
67.4
learn_p
4.3
CRAP 54.5
↑ 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)\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
BranchTrueFalseTotal
$url =~ /$PHOTO_RE/u ? : 0 5 5
$url =~ /$VIDEO_RE/u ? : 0 5 5
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
BranchTrueFalseTotal
$type eq 'link' ? : 5 0 5
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
BranchTrueFalseTotal
if $tmp 0 4 4
28  
29 # Bitbucket hack
30 4 $tmp = $dom->at('div.codehilite');
31 4 ▶ if ($tmp) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tmp) 0 4 4
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
BranchTrueFalseTotal
if ($tmp = $dom->at("pre#paste") || $dom->at("pre.paste") || $dom->at("body > pre") || $dom->at("body > div > pre")) 0 4 4
Condition33%3/9
$dom->at('pre#paste') || $dom->at('pre.paste') || $dom->at('body > pre') || $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/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')
ABCDresult
1XXX1
01XX1
001X1
00011
00000
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
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
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"]')
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
50 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
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
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
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
BranchTrueFalseTotal
unless ref $json eq "HASH" 0 0 0
67 0 ▶ return unless ref $json eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $json eq "HASH" 0 0 0
68  
69 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
70 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
71 0 ▶ $self->description($json->{description}) if $json->{description};
Branch: 1 branch
BranchTrueFalseTotal
if $json->{"description"} 0 0 0
72 0 ▶ $self->title($json->{headline}) if $json->{headline};
Branch: 1 branch
BranchTrueFalseTotal
if $json->{"headline"} 0 0 0
73 }
74  
75 1 1;
↑ Summary LinkEmbedder/Link/Travis.pm »