| 1 | package Dist::Conformance::Check 0.008; | ||||||||||||
| 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 | my $MODULE_NAME_RX = $Module::Runtime::module_name_rx; | |||||||||||
| 22 | 12 | my $MODULE_RX = qr/\A$MODULE_NAME_RX\z/; | |||||||||||
| 23 | 12 | our $MODULE = { type => 'string', pattern => "$MODULE_RX" }; | |||||||||||
| 24 | |||||||||||||
| 25 | |||||||||||||
| 26 | 0 | ▶ | sub config_schema ($) { return { properties => {} } } | ||||||||||
|
Subroutine
config_schema: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 27 | |||||||||||||
| 28 | |||||||||||||
| 29 | 0 | ▶ | sub schema ($class) { | ||||||||||
|
Subroutine
schema: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 30 | 0 | my $own = $class->config_schema; | |||||||||||
| 31 | return { | ||||||||||||
| 32 | type => 'object', | ||||||||||||
| 33 | additionalProperties => 0, | ||||||||||||
| 34 | required => $own->{required} // [], | ||||||||||||
| 35 | properties => { | ||||||||||||
| 36 | module => $MODULE, | ||||||||||||
| 37 | level => { type => 'string', enum => [qw{fail info}], default => 'fail' }, | ||||||||||||
| 38 | 0 | ▶ | %{ $own->{properties} }, | ||||||||||
|
Condition0%0/2
$$own{"required"} // []
MC/DC0%0/1
$$own{"required"} // []
$$own{"required"}
Truth table0%0/2
A
A= $$own{"required"}
| |||||||||||||
| 39 | }, | ||||||||||||
| 40 | }; | ||||||||||||
| 41 | } | ||||||||||||
| 42 | |||||||||||||
| 43 | |||||||||||||
| 44 | 0 | ▶ | sub from_config ( $class, %arguments ) { | ||||||||||
|
Subroutine
from_config: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||
| 45 | 0 | ▶ | my $where = delete $arguments{where} // "the check $arguments{name}"; | ||||||||||
|
Condition0%0/2
delete $arguments{"where"} // qq[the check $arguments{"name"}]
MC/DC0%0/1
delete $arguments{"where"} // qq[the check $arguments{"name"}]
delete $arguments{"where"}
Truth table0%0/2
A
A= delete $arguments{"where"}
| |||||||||||||
| 46 | 0 | ▶ | my $config = Dist::Conformance::Schema::validate( $arguments{config} // {}, $class->schema, $where ); | ||||||||||
|
Condition0%0/2
$arguments{"config"} // {}
MC/DC0%0/1
$arguments{"config"} // {}
$arguments{"config"}
Truth table0%0/2
A
A= $arguments{"config"}
| |||||||||||||
| 47 | 0 | return $class->new( %arguments, config => $config ); | |||||||||||
| 48 | } | ||||||||||||
| 49 | |||||||||||||
| 50 | |||||||||||||
| 51 | 0 | ▶ | sub check ( $self, $ ) { die( ref($self) . " does not implement check\n" ) } | ||||||||||
|
Subroutine
check: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 52 | |||||||||||||
| 53 | |||||||||||||
| 54 | 0 | ▶ | sub update ( $self, $update ) { | ||||||||||
|
Subroutine
update: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 55 | 0 | my ( $status, $detail ) = $self->check( $update->snapshot ); | |||||||||||
| 56 | 0 | ▶ | $update->by_hand( "$detail: " . $self->name . ' has no automatic fix' ) if $status eq 'fail'; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 57 | 0 | return; | |||||||||||
| 58 | } | ||||||||||||
| 59 | |||||||||||||
| 60 | |||||||||||||
| 61 | 0 | ▶ | sub adopt ( $, $ ) { return } | ||||||||||
|
Subroutine
adopt: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 62 | |||||||||||||
| 63 | |||||||||||||
| 64 | 0 | ▶ | sub template ( $self, $path ) { | ||||||||||
|
Subroutine
template: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 65 | 0 | my $text = $self->source->file($path); | |||||||||||
| 66 | 0 | my $variables = $self->variables; | |||||||||||
| 67 | 0 | ▶ | $text =~ s/\{\{ ([[:upper:]][[:upper:][:digit:]_]*) \}\}/exists $variables->{$1} ? $variables->{$1} : "{{$1}}"/ge; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 68 | 0 | my @unfilled = List::Util::uniq( sort $text =~ m/\{\{ ([[:upper:]][[:upper:][:digit:]_]*) \}\}/g ); | |||||||||||
| 69 | 0 | return ( $text, @unfilled ); | |||||||||||
| 70 | } | ||||||||||||
| 71 | |||||||||||||
| 72 | |||||||||||||
| 73 | 0 | ▶ | sub write_template ( $self, $update, $path, $template, $mode = oct 644 ) { | ||||||||||
|
Subroutine
write_template: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||
| 74 | 0 | my ( $text, @unfilled ) = $self->template($template); | |||||||||||
| 75 | 0 | ▶ | if (@unfilled) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 76 | 0 | $update->by_hand( "Write $path from $template by hand, or set the variables " . join( ', ', @unfilled ) . ' in .conformance.yml: nothing sets them' ); | |||||||||||
| 77 | 0 | return 0; | |||||||||||
| 78 | } | ||||||||||||
| 79 | 0 | return $update->write( $path, $text, $mode ); | |||||||||||
| 80 | } | ||||||||||||
| 81 | |||||||||||||
| 82 | |||||||||||||
| 83 | 0 | ▶ | sub missing ( $, $snapshot, @paths ) { | ||||||||||
|
Subroutine
missing: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 84 | 0 | my @missing = grep { local ($_) = $_; !$snapshot->contains($_) } @paths; | |||||||||||
| 85 | 0 | return @missing; | |||||||||||
| 86 | } | ||||||||||||
| 87 | |||||||||||||
| 88 | __END__ | ||||||||||||