Conformance/Check/SystemPackages.pm

filter: Statementstmt 23.5% 50 / 212 Branchbran 0.0% 0 / 70 Conditioncond 0.0% 0 / 46 MC/DCmcdc 0.0% 0 / 25 Subroutinesub 44.4% 12 / 27 Podpod 100% 7 / 7 totaltotal 17.8% 69 / 387 CC 65 SCAR 49.1
CC
65
Cov
15%
resolve
380.0
update
182.0
errors_of
132.0
CRAP 135.3
↑ Summary Conformance/Check/CriticProfile.pm »
1 package Dist::Conformance::Check::SystemPackages 0.008;
2  
3 # ABSTRACT: The system packages that a repository declares in metamerge.yml, validated, and resolved for a host
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 Lingua::EN::Inflect();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use List::Util();
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 ▶use Dist::Conformance::Schema();
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Dist::Conformance::Snapshot::Directory();
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17  
18 1 our $FILE = 'metamerge.yml';
19 1 our $PACKAGES = 'x_system_packages';
20 1 our $SOURCES = 'x_system_sources';
21 1 our $DEPENDENCY = '\A[A-Za-z0-9][A-Za-z0-9_.+:-]*\z';
22 1 our $SOURCE_NAME = '\A[a-z0-9][a-z0-9.-]*\z';
23  
24 # The name of a packager, as Provisioner::Packager->named takes it. test is not one.
25 1 our $PACKAGER = '\A(?!test\z)[a-z][a-z0-9]*\z';
26  
27 1 our %PACKAGE_NAME = ( deb => '\A[a-z0-9][a-z0-9+.-]*[a-z0-9+.]\z' );
28  
29 1 our $ANY_PACKAGE_NAME = '\A[A-Za-z0-9](?:[A-Za-z0-9+._-]*[A-Za-z0-9+._])?\z';
30  
31 # DISTRO or DISTRO/RELEASE, in the characters that os-release allows in ID and VERSION_ID.
32 1 our $HOST = '\A[a-z0-9._-]+(?:/[a-z0-9._-]+)?\z';
33  
34 3 ▶my sub list_of ($item) { return { type => 'array', minItems => 1, items => $item } }
Subroutine list_of: called CC=1 SCAR=0.0
35  
36 # The keywords of a mapping that must have a key other than $key, which refuse it with $message.
37 3 ▶my sub more_than ( $key, $message ) {
Subroutine more_than: called CC=1 SCAR=0.0
38 return (
39 3 minProperties => 1,
40 not => { required => [$key], maxProperties => 1 },
41 'x-errorMessage' => { minProperties => $message, not => $message },
42 );
43 }
44  
45 2 ▶my sub entry_of ($pattern) {
Subroutine entry_of: called CC=1 SCAR=0.0
46 2 my $name = { type => 'string', pattern => $pattern };
47 return {
48 2 anyOf => [
49 $name,
50 {
51 type => 'object',
52 more_than( source => 'names no package, as name or for a distro' ),
53 additionalProperties => 0,
54 properties => { name => $name, source => { type => 'string', pattern => $SOURCE_NAME } },
55 patternProperties => { '(?!(?:name|source)\z)' . $HOST => { %$name, nullable => 1 } },
56 },
57 ],
58 };
59 }
60  
61 1 my $URL_RX = qr{\Ahttps?://[^/\s]+\S*\z};
62 1 my $SUITE_RX = qr/\A(?:[^\s{}]|\{codename\})+\z/;
63 1 my $NONBLANK_RX = qr/\A\S+\z/;
64 1 my $ARCH_RX = qr/\A[[:lower:][:digit:]]+\z/;
65 1 my $FINGERPRINT_RX = qr/\A[[:xdigit:]]{40}\z/;
66 1 my $TEST_RX = qr/\A[^\n]*\S[^\n]*\z/;
67  
68 1 our $URL = { type => 'string', pattern => "$URL_RX" };
69  
70 1 our %SOURCE = (
71 deb => {
72 type => 'object',
73 required => [qw{name uri suites components key fingerprint}],
74 additionalProperties => 0,
75 properties => {
76 name => { type => 'string', pattern => $SOURCE_NAME },
77 uri => $URL,
78 key => $URL,
79 suites => list_of( { type => 'string', pattern => "$SUITE_RX" } ),
80 components => { type => 'array', items => { type => 'string', pattern => "$NONBLANK_RX" } },
81 architectures => { type => 'array', items => { type => 'string', pattern => "$ARCH_RX" } },
82 fingerprint => { type => 'string', pattern => "$FINGERPRINT_RX" },
83 distros => list_of( { type => 'string', pattern => $HOST } ),
84 pin => {
85 type => 'object',
86 required => ['priority'],
87 additionalProperties => 0,
88 properties => { priority => { type => 'integer' }, packages => { type => 'string', pattern => "$NONBLANK_RX" } },
89 },
90 },
91 },
92 );
93  
94 our $SCHEMA = {
95 type => 'object',
96 properties => {
97 $PACKAGES => {
98 type => 'object',
99 additionalProperties => 0,
100 patternProperties => {
101 $DEPENDENCY => {
102 type => 'object',
103 more_than( test => 'names no packager' ),
104 additionalProperties => 0,
105 properties => {
106 test => { type => 'string', pattern => "$TEST_RX" },
107 1 map { $_ => entry_of( $PACKAGE_NAME{$_} ) } keys %PACKAGE_NAME,
108 },
109 patternProperties => { '(?!(?:' . join( q{|}, sort keys %PACKAGE_NAME ) . ')\z)' . $PACKAGER => entry_of($ANY_PACKAGE_NAME) },
110 },
111 },
112 },
113 $SOURCES => {
114 type => 'object',
115 additionalProperties => 0,
116 1 properties => { map { $_ => list_of( $SOURCE{$_} ) } keys %SOURCE },
117 },
118 },
119 };
120  
121 # The mapping of metamerge.yml, or an empty one when there is none. Dies when the file does not parse.
122 0 ▶my sub document_of ($snapshot) {
Subroutine document_of: not called CC=2 SCAR=17.9
123 0 ▶ my $text = $snapshot->content($FILE) // return {};
Condition0%0/2
$snapshot->content($Dist::Conformance::Check::SystemPackages::FILE) // (return {})
l!l
00
MC/DC0%0/1
$snapshot->content($Dist::Conformance::Check::SystemPackages::FILE) // (return {})
$snapshot->content($Dist::Conformance::Check::SystemPackages::FILE)
Truth table0%0/2
A
A= $snapshot->content($Dist::Conformance::Check::SystemPackages::FILE)
Aresult
11
00
124 0 return Dist::Conformance::Schema::parse_yaml( $text, $FILE );
125 }
126  
127 0 ▶my sub declaration_of ($document) { return { packages => $document->{$PACKAGES} // {}, sources => $document->{$SOURCES} // {} } }
Subroutine declaration_of: not called CC=3 SCAR=24.8
Condition0%0/4
$$document{$Dist::Conformance::Check::SystemPackages::PACKAGES} // {}
l!l
00
$$document{$Dist::Conformance::Check::SystemPackages::SOURCES} // {}
l!l
00
MC/DC0%0/1
$$document{$Dist::Conformance::Check::SystemPackages::PACKAGES} // {}
$$document{$Dist::Conformance::Check::SystemPackages::PACKAGES}
MC/DC0%0/1
$$document{$Dist::Conformance::Check::SystemPackages::SOURCES} // {}
$$document{$Dist::Conformance::Check::SystemPackages::SOURCES}
Truth table0%0/2
A
A= $$document{$Dist::Conformance::Check::SystemPackages::PACKAGES}
Aresult
11
00
Truth table0%0/2
A
A= $$document{$Dist::Conformance::Check::SystemPackages::SOURCES}
Aresult
11
00
128  
129 # The errors of the schema, or else what it cannot say, because it compares one part of the document with
130 # another: that the sources and the entries that name them agree.
131 0 ▶my sub errors_of ($document) {
Subroutine errors_of: not called CC=11 SCAR=48.8
132 0 my @errors = Dist::Conformance::Schema::errors( $document, $SCHEMA );
133 0 ▶ return @errors if @errors;
Branch: 1 branch
BranchTrueFalseTotal
if @errors 0 0 0
134 0 my ( $packages, $sources ) = @{ declaration_of($document) }{qw{packages sources}};
135 0 my %named;
136 0 for my $dependency ( sort keys %$packages ) {
137 0 my @packagers = grep { $_ ne 'test' } sort keys %{ $packages->{$dependency} };
138 0 for my $packager ( grep { ref $packages->{$dependency}{$_} } @packagers ) {
139 0 my $entry = $packages->{$dependency}{$packager};
140 0 ▶ next if !defined $entry->{source};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$entry{"source"} 0 0 0
141 0 $named{$packager}{ $entry->{source} } = 1;
142 0 ▶ if ( List::Util::none { $_->{name} eq $entry->{source} } @{ $sources->{$packager} // [] } ) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if (&List::Util::none(sub { $our $_{"name"} eq $$entry{"source"}; } , @{$$sources{$packager} // [];})) 0 0 0
Condition0%0/2
$$sources{$packager} // []
l!l
00
MC/DC0%0/1
$$sources{$packager} // []
$$sources{$packager}
Truth table0%0/2
A
A= $$sources{$packager}
Aresult
11
00
143 0 push @errors, "/$PACKAGES/$dependency/$packager/source: $entry->{source} is not a source in $SOURCES/$packager";
144 }
145 }
146 }
147 0 for my $packager ( sort keys %$sources ) {
148 0 my %seen;
149 0 for my $index ( 0 .. $#{ $sources->{$packager} } ) {
150 0 my $source = $sources->{$packager}[$index];
151 0 ▶ push @errors, "/$SOURCES/$packager/$index/name: $source->{name} is the name of another source too" if $seen{ $source->{name} }++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen{$$source{"name"}}++ 0 0 0
152 0 ▶ push @errors, "/$SOURCES/$packager/$index: no dependency names $source->{name} as its source" if !$named{$packager}{ $source->{name} };
Branch: 1 branch
BranchTrueFalseTotal
unless $named{$packager}{$$source{"name"}} 0 0 0
153 }
154 }
155 0 return @errors;
156 }
157  
158  
159 0 ▶sub config_schema ($) { return { properties => { template => $Dist::Conformance::Schema::PATH } } }
Subroutine config_schema: not called CC=1 SCAR=6.9
Pod documented
160  
161  
162 0 ▶sub required ($self) {
Subroutine required: not called CC=4 SCAR=30.0
Pod documented
163 0 ▶ my $path = $self->config->{template} // return;
Condition0%0/2
$self->config->{"template"} // (return)
l!l
00
MC/DC0%0/1
$self->config->{"template"} // (return)
$self->config->{"template"}
Truth table0%0/2
A
A= $self->config->{"template"}
Aresult
11
00
164 0 my ( $text, @unfilled ) = $self->template($path);
165 0 ▶ die "$path needs the variables " . join( ', ', @unfilled ) . ", which nothing sets\n" if @unfilled;
Branch: 1 branch
BranchTrueFalseTotal
if @unfilled 0 0 0
166 0 my $document = Dist::Conformance::Schema::parse_yaml( $text, $path );
167 0 my @errors = errors_of($document);
168 0 ▶ Dist::Conformance::Schema::refuse( $path, @errors ) if @errors;
Branch: 1 branch
BranchTrueFalseTotal
if @errors 0 0 0
169 0 return $document;
170 }
171  
172 # The sorted names of the dependencies of the template $required that the valid $document does not declare.
173 0 ▶my sub missing_from ( $document, $required ) {
Subroutine missing_from: not called CC=4 SCAR=30.0
174 0 ▶ return if !$required;
Branch: 1 branch
BranchTrueFalseTotal
unless $required 0 0 0
175 0 ▶ my $declared = $document->{$PACKAGES} // {};
Condition0%0/2
$$document{$Dist::Conformance::Check::SystemPackages::PACKAGES} // {}
l!l
00
MC/DC0%0/1
$$document{$Dist::Conformance::Check::SystemPackages::PACKAGES} // {}
$$document{$Dist::Conformance::Check::SystemPackages::PACKAGES}
Truth table0%0/2
A
A= $$document{$Dist::Conformance::Check::SystemPackages::PACKAGES}
Aresult
11
00
176 0 ▶ my @missing = grep { !exists $declared->{$_} } sort keys %{ $required->{$PACKAGES} // {} };
Condition0%0/2
$$required{$Dist::Conformance::Check::SystemPackages::PACKAGES} // {}
l!l
00
MC/DC0%0/1
$$required{$Dist::Conformance::Check::SystemPackages::PACKAGES} // {}
$$required{$Dist::Conformance::Check::SystemPackages::PACKAGES}
Truth table0%0/2
A
A= $$required{$Dist::Conformance::Check::SystemPackages::PACKAGES}
Aresult
11
00
177 0 return @missing;
178 }
179  
180  
181 0 ▶sub declared ( $, $from ) {
Subroutine declared: not called CC=4 SCAR=30.0
Pod documented
182 0 ▶ my $snapshot = builtin::blessed($from) && $from->isa('Dist::Conformance::Snapshot') ? $from : Dist::Conformance::Snapshot::Directory->new( root => $from );
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($from) && $from->isa('Dist::Conformance::Snapshot') ? : 0 0 0
Condition0%0/3
builtin::blessed($from) and $from->isa("Dist::Conformance::Snapshot")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($from) and $from->isa("Dist::Conformance::Snapshot")
builtin::blessed($from) $from->isa("Dist::Conformance::Snapshot")
Truth table0%0/3
A and B
A= builtin::blessed($from)B= $from->isa("Dist::Conformance::Snapshot")
ABresult
0X0
100
111
183 0 my $document = document_of($snapshot);
184 0 my @errors = errors_of($document);
185 0 ▶ Dist::Conformance::Schema::refuse( $FILE, @errors ) if @errors;
Branch: 1 branch
BranchTrueFalseTotal
if @errors 0 0 0
186 0 return declaration_of($document);
187 }
188  
189  
190 0 ▶sub resolve ( $, $declared, %host ) {
Subroutine resolve: not called CC=19 SCAR=59.4
Pod documented
191 0 my ( $packager, $distro, $release, $codename ) = @host{qw{packager distro release codename}};
192 0 ▶ die "resolve needs a packager\n" if !defined $packager;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $packager 0 0 0
193 0 ▶ my @keys = ( ( defined $distro && defined $release ? "$distro/$release" : () ), ( defined $distro ? $distro : () ), 'name' );
Branch: 2 branches
BranchTrueFalseTotal
defined $distro && defined $release ? : 0 0 0
defined $distro ? : 0 0 0
Condition0%0/3
defined $distro and defined $release
!ll&&!rl&&r
000
MC/DC0%0/2
defined $distro and defined $release
defined $distro defined $release
Truth table0%0/3
A and B
A= defined $distroB= defined $release
ABresult
0X0
100
111
194 0 my %on_host = map { $_ => 1 } grep { $_ ne 'name' } @keys;
195 0 ▶ my %source = map { $_->{name} => $_ } @{ $declared->{sources}{$packager} // [] };
Condition0%0/2
$$declared{"sources"}{$packager} // []
l!l
00
MC/DC0%0/1
$$declared{"sources"}{$packager} // []
$$declared{"sources"}{$packager}
Truth table0%0/2
A
A= $$declared{"sources"}{$packager}
Aresult
11
00
196  
197 0 my ( @needs, @unresolved );
198 0 for my $name ( sort keys %{ $declared->{packages} } ) {
199 0 my $dependency = $declared->{packages}{$name};
200 0 my $entry = $dependency->{$packager};
201 0 my %need = ( name => $name, package => $entry, source => undef, test => $dependency->{test} );
202 0 ▶ if ( ref $entry ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $entry) 0 0 0
203 0 my ($key) = grep { exists $entry->{$_} } @keys;
204 0 ▶ $need{package} = defined $key ? $entry->{$key} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $key ? : 0 0 0
205 0 ▶ $need{source} = $entry->{source} if defined $need{package};
Branch: 1 branch
BranchTrueFalseTotal
if defined $need{"package"} 0 0 0
206 0 ▶ $entry = undef if !defined $key;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $key 0 0 0
207 }
208 0 ▶ my $source = defined $need{source} ? $source{ $need{source} } : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $need{'source'} ? : 0 0 0
209 0 ▶ if ( !defined $entry || ( $source && $source->{distros} && !List::Util::any( sub { $on_host{$_} }, @{ $source->{distros} } ) ) ) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $entry or $source and $$source{"distros"} and not &List::Util::any(sub { $on_host{$_}; } , @{$$source{"distros"};})) 0 0 0
Condition0%0/9
not defined $entry or $source and $$source{"distros"} and not &List::Util::any(sub { $on_host{$_}; } , @{$$source{"distros"};})
l!l&&r!l&&!r
000
$source and $$source{"distros"} and not &List::Util::any(sub { $on_host{$_}; } , @{$$source{"distros"};})
!ll&&!rl&&r
000
$source and $$source{"distros"}
!ll&&!rl&&r
000
MC/DC0%0/4
not defined $entry or $source and $$source{"distros"} and not &List::Util::any(sub { $on_host{$_}; } , @{$$source{"distros"};})
not defined $entry $source $$source{"distros"} not &List::Util::any(sub { $on_host{$_}; } , @{$$source{"distros"};})
Truth table0%0/5
not(A) or B and C and not(D)
A= not defined $entryB= $sourceC= $$source{"distros"}D= not &List::Util::any(sub { $on_host{$_}; } , @{$$source{"distros"};})
ABCDresult
1XXX1
01111
00XX0
010X0
01100
210 0 push @unresolved, $name;
211 0 next;
212 }
213 0 push @needs, \%need;
214 }
215  
216 0 my @sources;
217 0 for my $name ( List::Util::uniq( grep { defined } map { $_->{source} } @needs ) ) {
218 0 my %resolved = %{ $source{$name} };
219 0 delete $resolved{distros};
220 $resolved{suites} = [
221 map {
222 0 my $suite = $_;
223 0 ▶ die "The source $name needs the codename of the host, for the suite $suite\n" if index( $suite, '{codename}' ) >= 0 && !defined $codename;
Branch: 1 branch
BranchTrueFalseTotal
if index($suite, "{codename}") != -1 and not defined $codename 0 0 0
Condition0%0/3
index($suite, "{codename}") != -1 and not defined $codename
!ll&&!rl&&r
000
MC/DC0%0/2
index($suite, "{codename}") != -1 and not defined $codename
index($suite, "{codename}") != -1 not defined $codename
Truth table0%0/3
A and not(B)
A= index($suite, "{codename}") != -1B= not defined $codename
ABresult
0X0
100
111
224 0 $suite =~ s/\{codename\}/$codename/gr;
225 0 } @{ $resolved{suites} }
226 ];
227 0 push @sources, \%resolved;
228 }
229 return {
230 needs => \@needs,
231 0 packages => [ List::Util::uniq( grep { defined } map { $_->{package} } @needs ) ],
232 sources => \@sources,
233 0 programs => [ grep { defined } map { $_->{test} } @needs ],
234 unresolved => \@unresolved,
235 };
236 }
237  
238  
239 0 ▶sub os_release ($text) {
Subroutine os_release: not called CC=5 SCAR=34.0
Pod documented
240 0 my %variables;
241 0 for my $line ( split /\n/, $text ) {
242 0 ▶ my ( $name, $value ) = $line =~ m/\A\s*([[:alpha:]_]\w*)=(.*?)\s*\z/ or next;
Branch: 1 branch
BranchTrueFalseTotal
() = $line =~ /\A\s*([[:alpha:]_]\w*)=(.*?)\s*\z/aasx or next 0 0 0
243 0 my ($double) = $value =~ m/\A"((?:[^"\\]|\\.)*)"\z/;
244 0 my ($single) = $value =~ m/\A'([^']*)'\z/;
245 0 ▶ $variables{$name} = defined $double ? $double =~ s/\\(.)/$1/gr : $single // $value;
Branch: 1 branch
BranchTrueFalseTotal
defined $double ? : 0 0 0
Condition0%0/3
$single // $value
l!l&&r!l&&!r
000
MC/DC0%0/2
$single // $value
$single $value
Truth table0%0/3
A // B
A= $singleB= $value
ABresult
1X1
011
000
246 }
247 0 return \%variables;
248 }
249  
250  
251 0 ▶sub check ( $self, $snapshot ) {
Subroutine check: not called CC=9 SCAR=45.0
Pod documented
252 0 ▶ if ( !$snapshot->contains($FILE) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($snapshot->contains($Dist::Conformance::Check::SystemPackages::FILE)) 0 0 0
253 0 my @missing = missing_from( {}, scalar $self->required );
254 0 ▶ return ( 'fail', "there is no $FILE, to declare " . join ', ', @missing ) if @missing;
Branch: 1 branch
BranchTrueFalseTotal
if @missing 0 0 0
255 0 return ( 'pass', "there is no $FILE, so it needs no system packages" );
256 }
257 0 ▶ my $document = eval { document_of($snapshot) } // return ( 'fail', Dist::Conformance::Schema::first_line($@) );
Condition0%0/2
eval { do { document_of $snapshot } } // (return "fail", Dist::Conformance::Schema::first_line($@))
l!l
00
MC/DC0%0/1
eval { do { document_of $snapshot } } // (return "fail", Dist::Conformance::Schema::first_line($@))
eval { do { document_of $snapshot } }
Truth table0%0/2
A
A= eval { do { document_of $snapshot } }
Aresult
11
00
258 0 my @errors = errors_of($document);
259 0 ▶ return ( 'fail', "$FILE is not valid: " . join '; ', @errors ) if @errors;
Branch: 1 branch
BranchTrueFalseTotal
if @errors 0 0 0
260 0 my @missing = missing_from( $document, scalar $self->required );
261 0 ▶ return ( 'fail', "$FILE does not declare " . join ', ', @missing ) if @missing;
Branch: 1 branch
BranchTrueFalseTotal
if @missing 0 0 0
262 0 my $declaration = declaration_of($document);
263 0 my $sources = $declaration->{sources};
264 0 my @said = ( map { local ($_) = $_; Lingua::EN::Inflect::NO( "$_ source", scalar @{ $sources->{$_} } ) } sort keys %$sources );
265 0 ▶ unshift @said, Lingua::EN::Inflect::NO( 'dependency', scalar keys %{ $declaration->{packages} } ) if %{ $declaration->{packages} };
Branch: 1 branch
BranchTrueFalseTotal
if %{$$declaration{"packages"};} 0 0 0
266 0 ▶ return ( 'pass', "$FILE declares no system packages" ) if !@said;
Branch: 1 branch
BranchTrueFalseTotal
unless @said 0 0 0
267 0 my $last = pop @said;
268 0 ▶ return ( 'pass', "$FILE declares " . ( @said ? join( ', ', @said ) . " and $last" : $last ) );
Branch: 1 branch
BranchTrueFalseTotal
@said ? : 0 0 0
269 }
270  
271  
272 0 ▶sub update ( $self, $update ) {
Subroutine update: not called CC=13 SCAR=52.0
Pod documented
273 0 ▶ my $template = $self->config->{template} // return $self->SUPER::update($update);
Condition0%0/2
$self->config->{"template"} // (return $self->SUPER::update($update))
l!l
00
MC/DC0%0/1
$self->config->{"template"} // (return $self->SUPER::update($update))
$self->config->{"template"}
Truth table0%0/2
A
A= $self->config->{"template"}
Aresult
11
00
274 0 my $snapshot = $update->snapshot;
275 0 ▶ return $self->write_template( $update, $FILE, $template ) if !$snapshot->contains($FILE);
Branch: 1 branch
BranchTrueFalseTotal
unless $snapshot->contains($Dist::Conformance::Check::SystemPackages::FILE) 0 0 0
276 0 my $document = eval { document_of($snapshot) };
277 0 ▶ if ( !$document ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($document) 0 0 0
278 0 $update->by_hand( Dist::Conformance::Schema::first_line($@) . ': fix it by hand' );
279 0 return;
280 }
281 0 ▶ if ( my @errors = errors_of($document) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@errors) = errors_of($document)) 0 0 0
282 0 $update->by_hand( "$FILE is not valid: " . join( '; ', @errors ) . ': fix it by hand' );
283 0 return;
284 }
285 0 my $required = $self->required;
286 0 ▶ my @missing = missing_from( $document, $required ) or return;
Branch: 1 branch
BranchTrueFalseTotal
my(@missing) = missing_from($document, $required) or return 0 0 0
287 0 my @additions;
288 0 for my $name (@missing) {
289 0 my $dependency = $required->{$PACKAGES}{$name};
290 0 $document->{$PACKAGES}{$name} = $dependency;
291 0 push @additions, [ [$PACKAGES], { $name => $dependency } ];
292 0 ▶ for my $packager ( grep { ref $dependency->{$_} && defined $dependency->{$_}{source} } sort keys %$dependency ) {
Condition0%0/3
ref $$dependency{$_} && defined $$dependency{$_}{'source'}
!ll&&!rl&&r
000
MC/DC0%0/2
ref $$dependency{$_} && defined $$dependency{$_}{'source'}
ref $$dependency{$_} defined $$dependency{$_}{'source'}
Truth table0%0/3
A && B
A= ref $$dependency{$_}B= defined $$dependency{$_}{'source'}
ABresult
0X0
100
111
293 0 my $source_name = $dependency->{$packager}{source};
294 0 ▶ my $sources = $document->{$SOURCES}{$packager} //= [];
Condition0%0/2
$$document{$Dist::Conformance::Check::SystemPackages::SOURCES}{$packager} //= []
l!l
00
MC/DC0%0/1
$$document{$Dist::Conformance::Check::SystemPackages::SOURCES}{$packager} //= []
$$document{$Dist::Conformance::Check::SystemPackages::SOURCES}{$packager}
Truth table0%0/2
A
A= $$document{$Dist::Conformance::Check::SystemPackages::SOURCES}{$packager}
Aresult
11
00
295 0 ▶ next if List::Util::any { $_->{name} eq $source_name } @$sources;
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if &List::Util::any(sub { $our $_{"name"} eq $source_name; } , @$sources) 0 0 0
296 0 ▶ my $source = List::Util::first { $_->{name} eq $source_name } @{ $required->{$SOURCES}{$packager} };
Subroutine __ANON__: not called CC=1 SCAR=6.9
297 0 push @$sources, $source;
298 0 push @additions, [ [ $SOURCES, $packager ], [$source] ];
299 }
300 }
301 0 my $text = $snapshot->content($FILE);
302 0 my $same = eval {
303 0 for my $addition (@additions) { $text = Dist::Conformance::Schema::insert_yaml( $text, @$addition ) }
304 0 Dist::Conformance::Schema::encode_json( Dist::Conformance::Schema::parse_yaml( $text, $FILE ) ) eq Dist::Conformance::Schema::encode_json($document);
305 };
306 0 ▶ if ( !$same ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($same) 0 0 0
307 0 $update->by_hand( "Add " . join( ', ', @missing ) . " to $FILE by hand: its layout is not one that the update can edit" );
308 0 return;
309 }
310 0 $update->write( $FILE, $text );
311 0 return;
312 }
313  
314 __END__
↑ Summary Conformance/Check/CriticProfile.pm »