Conformance/Check.pm

filter: Statementstmt 46.3% 25 / 54 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 38.8% 7 / 18 Podpod 100% 9 / 9 totaltotal 42.7% 41 / 96 CC 8 SCAR 16.1
CC
8
Cov
38%
from_config
12.0
write_template
12.0
schema
6.0
CRAP 5.0
« Conformance/Check/Workflows.pm ↑ Summary Conformance/Check/ToolConfiguration.pm »
1 package Dist::Conformance::Check 0.007;
2  
3 # ABSTRACT: The interface of a check, and what the checks share
4  
5 12 ▶use 5.040;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 12 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 12 ▶use re '/aasx';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 12 ▶use Mojo::Base -base, -signatures;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 12 ▶use List::Util();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 12 ▶use Module::Runtime();
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 12 ▶use Dist::Conformance::Schema();
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15  
16 12 has 'name';
17 0 ▶has config => sub { {} };
Subroutine __ANON__: not called CC=1 SCAR=1.2
18 12 has 'source';
19 0 ▶has variables => sub { {} };
Subroutine __ANON__: not called CC=1 SCAR=1.2
20  
21 12 our $MODULE = { type => 'string', pattern => "\\A$Module::Runtime::module_name_rx\\z" };
22  
23  
24 0 ▶sub config_schema ($) { return { properties => {} } }
Subroutine config_schema: not called CC=1 SCAR=6.9
Pod documented
25  
26  
27 0 ▶sub schema ($class) {
Subroutine schema: not called CC=2 SCAR=17.9
Pod documented
28 0 my $own = $class->config_schema;
29 return {
30 type => 'object',
31 additionalProperties => 0,
32 required => $own->{required} // [],
33 properties => {
34 module => $MODULE,
35 level => { type => 'string', enum => [qw{fail info}], default => 'fail' },
36 0 ▶ %{ $own->{properties} },
Condition0%0/2
$own->{"required"} // []
l!l
00
MC/DC0%0/1
$own->{"required"} // []
$own->{"required"}
Truth table0%0/2
A
A= $own->{"required"}
Aresult
11
00
37 },
38 };
39 }
40  
41  
42 0 ▶sub from_config ( $class, %arguments ) {
Subroutine from_config: not called CC=3 SCAR=24.8
Pod documented
43 0 ▶ my $where = delete $arguments{where} // "the check $arguments{name}";
Condition0%0/2
delete $arguments{"where"} // qq[the check $arguments{"name"}]
l!l
00
MC/DC0%0/1
delete $arguments{"where"} // qq[the check $arguments{"name"}]
delete $arguments{"where"}
Truth table0%0/2
A
A= delete $arguments{"where"}
Aresult
11
00
44 0 ▶ my $config = Dist::Conformance::Schema::validate( $arguments{config} // {}, $class->schema, $where );
Condition0%0/2
$arguments{"config"} // {}
l!l
00
MC/DC0%0/1
$arguments{"config"} // {}
$arguments{"config"}
Truth table0%0/2
A
A= $arguments{"config"}
Aresult
11
00
45 0 return $class->new( %arguments, config => $config );
46 }
47  
48  
49 0 ▶sub check ( $self, $ ) { die( ref($self) . " does not implement check\n" ) }
Subroutine check: not called CC=1 SCAR=6.9
Pod documented
50  
51  
52 0 ▶sub update ( $self, $update ) {
Subroutine update: not called CC=2 SCAR=17.9
Pod documented
53 0 my ( $status, $detail ) = $self->check( $update->snapshot );
54 0 ▶ $update->by_hand( "$detail: " . $self->name . ' has no automatic fix' ) if $status eq 'fail';
Branch: 1 branch
BranchTrueFalseTotal
if $status eq "fail" 0 0 0
55 0 return;
56 }
57  
58  
59 0 ▶sub adopt ( $, $ ) { return }
Subroutine adopt: not called CC=1 SCAR=6.9
Pod documented
60  
61  
62 0 ▶sub template ( $self, $path ) {
Subroutine template: not called CC=2 SCAR=17.9
Pod documented
63 0 my $text = $self->source->file($path);
64 0 my $variables = $self->variables;
65 0 ▶ $text =~ s/\{\{ ([[:upper:]][[:upper:][:digit:]_]*) \}\}/exists $variables->{$1} ? $variables->{$1} : "{{$1}}"/ge;
Branch: 1 branch
BranchTrueFalseTotal
exists $variables->{$1} ? : 0 0 0
66 0 my @unfilled = List::Util::uniq( sort $text =~ m/\{\{ ([[:upper:]][[:upper:][:digit:]_]*) \}\}/g );
67 0 return ( $text, @unfilled );
68 }
69  
70  
71 0 ▶sub write_template ( $self, $update, $path, $template, $mode = oct 644 ) {
Subroutine write_template: not called CC=3 SCAR=24.8
Pod documented
72 0 my ( $text, @unfilled ) = $self->template($template);
73 0 ▶ if (@unfilled) {
Branch: 1 branch
BranchTrueFalseTotal
if (@unfilled) 0 0 0
74 0 $update->by_hand( "Write $path from $template by hand, or set the variables " . join( ', ', @unfilled ) . ' in .conformance.yml: nothing sets them' );
75 0 return 0;
76 }
77 0 return $update->write( $path, $text, $mode );
78 }
79  
80  
81 0 ▶sub missing ( $, $snapshot, @paths ) {
Subroutine missing: not called CC=1 SCAR=6.9
Pod documented
82 0 my @missing = grep { !$snapshot->contains($_) } @paths;
83 0 return @missing;
84 }
85  
86 __END__
« Conformance/Check/Workflows.pm ↑ Summary Conformance/Check/ToolConfiguration.pm »