| 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
| |||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
$url or $file
MC/DC0%0/2
$url or $file
$url
$file
Truth table33%1/3
A or B
A= $urlB= $file
| |||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||
| 42 | 2 | $html = read_file($file); | |||||||||||||||||||||||||||||||||||||||
| 43 | 2 | ▶ | die 'File is empty' unless $html; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||
| 69 | 18 | ▶ | if($no_colour) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | ▶ | printf "[%s] %s: %s\n", $r->{status} // 'unknown', $r->{name} // $key, $r->{notes} // ''; | ||||||||||||||||||||||||||||||||||||||
|
Condition0%0/7
$r->{"status"} // "unknown"
$r->{"name"} // $key
$r->{"notes"} // ""
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"}
Truth table0%0/3
A // B
A= $r->{"name"}B= $key
Truth table0%0/2
A
A= $r->{"notes"}
| |||||||||||||||||||||||||||||||||||||||||
| 71 | } else { | ||||||||||||||||||||||||||||||||||||||||
| 72 | 18 | ▶ | my $status = $r->{status} // 'unknown'; | ||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$r->{"status"} // "unknown"
MC/DC0%0/1
$r->{"status"} // "unknown"
$r->{"status"}
Truth table50%1/2
A
A= $r->{"status"}
| |||||||||||||||||||||||||||||||||||||||||
| 73 | 18 | ▶ | my $color = | ||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||
| 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
$r->{"notes"} // ""
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
Truth table50%1/2
A
A= $r->{"notes"}
| |||||||||||||||||||||||||||||||||||||||||
| 86 | 18 | print color('reset'); | |||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||
| 89 | 18 | ▶ | if ($r->{'resolution'} && length($r->{'resolution'})) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$r->{"resolution"} and length $r->{"resolution"}
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"}
| |||||||||||||||||||||||||||||||||||||||||
| 90 | 7 | print "\t", $r->{'resolution'}, "\n"; | |||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||