Conformance/Check.pm

filter: Statementstmt 44.0% 22 / 50 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 37.5% 6 / 16 Podpod 100% 8 / 8 totaltotal 40.4% 36 / 89 CC 8 SCAR 16.7
CC
8
Cov
35%
from_config
12.0
write_template
12.0
schema
6.0
CRAP 5.3
« Conformance/Check/Workflows.pm ↑ Summary Conformance/Check/ToolConfiguration.pm »
1 package Dist::Conformance::Check 0.005;
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 12 ▶use Dist::Conformance::Schema();
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14  
15 12 has 'name';
16 0 ▶has config => sub { {} };
Subroutine __ANON__: not called CC=1 SCAR=1.2
17 12 has 'source';
18 0 ▶has variables => sub { {} };
Subroutine __ANON__: not called CC=1 SCAR=1.2
19  
20 12 our $MODULE = { type => 'string', pattern => '\A[A-Za-z_]\w*(?:::\w+)*\z' };
21  
22  
23 0 ▶sub config_schema ($) { return { properties => {} } }
Subroutine config_schema: not called CC=1 SCAR=6.9
Pod documented
24  
25  
26 0 ▶sub schema ($class) {
Subroutine schema: not called CC=2 SCAR=17.9
Pod documented
27 0 my $own = $class->config_schema;
28 return {
29 type => 'object',
30 additionalProperties => 0,
31 required => $own->{required} // [],
32 properties => {
33 module => $MODULE,
34 level => { type => 'string', enum => [qw{fail info}], default => 'fail' },
35 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
36 },
37 };
38 }
39  
40  
41 0 ▶sub from_config ( $class, %arguments ) {
Subroutine from_config: not called CC=3 SCAR=24.8
Pod documented
42 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
43 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
44 0 return $class->new( %arguments, config => $config );
45 }
46  
47  
48 0 ▶sub check ( $self, $ ) { die( ref($self) . " does not implement check\n" ) }
Subroutine check: not called CC=1 SCAR=6.9
Pod documented
49  
50  
51 0 ▶sub update ( $self, $update ) {
Subroutine update: not called CC=2 SCAR=17.9
Pod documented
52 0 my ( $status, $detail ) = $self->check( $update->snapshot );
53 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
54 0 return;
55 }
56  
57  
58 0 ▶sub template ( $self, $path ) {
Subroutine template: not called CC=2 SCAR=17.9
Pod documented
59 0 my $text = $self->source->file($path);
60 0 my $variables = $self->variables;
61 0 ▶ $text =~ s/\{\{ ([[:upper:]][[:upper:][:digit:]_]*) \}\}/exists $variables->{$1} ? $variables->{$1} : "{{$1}}"/ge;
Branch: 1 branch
BranchTrueFalseTotal
exists $variables->{$1} ? : 0 0 0
62 0 my @unfilled = List::Util::uniq( sort $text =~ m/\{\{ ([[:upper:]][[:upper:][:digit:]_]*) \}\}/g );
63 0 return ( $text, @unfilled );
64 }
65  
66  
67 0 ▶sub write_template ( $self, $update, $path, $template, $mode = oct 644 ) {
Subroutine write_template: not called CC=3 SCAR=24.8
Pod documented
68 0 my ( $text, @unfilled ) = $self->template($template);
69 0 ▶ if (@unfilled) {
Branch: 1 branch
BranchTrueFalseTotal
if (@unfilled) 0 0 0
70 0 $update->by_hand( "Write $path from $template by hand, or set the variables " . join( ', ', @unfilled ) . ' in .conformance.yml: nothing sets them' );
71 0 return 0;
72 }
73 0 return $update->write( $path, $text, $mode );
74 }
75  
76  
77 0 ▶sub missing ( $, $snapshot, @paths ) {
Subroutine missing: not called CC=1 SCAR=6.9
Pod documented
78 0 my @missing = grep { !$snapshot->contains($_) } @paths;
79 0 return @missing;
80 }
81  
82 __END__
« Conformance/Check/Workflows.pm ↑ Summary Conformance/Check/ToolConfiguration.pm »