| 1 | package Dist::Conformance::Check::IniTemplate 0.011; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | # ABSTRACT: An INI file is its template, with the overrides of the repository | ||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use 5.040; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use warnings FATAL => 'all'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use re '/aasx'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 3 | ▶ | no autovivification; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use Mojo::Base 'Dist::Conformance::Check', -signatures; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use Config::INI::Reader(); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 3 | ▶ | use Dist::Conformance::Schema(); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 3 | our $SCALAR = { anyOf => [ { type => 'string', nullable => 1 }, { type => 'number' } ] }; | |||||||||||||||||||||||||||||||||||||||||
| 17 | 3 | our $VALUE = { anyOf => [ $SCALAR, { type => 'array', minItems => 1, items => { anyOf => [ { type => 'string' }, { type => 'number' } ] } } ] }; | |||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 0 | ▶ | sub config_schema ($) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
config_schema: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | return { | ||||||||||||||||||||||||||||||||||||||||||
| 21 | 0 | required => [qw{file template}], | |||||||||||||||||||||||||||||||||||||||||
| 22 | properties => { | ||||||||||||||||||||||||||||||||||||||||||
| 23 | file => $Dist::Conformance::Schema::PATH, | ||||||||||||||||||||||||||||||||||||||||||
| 24 | template => $Dist::Conformance::Schema::PATH, | ||||||||||||||||||||||||||||||||||||||||||
| 25 | overrides => { | ||||||||||||||||||||||||||||||||||||||||||
| 26 | type => 'object', | ||||||||||||||||||||||||||||||||||||||||||
| 27 | additionalProperties => { anyOf => [ { type => 'string', enum => ['off'] }, { type => 'object', additionalProperties => $VALUE } ] }, | ||||||||||||||||||||||||||||||||||||||||||
| 28 | default => {}, | ||||||||||||||||||||||||||||||||||||||||||
| 29 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 30 | positions => { type => 'object', additionalProperties => { type => 'string', minLength => 1, nullable => 1 }, default => {} }, | ||||||||||||||||||||||||||||||||||||||||||
| 31 | settings => { type => 'object', additionalProperties => $VALUE, default => {} }, | ||||||||||||||||||||||||||||||||||||||||||
| 32 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 33 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | 3 | my $READER = Config::INI::Reader->new; | |||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | # The text of the line C<$line> as Config::INI::Reader reads it: without its | ||||||||||||||||||||||||||||||||||||||||||
| 39 | # newline, and without a comment after C< ;>. Undef for a line that it | ||||||||||||||||||||||||||||||||||||||||||
| 40 | # ignores. | ||||||||||||||||||||||||||||||||||||||||||
| 41 | # @param line Str one line of the file | ||||||||||||||||||||||||||||||||||||||||||
| 42 | # @returns Str or undef | ||||||||||||||||||||||||||||||||||||||||||
| 43 | # @example my $text = readable("[Foo] ; why\n"); | ||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | sub readable ($line) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
readable: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | my $text = $line; | |||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | chomp $text; | |||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | $READER->preprocess_line( \$text ); | |||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | return $READER->can_ignore($text) ? undef : $text; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | # The header of the section that the line C<$line> starts, without its | ||||||||||||||||||||||||||||||||||||||||||
| 52 | # brackets, as the reader of the file reads it. A subclass for another reader | ||||||||||||||||||||||||||||||||||||||||||
| 53 | # overrides it. | ||||||||||||||||||||||||||||||||||||||||||
| 54 | # @param line Str one line of the file | ||||||||||||||||||||||||||||||||||||||||||
| 55 | # @returns Str the header, or undef when the line starts no section | ||||||||||||||||||||||||||||||||||||||||||
| 56 | # @example my $header = $check->line_header("[Git::Commit / Release_Commit]\n"); | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | sub line_header ( $, $line ) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
line_header: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | my $text = readable($line) // return; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
readable($line) // (return)
MC/DC0%0/1
readable($line) // (return)
readable($line)
Truth table0%0/2
A
A= readable($line)
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | return $READER->parse_section_header($text); | |||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | # The key and the value that the line C<$line> sets, as the reader of the file | ||||||||||||||||||||||||||||||||||||||||||
| 63 | # reads them. A subclass for another reader overrides it. | ||||||||||||||||||||||||||||||||||||||||||
| 64 | # @param line Str one line of the file | ||||||||||||||||||||||||||||||||||||||||||
| 65 | # @returns the key and the value, as a list, or an empty list for a line that sets none | ||||||||||||||||||||||||||||||||||||||||||
| 66 | # @example my ( $key, $value ) = $check->line_parameter("allow_dirty = Changes\n"); | ||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | sub line_parameter ( $, $line ) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
line_parameter: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | my $text = readable($line) // return; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
readable($line) // (return)
MC/DC0%0/1
readable($line) // (return)
readable($line)
Truth table0%0/2
A
A= readable($line)
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | return if defined $READER->parse_section_header($text); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | my ( $key, $value ) = $READER->parse_value_assignment($text); | |||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | return if !defined $key; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | return ( $key, $value ); | |||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | # Whether the header C<$header> turns its section off, and the name by which | ||||||||||||||||||||||||||||||||||||||||||
| 76 | # C<overrides> names the section. The base takes the header for the name, and | ||||||||||||||||||||||||||||||||||||||||||
| 77 | # no header turns anything off. | ||||||||||||||||||||||||||||||||||||||||||
| 78 | # @param header Str the header, without its brackets | ||||||||||||||||||||||||||||||||||||||||||
| 79 | # @returns a boolean and the name, as a list | ||||||||||||||||||||||||||||||||||||||||||
| 80 | # @example my ( $off, $name ) = $check->section_of('Git::Commit / Release_Commit'); | ||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | sub section_of ( $, $header ) { return ( 0, $header ) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
section_of: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | # The header line of a section that C<overrides> gives keys, where the template | ||||||||||||||||||||||||||||||||||||||||||
| 84 | # has the line C<$line> for it. The base keeps the line of the template. | ||||||||||||||||||||||||||||||||||||||||||
| 85 | # @param name Str the name of the section | ||||||||||||||||||||||||||||||||||||||||||
| 86 | # @param line Str the line of the template | ||||||||||||||||||||||||||||||||||||||||||
| 87 | # @returns Str the line | ||||||||||||||||||||||||||||||||||||||||||
| 88 | # @example my $line = $check->on_header( 'MetaJSON', "[MetaJSON]\n" ); | ||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | sub on_header ( $, $, $line ) { return $line } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
on_header: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | # The header line of a section that only C<overrides> has. | ||||||||||||||||||||||||||||||||||||||||||
| 92 | # @param name Str the name of the section | ||||||||||||||||||||||||||||||||||||||||||
| 93 | # @returns Str the line | ||||||||||||||||||||||||||||||||||||||||||
| 94 | # @example my $line = $check->new_header('MetaJSON'); | ||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | sub new_header ( $, $name ) { return "[$name]\n" } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new_header: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | # The lines that a section that C<overrides> turns off becomes, given the lines | ||||||||||||||||||||||||||||||||||||||||||
| 98 | # C<@body> that the template has after its header. The base leaves the section | ||||||||||||||||||||||||||||||||||||||||||
| 99 | # out. | ||||||||||||||||||||||||||||||||||||||||||
| 100 | # @param name Str the name of the section | ||||||||||||||||||||||||||||||||||||||||||
| 101 | # @param body ArrayRef[Str] the lines after its header, each with its newline | ||||||||||||||||||||||||||||||||||||||||||
| 102 | # @returns the lines, as a list | ||||||||||||||||||||||||||||||||||||||||||
| 103 | # @example my @lines = $check->off_lines( 'Leftovers', [] ); | ||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | sub off_lines ( $, $, $ ) { return } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
off_lines: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | # The character that starts a comment that the update writes. | ||||||||||||||||||||||||||||||||||||||||||
| 107 | # @returns Str the character | ||||||||||||||||||||||||||||||||||||||||||
| 108 | # @example my $comment = $check->comment; | ||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | sub comment ($) { return q{;} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
comment: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | ▶ | sub values_of ($value) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
values_of: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | ▶ | return if !defined $value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | ▶ | return ref $value eq 'ARRAY' ? @$value : ($value); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | ▶ | sub same ( $x, $y ) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
same: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | ▶ | my $text = sub ($keys) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | return join "\n", map { my $key = $_; join "\0", $key, values_of( $keys->{$key} ) } sort keys %$keys; | |||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | return $text->($x) eq $text->($y); | |||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | ▶ | sub overlay ( $from, $to ) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
overlay: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | ▶ | my %overlay = map { $_ => $to->{$_} } grep { local ($_) = $_; !exists $from->{$_} || !same( { k => $from->{$_} }, { k => $to->{$_} } ) } keys %$to; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
exists $$from{$_} && same({'k', $$from{$_}}, {'k', $$to{$_}})
MC/DC0%0/2
exists $$from{$_} && same({'k', $$from{$_}}, {'k', $$to{$_}})
exists $$from{$_}
same({'k', $$from{$_}}, {'k', $$to{$_}})
Truth table0%0/3
A && B
A= exists $$from{$_}B= same({'k', $$from{$_}}, {'k', $$to{$_}})
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | $overlay{$_} = undef for grep { !exists $to->{$_} } keys %$from; | |||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | return \%overlay; | |||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | ▶ | sub rewrite_lines ( $self, $lines, $overlay ) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rewrite_lines: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | my ( @out, %done, $after ); | |||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | my $indent = q{}; | |||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | for my $line (@$lines) { | |||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | my ($key) = $self->line_parameter($line); | |||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | my ($lead) = $line =~ m/\A(\h*)/; | |||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | ▶ | if ( defined $key && exists $overlay->{$key} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $key and exists $$overlay{$key}
MC/DC0%0/2
defined $key and exists $$overlay{$key}
defined $key
exists $$overlay{$key}
Truth table0%0/3
A and B
A= defined $keyB= exists $$overlay{$key}
| |||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | ▶ | next if $done{$key}++; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | my @values = values_of( $overlay->{$key} ); | |||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | ▶ | next if !@values; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | push @out, map { "$lead$key = $_\n" } @values; | |||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | ( $after, $indent ) = ( scalar @out, $lead ); | |||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | push @out, $line; | |||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | ▶ | ( $after, $indent ) = ( scalar @out, $lead ) if defined $key; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | my @new; | |||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | for my $key ( grep { !$done{$_} } sort keys %$overlay ) { | |||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | push @new, map { "$indent$key = $_\n" } values_of( $overlay->{$key} ); | |||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | ▶ | splice @out, $after // 0, 0, @new; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$after // 0
MC/DC0%0/1
$after // 0
$after
Truth table0%0/2
A
A= $after
| |||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | return @out; | |||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | ▶ | sub parse ( $self, $text, $where ) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | my $data = Dist::Conformance::Schema::parse_ini( $text, $where ); | |||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | my ( %sections, @order ); | |||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | for my $line ( split /^/, $text ) { | |||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | ▶ | my $header = $self->line_header($line) // next; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->line_header($line) // (next)
MC/DC0%0/1
$self->line_header($line) // (next)
$self->line_header($line)
Truth table0%0/2
A
A= $self->line_header($line)
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | my ( $off, $name ) = $self->section_of($header); | |||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | ▶ | push @order, $name if !$sections{$name}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | ▶ | $sections{$name} = { off => $off, parameters => $data->{$header} // {} }; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$$data{$header} // {}
MC/DC0%0/1
$$data{$header} // {}
$$data{$header}
Truth table0%0/2
A
A= $$data{$header}
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | ▶ | return { settings => $data->{_} // {}, sections => \%sections, order => \@order }; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$$data{"_"} // {}
MC/DC0%0/1
$$data{"_"} // {}
$$data{"_"}
Truth table0%0/2
A
A= $$data{"_"}
| |||||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||
| 171 | # The entries of C<overrides>, by the name of each section, as L<expected|/"expected($snapshot)"> | ||||||||||||||||||||||||||||||||||||||||||
| 172 | # applies them to the template, whose sections are C<$standard>. The base | ||||||||||||||||||||||||||||||||||||||||||
| 173 | # takes the names as they are. | ||||||||||||||||||||||||||||||||||||||||||
| 174 | # @param standard HashRef the template, as L<parse|/"parse($text, $where)"> returns it | ||||||||||||||||||||||||||||||||||||||||||
| 175 | # @returns HashRef from the name of each section to C<off> or its keys | ||||||||||||||||||||||||||||||||||||||||||
| 176 | # @example my $overrides = $check->resolved_overrides($standard); | ||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | ▶ | sub resolved_overrides ( $self, $ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
resolved_overrides: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | return { %{ $self->config->{overrides} } }; | |||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | ▶ | sub expected ( $self, @ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
expected: not called CC=22 SCAR=62.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | my $template = $self->config->{template}; | |||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | my ( $text, @unfilled ) = $self->template($template); | |||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | ▶ | die( "$template needs the variables " . join( ', ', @unfilled ) . " in .conformance.yml: nothing sets them\n" ) if @unfilled; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | my $standard = $self->parse( $text, $template ); | |||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | my $overrides = $self->resolved_overrides($standard); | |||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | ▶ | $text .= "\n" if $text =~ m/[^\n]\z/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | my @lines = split /^/, $text; | |||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | my ( @headers, @names ); | |||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | for my $index ( 0 .. $#lines ) { | |||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | ▶ | my $header = $self->line_header( $lines[$index] ) // next; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->line_header($lines[$index]) // (next)
MC/DC0%0/1
$self->line_header($lines[$index]) // (next)
$self->line_header($lines[$index])
Truth table0%0/2
A
A= $self->line_header($lines[$index])
| |||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | push @headers, $index; | |||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | push @names, ( $self->section_of($header) )[1]; | |||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | ▶ | my @bodies = ( [ 0, $headers[0] // scalar @lines ] ); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$headers[0] // scalar @lines
MC/DC0%0/1
$headers[0] // scalar @lines
$headers[0]
Truth table0%0/2
A
A= $headers[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | ▶ | push @bodies, map { [ $headers[$_] + 1, $headers[ $_ + 1 ] // scalar @lines ] } 0 .. $#headers; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$headers[$_ + 1] // scalar @lines
MC/DC0%0/1
$headers[$_ + 1] // scalar @lines
$headers[$_ + 1]
Truth table0%0/2
A
A= $headers[$_ + 1]
| |||||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | my %named = map { $_ => 1 } @names; | |||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | my ( %own, %after, @last ); | |||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | for my $name ( grep { !$named{$_} } sort keys %$overrides ) { | |||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | my $want = $overrides->{$name}; | |||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | ▶ | $own{$name} = [ ref $want ? ( $self->new_header($name), $self->rewrite_lines( [], $want ) ) : $self->off_lines( $name, [] ) ]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | ▶ | my $positions = $self->config->{positions} // {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->config->{"positions"} // {}
MC/DC0%0/1
$self->config->{"positions"} // {}
$self->config->{"positions"}
Truth table0%0/2
A
A= $self->config->{"positions"}
| |||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | for my $name ( sort keys %$positions ) { | |||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | my $anchor = $positions->{$name}; | |||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | ▶ | die "positions places the section $name, which the template has, and which stays where the template puts it\n" if $named{$name}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | ▶ | die "positions places the section $name, which the overrides do not name\n" if !$own{$name}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | ▶ | die "positions puts the section $name after $anchor, which neither the template nor the overrides name\n" if defined $anchor && !$named{$anchor} && !$own{$anchor}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
defined $anchor and not $named{$anchor} and not $own{$anchor}
defined $anchor and not $named{$anchor}
MC/DC0%0/3
defined $anchor and not $named{$anchor} and not $own{$anchor}
defined $anchor
not $named{$anchor}
not $own{$anchor}
Truth table0%0/4
A and not(B) and not(C)
A= defined $anchorB= not $named{$anchor}C= not $own{$anchor}
| |||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | ▶ | push @{ $after{ $anchor // q{} } }, $name; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$anchor // ""
MC/DC0%0/1
$anchor // ""
$anchor
Truth table0%0/2
A
A= $anchor
| |||||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | push @last, grep { !exists $positions->{$_} } sort keys %own; | |||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | my ( $settings, $introduction ) = $self->split_tail( [ @lines[ $bodies[0][0] .. $bodies[0][1] - 1 ] ] ); | |||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | my @out = ( $self->rewrite_lines( $settings, $self->config->{settings} ), placed_after( \%own, \%after, q{} ), @$introduction ); | |||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | for my $i ( 0 .. $#headers ) { | |||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | my $name = $names[$i]; | |||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | my ( $keys, $tail ) = $self->split_tail( [ @lines[ $bodies[ $i + 1 ][0] .. $bodies[ $i + 1 ][1] - 1 ] ] ); | |||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | my @body = @$keys; | |||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | my @tail = @$tail; | |||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | my $want = $overrides->{$name}; | |||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | my @section; | |||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | ▶ | if ( !defined $want ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | @section = ( $lines[ $headers[$i] ], @body ); | |||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||
| 229 | elsif ( $want eq 'off' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | @section = $self->off_lines( $name, \@body ); | |||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||
| 232 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | @section = ( $self->on_header( $name, $lines[ $headers[$i] ] ), $self->rewrite_lines( \@body, $want ) ); | |||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | push @out, @section, placed_after( \%own, \%after, $name ), @tail; | |||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | my @rest; | |||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | for my $name (@last) { | |||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | push @rest, @{ $own{$name} }, placed_after( \%own, \%after, $name ); | |||||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | ▶ | push @out, "\n" . $self->comment . " The overrides of .conformance.yml\n", @rest if @rest; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | return join q{}, @out; | |||||||||||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||
| 245 | # The lines of a section's body up to its last key, and the blank lines and | ||||||||||||||||||||||||||||||||||||||||||
| 246 | # comments after it, which introduce what comes next. They stay when the | ||||||||||||||||||||||||||||||||||||||||||
| 247 | # section goes, and a section placed after this one goes above them. | ||||||||||||||||||||||||||||||||||||||||||
| 248 | # @param lines ArrayRef[Str] the lines of the body | ||||||||||||||||||||||||||||||||||||||||||
| 249 | # @returns ArrayRef[Str] the lines up to the last key, then ArrayRef[Str] the rest | ||||||||||||||||||||||||||||||||||||||||||
| 250 | # @example my ( $keys, $tail ) = $check->split_tail( [ "a = 1\n", "\n", "; next\n" ] ); | ||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | ▶ | sub split_tail ( $self, $lines ) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
split_tail: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | my $end = scalar @$lines; | |||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | ▶ | $end-- while $end > 0 && !defined $self->line_parameter( $lines->[ $end - 1 ] ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$end > 0 and not defined $self->line_parameter($$lines[$end - 1])
MC/DC0%0/2
$end > 0 and not defined $self->line_parameter($$lines[$end - 1])
$end > 0
not defined $self->line_parameter($$lines[$end - 1])
Truth table0%0/3
A and not(B)
A= $end > 0B= not defined $self->line_parameter($$lines[$end - 1])
| |||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | return ( [ @{$lines}[ 0 .. $end - 1 ] ], [ @{$lines}[ $end .. $#$lines ] ] ); | |||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||
| 257 | # The lines of the sections that C<%after> puts after the section C<$anchor>, | ||||||||||||||||||||||||||||||||||||||||||
| 258 | # each after a blank line, and after each of them the sections that go after it. | ||||||||||||||||||||||||||||||||||||||||||
| 259 | # @param own HashRef from the name of each section that only the overrides have to its lines | ||||||||||||||||||||||||||||||||||||||||||
| 260 | # @param after HashRef from the name of a section to the names of those that go after it | ||||||||||||||||||||||||||||||||||||||||||
| 261 | # @param anchor Str the name of the section, or the empty string for the top of the file | ||||||||||||||||||||||||||||||||||||||||||
| 262 | # @returns the lines, as a list | ||||||||||||||||||||||||||||||||||||||||||
| 263 | # @example my @lines = placed_after( \%own, \%after, 'Git::Commit' ); | ||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | ▶ | sub placed_after ( $own, $after, $anchor ) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
placed_after: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | my ( @lines, %seen ); | |||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | ▶ | my @todo = @{ $after->{$anchor} // [] }; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$$after{$anchor} // []
MC/DC0%0/1
$$after{$anchor} // []
$$after{$anchor}
Truth table0%0/2
A
A= $$after{$anchor}
| |||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | ▶ | while ( defined( my $name = shift @todo ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | ▶ | next if $seen{$name}++; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | push @lines, "\n", @{ $own->{$name} }; | |||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | ▶ | unshift @todo, @{ $after->{$name} // [] }; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$$after{$name} // []
MC/DC0%0/1
$$after{$name} // []
$$after{$name}
Truth table0%0/2
A
A= $$after{$name}
| |||||||||||||||||||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | return @lines; | |||||||||||||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | ▶ | sub differences ( $, $have, $want ) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
differences: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | my ( $hs, $ws ) = ( $have->{sections}, $want->{sections} ); | |||||||||||||||||||||||||||||||||||||||||
| 278 | my @kinds = ( | ||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | [ 'lacks the section', grep { !exists $hs->{$_} } @{ $want->{order} } ], | |||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | [ 'has the section', grep { !exists $ws->{$_} } @{ $have->{order} } ], | |||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | ▶ | [ 'sets other keys in the section', grep { local ($_) = $_; exists $hs->{$_} && !same( $hs->{$_}{parameters}, $ws->{$_}{parameters} ) } @{ $want->{order} } ], | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
exists $$hs{$_} && !same($$hs{$_}{'parameters'}, $$ws{$_}{'parameters'})
MC/DC0%0/2
exists $$hs{$_} && !same($$hs{$_}{'parameters'}, $$ws{$_}{'parameters'})
exists $$hs{$_}
!same($$hs{$_}{'parameters'}, $$ws{$_}{'parameters'})
Truth table0%0/3
A && not(B)
A= exists $$hs{$_}B= !same($$hs{$_}{'parameters'}, $$ws{$_}{'parameters'})
| |||||||||||||||||||||||||||||||||||||||||||
| 282 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | my @differences; | |||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | for my $kind (@kinds) { | |||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | my ( $phrase, @names ) = @$kind; | |||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | ▶ | next if !@names; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | ▶ | my $text = ( @names > 1 ? $phrase =~ s/section\z/sections/r : $phrase ) . ' ' . join ', ', map { "[$_]" } @names; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | ▶ | $text .= ', which neither the template nor the overrides name' if $phrase eq 'has the section'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | push @differences, $text; | |||||||||||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | my @mine = grep { exists $ws->{$_} } @{ $have->{order} }; | |||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | my @standard = grep { exists $hs->{$_} } @{ $want->{order} }; | |||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | ▶ | push @differences, 'puts the sections in another order' if join( "\0", @mine ) ne join( "\0", @standard ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | ▶ | push @differences, 'sets other keys before the first section' if !same( $have->{settings}, $want->{settings} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | return @differences; | |||||||||||||||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||
| 298 | # How the text C<$text> of the file differs from the text C<$want> that it must | ||||||||||||||||||||||||||||||||||||||||||
| 299 | # be, as phrases for a person. | ||||||||||||||||||||||||||||||||||||||||||
| 300 | # @param text Str the text of the file | ||||||||||||||||||||||||||||||||||||||||||
| 301 | # @param want Str the text that it must be | ||||||||||||||||||||||||||||||||||||||||||
| 302 | # @returns the phrases, as a list | ||||||||||||||||||||||||||||||||||||||||||
| 303 | # @throws when either text does not parse, naming the file or the template | ||||||||||||||||||||||||||||||||||||||||||
| 304 | # @example my @differences = $check->compare( $text, $check->expected($snapshot) ); | ||||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | ▶ | sub compare ( $self, $text, $want ) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
compare: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | my ( $file, $template ) = @{ $self->config }{qw{file template}}; | |||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | return $self->differences( $self->parse( $text, $file ), $self->parse( $want, $template ) ); | |||||||||||||||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | ▶ | sub check ( $self, $snapshot ) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 311 | 0 | my ( $file, $template ) = @{ $self->config }{qw{file template}}; | |||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | ▶ | my $text = $snapshot->content($file) // return ( 'fail', "$file is missing" ); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$snapshot->content($file) // (return "fail", "$file is missing")
MC/DC0%0/1
$snapshot->content($file) // (return "fail", "$file is missing")
$snapshot->content($file)
Truth table0%0/2
A
A= $snapshot->content($file)
| |||||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | my $want = $self->expected($snapshot); | |||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | ▶ | return ( 'pass', "is $template with the overrides" ) if $text eq $want; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | my @differences = eval { $self->compare( $text, $want ) }; | |||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | ▶ | return ( 'fail', Dist::Conformance::Schema::first_line($@) . ', and conformance update replaces it' ) if $@; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | ▶ | return ( 'info', "differs from $template with the overrides only in comments and layout, which conformance update rewrites" ) if !@differences; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | return ( 'fail', join( '; ', @differences ) . ', which conformance update corrects' ); | |||||||||||||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | ▶ | sub update ( $self, $update ) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
update: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | my $want = eval { $self->expected( $update->snapshot ) }; | |||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | ▶ | return $update->by_hand( Dist::Conformance::Schema::first_line($@) . ': ' . $self->name . ' cannot write ' . $self->config->{file} ) if !defined $want; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 324 | 0 | $update->write( $self->config->{file}, $want ); | |||||||||||||||||||||||||||||||||||||||||
| 325 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | ▶ | sub adopt ( $self, $snapshot ) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
adopt: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | my ( $file, $template ) = @{ $self->config }{qw{file template}}; | |||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | ▶ | my $text = $snapshot->content($file) // return; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$snapshot->content($file) // (return)
MC/DC0%0/1
$snapshot->content($file) // (return)
$snapshot->content($file)
Truth table0%0/2
A
A= $snapshot->content($file)
| |||||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | my ( $filled, @unfilled ) = $self->template($template); | |||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | ▶ | die( "$template needs the variables " . join( ', ', @unfilled ) . " in .conformance.yml: nothing sets them\n" ) if @unfilled; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | my $have = $self->parse( $text, $file ); | |||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | my $want = $self->parse( $filled, $template ); | |||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | my ( %overrides, %positions, $previous ); | |||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | for my $name ( @{ $have->{order} } ) { | |||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | my $mine = $have->{sections}{$name}{parameters}; | |||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | ▶ | if ( !exists $want->{sections}{$name} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 341 | 0 | $overrides{$name} = {%$mine}; | |||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | $positions{$name} = $previous; | |||||||||||||||||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||||||||||||||||
| 344 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 345 | 0 | my $changed = overlay( $want->{sections}{$name}{parameters}, $mine ); | |||||||||||||||||||||||||||||||||||||||||
| 346 | 0 | ▶ | $overrides{$name} = $changed if %$changed; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | $previous = $name; | |||||||||||||||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | my $settings = overlay( $want->{settings}, $have->{settings} ); | |||||||||||||||||||||||||||||||||||||||||
| 351 | 0 | ▶ | my %adopted = ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 352 | ( %overrides ? ( overrides => \%overrides ) : () ), | ||||||||||||||||||||||||||||||||||||||||||
| 353 | ( %positions ? ( positions => \%positions ) : () ), | ||||||||||||||||||||||||||||||||||||||||||
| 354 | ( %$settings ? ( settings => $settings ) : () ), | ||||||||||||||||||||||||||||||||||||||||||
| 355 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | ▶ | return %adopted ? \%adopted : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||||||
| 359 | __END__ | ||||||||||||||||||||||||||||||||||||||||||