Conformance/Flavor.pm

filter: Statementstmt 32.5% 26 / 80 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 43.7% 7 / 16 Podpod 100% 5 / 5 totaltotal 30.6% 38 / 124 CC 16 SCAR 32.9
CC
16
Cov
25%
read_file
72.0
linearize
30.0
merge_checks
20.0
CRAP 26.9
« Conformance.pm ↑ Summary Conformance/Check/RefusedIniKeys.pm »
1 package Dist::Conformance::Flavor 0.008;
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 ▶no autovivification;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Mojo::Base -base, -signatures;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 ▶use List::Util();
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 2 ▶use Dist::Conformance::Schema();
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15  
16 2 has 'name';
17 2 has 'description';
18 0 ▶has checks => sub { {} };
Subroutine __ANON__: not called CC=1 SCAR=1.2
19 0 ▶has variables => sub { {} };
Subroutine __ANON__: not called CC=1 SCAR=1.2
20 0 ▶has lineage => sub { [] };
Subroutine __ANON__: not called CC=1 SCAR=1.2
21  
22 2 our %SCHEMA = (
23 type => 'object',
24 required => ['name'],
25 additionalProperties => 0,
26 properties => {
27 name => $Dist::Conformance::Schema::NAME,
28 description => { type => 'string' },
29 extends => { type => 'array', items => $Dist::Conformance::Schema::NAME, default => [] },
30 variables => { type => 'object', additionalProperties => { type => 'string' }, default => {} },
31 checks => { type => 'object', additionalProperties => { type => 'object', nullable => 1 }, default => {} },
32 },
33 );
34  
35  
36 0 ▶sub load ( $class, $source, $name ) {
Subroutine load: not called CC=2 SCAR=17.9
Pod documented
37 0 my @order = linearize( $source, $name );
38 0 my ( %checks, %variables );
39 0 for my $data (@order) {
40 0 %variables = ( %variables, %{ $data->{variables} } );
41 0 merge_checks( \%checks, $data->{checks} );
42 }
43 return $class->new(
44 name => $name,
45 description => $order[-1]{description},
46 checks => \%checks,
47 variables => \%variables,
48 0 lineage => [ map { $_->{name} } @order ],
49 );
50 }
51  
52  
53 0 ▶sub linearize ( $source, $name ) {
Subroutine linearize: not called CC=5 SCAR=34.0
Pod documented
54 0 my ( @order, %done );
55 0 my @path = ( { name => $name, data => read_file( $source, $name ), next => 0 } );
56 0 ▶ while (@path) {
Branch: 1 branch
BranchTrueFalseTotal
if (@path) 0 0 0
57 0 my $frame = $path[-1];
58 0 my $parent = $frame->{data}{extends}[ $frame->{next}++ ];
59 0 ▶ if ( !defined $parent ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $parent) 0 0 0
60 0 push @order, $frame->{data};
61 0 $done{ $frame->{name} } = 1;
62 0 pop @path;
63 0 next;
64 }
65 0 my @names = map { $_->{name} } @path;
66 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
BranchTrueFalseTotal
if &List::Util::any(sub { $_ eq $parent; } , @names) 0 0 0
67 0 ▶ next if $done{$parent};
Branch: 1 branch
BranchTrueFalseTotal
if $done{$parent} 0 0 0
68 0 push @path, { name => $parent, data => read_file( $source, $parent, $frame->{name} ), next => 0 };
69 }
70 0 return @order;
71 }
72  
73  
74 0 ▶sub check_names ($self) {
Subroutine check_names: not called CC=1 SCAR=6.9
Pod documented
75 0 my @names = sort keys %{ $self->checks };
76 0 return @names;
77 }
78  
79  
80 0 ▶sub merge_checks ( $checks, $over ) {
Subroutine merge_checks: not called CC=4 SCAR=30.0
Pod documented
81 0 for my $check ( sort keys %$over ) {
82 0 my $config = $over->{$check};
83 0 ▶ if ( !defined $config ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $config) 0 0 0
84 0 delete $checks->{$check};
85 0 next;
86 }
87 0 ▶ my %merged = ( %{ $checks->{$check} // {} }, %$config );
Condition0%0/2
$$checks{$check} // {}
l!l
00
MC/DC0%0/1
$$checks{$check} // {}
$$checks{$check}
Truth table0%0/2
A
A= $$checks{$check}
Aresult
11
00
88 0 delete @merged{ grep { !defined $merged{$_} } keys %merged };
89 0 $checks->{$check} = \%merged;
90 }
91 0 return $checks;
92 }
93  
94  
95 0 ▶sub read_file ( $source, $name, $extended_by = undef ) {
Subroutine read_file: not called CC=8 SCAR=42.8
Pod documented
96 0 my $file = "conformance/$name.yml";
97 0 ▶ die "$name is not the name of a flavor\n" if !Dist::Conformance::Schema::matches( $Dist::Conformance::Schema::NAME, $name );
Branch: 1 branch
BranchTrueFalseTotal
unless Dist::Conformance::Schema::matches($Dist::Conformance::Schema::NAME, $name) 0 0 0
98 0 ▶ if ( !$source->exists_file($file) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($source->exists_file($file)) 0 0 0
99 0 ▶ my $by = defined $extended_by ? ", which conformance/$extended_by.yml extends" : q{};
Branch: 1 branch
BranchTrueFalseTotal
defined $extended_by ? : 0 0 0
100 0 die( "There is no flavor $name$by: the standards at " . $source->describe . " have no $file\n" );
101 }
102 0 my $data = Dist::Conformance::Schema::validate( Dist::Conformance::Schema::parse_yaml( $source->file($file), $file ), \%SCHEMA, $file );
103 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
BranchTrueFalseTotal
if $$data{"name"} ne $name 0 0 0
104 0 for my $check ( sort keys %{ $data->{checks} } ) {
105 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
BranchTrueFalseTotal
unless Dist::Conformance::Schema::matches($Dist::Conformance::Schema::NAME, $check) 0 0 0
106 }
107 0 return $data;
108 }
109  
110 __END__
« Conformance.pm ↑ Summary Conformance/Check/RefusedIniKeys.pm »