Conformance/Check/RefusedIniKeys.pm

filter: Statementstmt 32.7% 20 / 61 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 7 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 63.6% 7 / 11 Podpod 100% 4 / 4 totaltotal 30.1% 31 / 103 CC 13 SCAR 31.9
CC
13
Cov
24%
refused
56.0
check
20.0
update
20.0
CRAP 24.4
« Conformance/Flavor.pm ↑ Summary Conformance/Update.pm »
1 package Dist::Conformance::Check::RefusedIniKeys 0.008;
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 ▶no autovivification;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Mojo::Base 'Dist::Conformance::Check', -signatures;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶use Config::INI::Reader();
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 ▶use Dist::Conformance::Schema();
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15  
16 0 ▶sub config_schema ($) {
Subroutine config_schema: not called CC=1 SCAR=6.9
Pod documented
17 return {
18 0 required => [qw{file refuse}],
19 properties => {
20 file => $Dist::Conformance::Schema::PATH,
21 refuse => {
22 type => 'object',
23 minProperties => 1,
24 additionalProperties => {
25 type => 'object',
26 minProperties => 1,
27 additionalProperties => { type => 'string', minLength => 1 },
28 },
29 },
30 missing => { %$Dist::Conformance::Schema::STATUS, default => 'info' },
31 },
32 };
33 }
34  
35  
36 0 ▶sub refused ( $self, $text ) {
Subroutine refused: not called CC=7 SCAR=40.3
Pod documented
37 0 my $config = $self->config;
38 0 Dist::Conformance::Schema::parse_ini( $text, $config->{file} );
39 0 my $reader = Config::INI::Reader->new;
40 0 my ( $keys, $section ) = ( $config->{refuse}{_}, '_' );
41 0 my @refused;
42 0 my @lines = split /^/, $text;
43 0 for my $index ( 0 .. $#lines ) {
44 0 my $line = $lines[$index];
45 0 $reader->preprocess_line( \$line );
46 0 ▶ next if $reader->can_ignore($line);
Branch: 1 branch
BranchTrueFalseTotal
if $reader->can_ignore($line) 0 0 0
47 0 ▶ if ( defined( my $header = $reader->parse_section_header($line) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $header = $reader->parse_section_header($line))) 0 0 0
48 0 my ($plugin) = $header =~ m{\A(.+?)(?:\s*/.*)?\z};
49 0 ( $keys, $section ) = ( $config->{refuse}{$plugin}, $header );
50 0 next;
51 }
52 0 ▶ next if !$keys;
Branch: 1 branch
BranchTrueFalseTotal
unless $keys 0 0 0
53 0 my ($key) = $reader->parse_value_assignment($line);
54 0 ▶ push @refused, { line => $index, section => $section, key => $key, reason => $keys->{$key} } if defined $key && exists $keys->{$key};
Branch: 1 branch
BranchTrueFalseTotal
if defined $key and exists $$keys{$key} 0 0 0
Condition0%0/3
defined $key and exists $$keys{$key}
!ll&&!rl&&r
000
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}
ABresult
0X0
100
111
55 }
56 0 return @refused;
57 }
58  
59  
60 0 ▶sub check ( $self, $snapshot ) {
Subroutine check: not called CC=4 SCAR=30.0
Pod documented
61 0 my $file = $self->config->{file};
62 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")
l!l
00
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)
Aresult
11
00
63 0 my @refused = eval { $self->refused($text) };
64 0 ▶ return ( 'fail', Dist::Conformance::Schema::first_line($@) ) if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
65 0 ▶ return ( 'pass', 'sets no key that the flavor refuses' ) if !@refused;
Branch: 1 branch
BranchTrueFalseTotal
unless @refused 0 0 0
66 0 return ( 'fail', "$file sets " . join '; ', map { "$_->{key} in [$_->{section}], which $_->{reason}" } @refused );
67 }
68  
69  
70 0 ▶sub update ( $self, $update ) {
Subroutine update: not called CC=4 SCAR=30.0
Pod documented
71 0 my $file = $self->config->{file};
72 0 ▶ my $text = $update->snapshot->content($file) // return;
Condition0%0/2
$update->snapshot->content($file) // (return)
l!l
00
MC/DC0%0/1
$update->snapshot->content($file) // (return)
$update->snapshot->content($file)
Truth table0%0/2
A
A= $update->snapshot->content($file)
Aresult
11
00
73 0 my @refused = eval { $self->refused($text) };
74 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
75 0 $update->by_hand( Dist::Conformance::Schema::first_line($@) . ': fix it by hand' );
76 0 return;
77 }
78 0 ▶ return if !@refused;
Branch: 1 branch
BranchTrueFalseTotal
unless @refused 0 0 0
79 0 my %remove = map { $_->{line} => 1 } @refused;
80 0 my @lines = split /^/, $text;
81 0 $update->write( $file, join q{}, @lines[ grep { !$remove{$_} } 0 .. $#lines ] );
82 0 return;
83 }
84  
85 __END__
« Conformance/Flavor.pm ↑ Summary Conformance/Update.pm »