bin/seo-inspect

filter: Statementstmt 85.2% 52 / 61 Branchbran 65.0% 13 / 20 Conditioncond 35.0% 7 / 20 MC/DCmcdc 8.3% 1 / 12 Subroutinesub 100% 8 / 8 Podpod n/a totaltotal 66.9% 81 / 121 CC 1 SCAR 0.0
CC
1
Cov
71%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« lib/SEO/Inspector/Plugin/TitleCheck.pm ↑ Summary
1 #!/usr/bin/env perl
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use FindBin qw($Bin);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Getopt::Long qw(GetOptions);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use File::Slurp qw(read_file);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use JSON::MaybeXS;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use Term::ANSIColor;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 ▶use SEO::Inspector;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 # -------------------------------
15 # Command line options
16 # -------------------------------
17 2 my ($url, $file, $json, $no_colour);
18 2 ▶GetOptions(
Branch: 1 branch
BranchTrueFalseTotal
&GetOptions("url|u=s", \$url, "file|f=s", \$file, "json|j", \$json, "no-colour|n", \$no_colour, "no-color", \$no_colour) or die "Usage: $0 --url <URL> | --file <HTML file> [--json] [--no-colour]\n" 2 0 2
19 'url|u=s' => \$url,
20 'file|f=s' => \$file,
21 'json|j' => \$json,
22 'no-colour|n' => \$no_colour,
23 'no-color' => \$no_colour,
24 ) or die "Usage: $0 --url <URL> | --file <HTML file> [--json] [--no-colour]\n";
25  
26 2 ▶die 'Specify either --url or --file' unless $url || $file;
Branch: 1 branch
BranchTrueFalseTotal
unless $url or $file 0 2 2
Condition33%1/3
$url or $file
l!l&&r!l&&!r
020
MC/DC0%0/2
$url or $file
$url $file
Truth table33%1/3
A or B
A= $urlB= $file
ABresult
1X1
011
000
27  
28 # -------------------------------
29 # Create inspector object
30 # -------------------------------
31 2 my $inspector = SEO::Inspector->new(
32 url => $url,
33 plugin_dirs => [ "$Bin/lib/SEO/Inspector/Plugin" ]
34 );
35  
36 # -------------------------------
37 # Fetch HTML and run checks
38 # -------------------------------
39 2 my ($html, $plugin_results, $builtin_results);
40  
41 2 ▶if ($file) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file) { } 2 0 2
42 2 $html = read_file($file);
43 2 ▶ die 'File is empty' unless $html;
Branch: 1 branch
BranchTrueFalseTotal
unless $html 0 2 2
44  
45 2 $plugin_results = $inspector->check_html($html);
46 2 $builtin_results = $inspector->run_all($html);
47 } else {
48 0 my $all_results = $inspector->check_url($url);
49 0 $html = delete $all_results->{_html}; # remove internal HTML
50 0 $plugin_results = { map { $_ => $all_results->{$_} } grep { exists $inspector->{plugins}{$_} } keys %$all_results };
51 0 $builtin_results = { map { $_ => $all_results->{$_} } grep { !exists $inspector->{plugins}{$_} } keys %$all_results };
52 }
53  
54 # -------------------------------
55 # Merge results
56 # -------------------------------
57 2 my %results = (%$plugin_results, %$builtin_results);
58  
59 # -------------------------------
60 # Output results
61 # -------------------------------
62 2 ▶if ($json) {
Branch: 1 branch
BranchTrueFalseTotal
if ($json) { } 1 1 2
63 1 print JSON::MaybeXS::encode_json(\%results), "\n";
64 } else {
65 1 for my $key (sort keys %results) {
66 18 my $r = $results{$key};
67 18 ▶ next unless ref($r) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $r eq "HASH" 0 18 18
68  
69 18 ▶ if($no_colour) {
Branch: 1 branch
BranchTrueFalseTotal
if ($no_colour) { } 0 18 18
70 0 ▶ printf "[%s] %s: %s\n", $r->{status} // 'unknown', $r->{name} // $key, $r->{notes} // '';
Condition0%0/7
$r->{"status"} // "unknown"
l!l
00
$r->{"name"} // $key
l!l&&r!l&&!r
000
$r->{"notes"} // ""
l!l
00
MC/DC0%0/1
$r->{"status"} // "unknown"
$r->{"status"}
MC/DC0%0/2
$r->{"name"} // $key
$r->{"name"} $key
MC/DC0%0/1
$r->{"notes"} // ""
$r->{"notes"}
Truth table0%0/2
A
A= $r->{"status"}
Aresult
11
00
Truth table0%0/3
A // B
A= $r->{"name"}B= $key
ABresult
1X1
011
000
Truth table0%0/2
A
A= $r->{"notes"}
Aresult
11
00
71 } else {
72 18 ▶ my $status = $r->{status} // 'unknown';
Condition50%1/2
$r->{"status"} // "unknown"
l!l
180
MC/DC0%0/1
$r->{"status"} // "unknown"
$r->{"status"}
Truth table50%1/2
A
A= $r->{"status"}
Aresult
11
00
73 18 ▶ my $color =
Branch: 2 branches
BranchTrueFalseTotal
$status eq 'ok' ? : 8 10 18
$status eq 'error' ? : 0 10 10
74 $status eq 'ok' ? 'green' :
75 $status eq 'error' ? 'red' :
76 # $status eq 'warn' ? 'yellow' :
77 # $status eq 'unknown' ? 'yellow' :
78 'yellow'; # fallback for anything else
79  
80 18 print color('bold');
81 18 print color($color);
82 18 print "[$status] ";
83 18 print color('reset');
84 18 print color('bold');
85 18 ▶ printf "%s: %s\n", $r->{name} // $key, $r->{notes} // '';
Condition60%3/5
$r->{"name"} // $key
l!l&&r!l&&!r
1620
$r->{"notes"} // ""
l!l
180
MC/DC0%0/2
$r->{"name"} // $key
$r->{"name"} $key
MC/DC0%0/1
$r->{"notes"} // ""
$r->{"notes"}
Truth table66%2/3
A // B
A= $r->{"name"}B= $key
ABresult
1X1
011
000
Truth table50%1/2
A
A= $r->{"notes"}
Aresult
11
00
86 18 print color('reset');
87 }
88  
89 18 ▶ if ($r->{'resolution'} && length($r->{'resolution'})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r->{"resolution"} and length $r->{"resolution"}) 7 11 18
Condition66%2/3
$r->{"resolution"} and length $r->{"resolution"}
!ll&&!rl&&r
1107
MC/DC50%1/2
$r->{"resolution"} and length $r->{"resolution"}
$r->{"resolution"} length $r->{"resolution"}
Truth table66%2/3
A and B
A= $r->{"resolution"}B= length $r->{"resolution"}
ABresult
0X0
100
111
90 7 print "\t", $r->{'resolution'}, "\n";
91 }
92 }
93 }
« lib/SEO/Inspector/Plugin/TitleCheck.pm ↑ Summary