| 1 | package Dist::Conformance::Check::RefusedIniKeys 0.005; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # ABSTRACT: An INI file, such as dist.ini, sets no key that the flavor refuses, and the update removes each one | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use 5.040; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use warnings FATAL => 'all'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use re '/aasx'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Mojo::Base 'Dist::Conformance::Check', -signatures; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Config::INI::Reader(); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Dist::Conformance::Schema(); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 0 | ▶ | sub config_schema ($) { | ||||||||||||||||||||||||||
|
Subroutine
config_schema: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 16 | return { | ||||||||||||||||||||||||||||
| 17 | 0 | required => [qw{file refuse}], | |||||||||||||||||||||||||||
| 18 | properties => { | ||||||||||||||||||||||||||||
| 19 | file => $Dist::Conformance::Schema::PATH, | ||||||||||||||||||||||||||||
| 20 | refuse => { | ||||||||||||||||||||||||||||
| 21 | type => 'object', | ||||||||||||||||||||||||||||
| 22 | minProperties => 1, | ||||||||||||||||||||||||||||
| 23 | additionalProperties => { | ||||||||||||||||||||||||||||
| 24 | type => 'object', | ||||||||||||||||||||||||||||
| 25 | minProperties => 1, | ||||||||||||||||||||||||||||
| 26 | additionalProperties => { type => 'string', minLength => 1 }, | ||||||||||||||||||||||||||||
| 27 | }, | ||||||||||||||||||||||||||||
| 28 | }, | ||||||||||||||||||||||||||||
| 29 | missing => { %$Dist::Conformance::Schema::STATUS, default => 'info' }, | ||||||||||||||||||||||||||||
| 30 | }, | ||||||||||||||||||||||||||||
| 31 | }; | ||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 0 | ▶ | sub refused ( $self, $text ) { | ||||||||||||||||||||||||||
|
Subroutine
refused: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 36 | 0 | my $config = $self->config; | |||||||||||||||||||||||||||
| 37 | 0 | Dist::Conformance::Schema::parse_ini( $text, $config->{file} ); | |||||||||||||||||||||||||||
| 38 | 0 | my $reader = Config::INI::Reader->new; | |||||||||||||||||||||||||||
| 39 | 0 | my ( $keys, $section ) = ( $config->{refuse}{_}, '_' ); | |||||||||||||||||||||||||||
| 40 | 0 | my @refused; | |||||||||||||||||||||||||||
| 41 | 0 | my @lines = split /^/, $text; | |||||||||||||||||||||||||||
| 42 | 0 | for my $index ( 0 .. $#lines ) { | |||||||||||||||||||||||||||
| 43 | 0 | my $line = $lines[$index]; | |||||||||||||||||||||||||||
| 44 | 0 | $reader->preprocess_line( \$line ); | |||||||||||||||||||||||||||
| 45 | 0 | ▶ | next if $reader->can_ignore($line); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 0 | ▶ | if ( defined( my $header = $reader->parse_section_header($line) ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 0 | my ($plugin) = $header =~ m{\A(.+?)(?:\s*/.*)?\z}; | |||||||||||||||||||||||||||
| 48 | 0 | ( $keys, $section ) = ( $config->{refuse}{$plugin}, $header ); | |||||||||||||||||||||||||||
| 49 | 0 | next; | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | 0 | ▶ | next if !$keys; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | 0 | my ($key) = $reader->parse_value_assignment($line); | |||||||||||||||||||||||||||
| 53 | 0 | ▶ | push @refused, { line => $index, section => $section, key => $key, reason => $keys->{$key} } if defined $key && exists $keys->{$key}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $key and exists $keys->{$key}
MC/DC0%0/2
defined $key and exists $keys->{$key}
defined $key
exists $keys->{$key}
Truth table0%0/3
A and B
A= defined $keyB= exists $keys->{$key}
| |||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | 0 | return @refused; | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 0 | ▶ | sub check ( $self, $snapshot ) { | ||||||||||||||||||||||||||
|
Subroutine
check: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 60 | 0 | my $file = $self->config->{file}; | |||||||||||||||||||||||||||
| 61 | 0 | ▶ | my $text = $snapshot->content($file) // return ( $self->config->{missing}, "there is no $file" ); | ||||||||||||||||||||||||||
|
Condition0%0/2
$snapshot->content($file) // (return $self->config->{"missing"}, "there is no $file")
MC/DC0%0/1
$snapshot->content($file) // (return $self->config->{"missing"}, "there is no $file")
$snapshot->content($file)
Truth table0%0/2
A
A= $snapshot->content($file)
| |||||||||||||||||||||||||||||
| 62 | 0 | my @refused = eval { $self->refused($text) }; | |||||||||||||||||||||||||||
| 63 | 0 | ▶ | return ( 'fail', Dist::Conformance::Schema::first_line($@) ) if $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | 0 | ▶ | return ( 'pass', 'sets no key that the flavor refuses' ) if !@refused; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | 0 | return ( 'fail', "$file sets " . join '; ', map { "$_->{key} in [$_->{section}], which $_->{reason}" } @refused ); | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 0 | ▶ | sub update ( $self, $update ) { | ||||||||||||||||||||||||||
|
Subroutine
update: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 70 | 0 | my $file = $self->config->{file}; | |||||||||||||||||||||||||||
| 71 | 0 | ▶ | my $text = $update->snapshot->content($file) // return; | ||||||||||||||||||||||||||
|
Condition0%0/2
$update->snapshot->content($file) // (return)
MC/DC0%0/1
$update->snapshot->content($file) // (return)
$update->snapshot->content($file)
Truth table0%0/2
A
A= $update->snapshot->content($file)
| |||||||||||||||||||||||||||||
| 72 | 0 | my @refused = eval { $self->refused($text) }; | |||||||||||||||||||||||||||
| 73 | 0 | ▶ | if ($@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | 0 | $update->by_hand( Dist::Conformance::Schema::first_line($@) . ': fix it by hand' ); | |||||||||||||||||||||||||||
| 75 | 0 | return; | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | 0 | ▶ | return if !@refused; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | 0 | my %remove = map { $_->{line} => 1 } @refused; | |||||||||||||||||||||||||||
| 79 | 0 | my @lines = split /^/, $text; | |||||||||||||||||||||||||||
| 80 | 0 | $update->write( $file, join q{}, @lines[ grep { !$remove{$_} } 0 .. $#lines ] ); | |||||||||||||||||||||||||||
| 81 | 0 | return; | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | __END__ | ||||||||||||||||||||||||||||