| 1 | package Dist::Conformance::Flavor 0.004; | ||||||||||||
| 2 | |||||||||||||
| 3 | # ABSTRACT: A named set of checks and their configuration, read from a standards source | ||||||||||||
| 4 | |||||||||||||
| 5 | 2 | ▶ | use 5.040; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 2 | ▶ | use warnings FATAL => 'all'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 2 | ▶ | use re '/aasx'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 2 | ▶ | use Mojo::Base -base, -signatures; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | |||||||||||||
| 10 | 2 | ▶ | use List::Util(); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | |||||||||||||
| 12 | 2 | ▶ | use Dist::Conformance::Schema(); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 13 | |||||||||||||
| 14 | |||||||||||||
| 15 | 2 | has 'name'; | |||||||||||
| 16 | 2 | has 'description'; | |||||||||||
| 17 | 0 | ▶ | has checks => sub { {} }; | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||
| 18 | 0 | ▶ | has variables => sub { {} }; | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||
| 19 | 0 | ▶ | has lineage => sub { [] }; | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||
| 20 | |||||||||||||
| 21 | 2 | our %SCHEMA = ( | |||||||||||
| 22 | type => 'object', | ||||||||||||
| 23 | required => ['name'], | ||||||||||||
| 24 | additionalProperties => 0, | ||||||||||||
| 25 | properties => { | ||||||||||||
| 26 | name => $Dist::Conformance::Schema::NAME, | ||||||||||||
| 27 | description => { type => 'string' }, | ||||||||||||
| 28 | extends => { type => 'array', items => $Dist::Conformance::Schema::NAME, default => [] }, | ||||||||||||
| 29 | variables => { type => 'object', additionalProperties => { type => 'string' }, default => {} }, | ||||||||||||
| 30 | checks => { type => 'object', additionalProperties => { type => 'object', nullable => 1 }, default => {} }, | ||||||||||||
| 31 | }, | ||||||||||||
| 32 | ); | ||||||||||||
| 33 | |||||||||||||
| 34 | |||||||||||||
| 35 | 0 | ▶ | sub load ( $class, $source, $name ) { | ||||||||||
|
Subroutine
load: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 36 | 0 | my @order = linearize( $source, $name ); | |||||||||||
| 37 | 0 | my ( %checks, %variables ); | |||||||||||
| 38 | 0 | for my $data (@order) { | |||||||||||
| 39 | 0 | %variables = ( %variables, %{ $data->{variables} } ); | |||||||||||
| 40 | 0 | merge_checks( \%checks, $data->{checks} ); | |||||||||||
| 41 | } | ||||||||||||
| 42 | return $class->new( | ||||||||||||
| 43 | name => $name, | ||||||||||||
| 44 | description => $order[-1]{description}, | ||||||||||||
| 45 | checks => \%checks, | ||||||||||||
| 46 | variables => \%variables, | ||||||||||||
| 47 | 0 | lineage => [ map { $_->{name} } @order ], | |||||||||||
| 48 | ); | ||||||||||||
| 49 | } | ||||||||||||
| 50 | |||||||||||||
| 51 | |||||||||||||
| 52 | 0 | ▶ | sub linearize ( $source, $name ) { | ||||||||||
|
Subroutine
linearize: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||
| 53 | 0 | my ( @order, %done ); | |||||||||||
| 54 | 0 | my @path = ( { name => $name, data => read_file( $source, $name ), next => 0 } ); | |||||||||||
| 55 | 0 | ▶ | while (@path) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 56 | 0 | my $frame = $path[-1]; | |||||||||||
| 57 | 0 | my $parent = $frame->{data}{extends}[ $frame->{next}++ ]; | |||||||||||
| 58 | 0 | ▶ | if ( !defined $parent ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 59 | 0 | push @order, $frame->{data}; | |||||||||||
| 60 | 0 | $done{ $frame->{name} } = 1; | |||||||||||
| 61 | 0 | pop @path; | |||||||||||
| 62 | 0 | next; | |||||||||||
| 63 | } | ||||||||||||
| 64 | 0 | my @names = map { $_->{name} } @path; | |||||||||||
| 65 | 0 | ▶ | die 'The flavors extend each other in a cycle: ', join( ' -> ', @names, $parent ), "\n" if List::Util::any { $_ eq $parent } @names; | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
| |||||||||||||
| 66 | 0 | ▶ | next if $done{$parent}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 67 | 0 | push @path, { name => $parent, data => read_file( $source, $parent, $frame->{name} ), next => 0 }; | |||||||||||
| 68 | } | ||||||||||||
| 69 | 0 | return @order; | |||||||||||
| 70 | } | ||||||||||||
| 71 | |||||||||||||
| 72 | |||||||||||||
| 73 | 0 | ▶ | sub check_names ($self) { | ||||||||||
|
Subroutine
check_names: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 74 | 0 | my @names = sort keys %{ $self->checks }; | |||||||||||
| 75 | 0 | return @names; | |||||||||||
| 76 | } | ||||||||||||
| 77 | |||||||||||||
| 78 | |||||||||||||
| 79 | 0 | ▶ | sub merge_checks ( $checks, $over ) { | ||||||||||
|
Subroutine
merge_checks: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||
| 80 | 0 | for my $check ( sort keys %$over ) { | |||||||||||
| 81 | 0 | my $config = $over->{$check}; | |||||||||||
| 82 | 0 | ▶ | if ( !defined $config ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 83 | 0 | delete $checks->{$check}; | |||||||||||
| 84 | 0 | next; | |||||||||||
| 85 | } | ||||||||||||
| 86 | 0 | ▶ | my %merged = ( %{ $checks->{$check} // {} }, %$config ); | ||||||||||
|
Condition0%0/2
$checks->{$check} // {}
MC/DC0%0/1
$checks->{$check} // {}
$checks->{$check}
Truth table0%0/2
A
A= $checks->{$check}
| |||||||||||||
| 87 | 0 | delete @merged{ grep { !defined $merged{$_} } keys %merged }; | |||||||||||
| 88 | 0 | $checks->{$check} = \%merged; | |||||||||||
| 89 | } | ||||||||||||
| 90 | 0 | return $checks; | |||||||||||
| 91 | } | ||||||||||||
| 92 | |||||||||||||
| 93 | |||||||||||||
| 94 | 0 | ▶ | sub read_file ( $source, $name, $extended_by = undef ) { | ||||||||||
|
Subroutine
read_file: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||
| 95 | 0 | my $file = "conformance/$name.yml"; | |||||||||||
| 96 | 0 | ▶ | die "$name is not the name of a flavor\n" if !Dist::Conformance::Schema::matches( $Dist::Conformance::Schema::NAME, $name ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 97 | 0 | ▶ | if ( !$source->exists_file($file) ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 98 | 0 | ▶ | my $by = defined $extended_by ? ", which conformance/$extended_by.yml extends" : q{}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 99 | 0 | die( "There is no flavor $name$by: the standards at " . $source->describe . " have no $file\n" ); | |||||||||||
| 100 | } | ||||||||||||
| 101 | 0 | my $data = Dist::Conformance::Schema::validate( Dist::Conformance::Schema::parse_yaml( $source->file($file), $file ), \%SCHEMA, $file ); | |||||||||||
| 102 | 0 | ▶ | die "$file is not valid:\n /name: is $data->{name}, not $name, the name of the file\n" if $data->{name} ne $name; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 103 | 0 | for my $check ( sort keys %{ $data->{checks} } ) { | |||||||||||
| 104 | 0 | ▶ | die "$file is not valid:\n /checks/$check: is not the name of a check\n" if !Dist::Conformance::Schema::matches( $Dist::Conformance::Schema::NAME, $check ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 105 | } | ||||||||||||
| 106 | 0 | return $data; | |||||||||||
| 107 | } | ||||||||||||
| 108 | |||||||||||||
| 109 | __END__ | ||||||||||||