Conformance.pm

filter: Statementstmt 36.7% 57 / 155 Branchbran 0.0% 0 / 34 Conditioncond 0.0% 0 / 20 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 55.1% 16 / 29 Podpod 100% 8 / 8 totaltotal 31.4% 81 / 258 CC 29 SCAR 34.1
CC
29
Cov
27%
build_source
72.0
check
72.0
make_check
56.0
CRAP 30.2
« Conformance/Check/GitHooks.pm ↑ Summary Conformance/Flavor.pm »
1 package Dist::Conformance 0.008;
2  
3 # ABSTRACT: Whether the development harness of a repository conforms to its standards, and bringing it up to date
4  
5 1 ▶use 5.040;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use re '/aasx';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶no autovivification;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Mojo::Base -base, -signatures;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶use List::Util();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Module::Runtime();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Mojo::File();
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 ▶use Dist::Conformance::Check();
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use Dist::Conformance::Config();
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use Dist::Conformance::Flavor();
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use Dist::Conformance::Schema();
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use Dist::Conformance::Snapshot::Directory();
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use Dist::Conformance::Source::Directory();
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use Dist::Conformance::Source::Git();
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use Dist::Conformance::Update();
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24  
25 1 has 'root';
26 0 ▶has snapshot => sub ($self) {
Subroutine __ANON__: not called CC=2 SCAR=17.9
27 0 ▶ die "Dist::Conformance needs a root or a snapshot\n" if !defined $self->root;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->root 0 0 0
28 0 return Dist::Conformance::Snapshot::Directory->new( root => $self->root );
29 1 };
30 0 ▶has config => sub ($self) { Dist::Conformance::Config::load( $self->snapshot ) };
Subroutine __ANON__: not called CC=1 SCAR=1.2
31 1 has 'cache';
32 1 has offline => 0;
33 1 has 'standards';
34 0 ▶has source => sub ($self) { $self->build_source };
Subroutine __ANON__: not called CC=1 SCAR=1.2
35 0 ▶has flavor => sub ($self) { Dist::Conformance::Flavor->load( $self->source, $self->config->{flavor} ) };
Subroutine __ANON__: not called CC=1 SCAR=1.2
36  
37  
38 0 ▶sub build_source ($self) {
Subroutine build_source: not called CC=8 SCAR=42.8
Pod documented
39 0 my $config = $self->config->{source};
40 0 ▶ my %path = ( path => $config->{path} // q{} );
Condition0%0/2
$$config{"path"} // ""
l!l
00
MC/DC0%0/1
$$config{"path"} // ""
$$config{"path"}
Truth table0%0/2
A
A= $$config{"path"}
Aresult
11
00
41 0 ▶ if ( defined $self->standards ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->standards) 0 0 0
42 0 return Dist::Conformance::Source::Directory->new( directory => $self->standards, %path );
43 }
44 0 ▶ if ( defined $config->{git} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$config{"git"}) 0 0 0
45 0 my %options = ( url => $config->{git}, offline => $self->offline, %path );
46 0 ▶ $options{ref} = $config->{ref} if defined $config->{ref};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$config{"ref"} 0 0 0
47 0 ▶ $options{cache} = $self->cache if defined $self->cache;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->cache 0 0 0
48 0 return Dist::Conformance::Source::Git->new(%options);
49 }
50 0 my $directory = Mojo::File->new( $config->{directory} );
51 0 ▶ $directory = Mojo::File->new( $self->root )->child( $config->{directory} ) if !$directory->is_abs && defined $self->root;
Branch: 1 branch
BranchTrueFalseTotal
if not $directory->is_abs and defined $self->root 0 0 0
Condition0%0/3
not $directory->is_abs and defined $self->root
!ll&&!rl&&r
000
MC/DC0%0/2
not $directory->is_abs and defined $self->root
not $directory->is_abs defined $self->root
Truth table0%0/3
not(A) and B
A= not $directory->is_absB= defined $self->root
ABresult
0X0
100
111
52 0 return Dist::Conformance::Source::Directory->new( directory => "$directory", %path );
53 }
54  
55  
56 0 ▶sub skipped ($self) {
Subroutine skipped: not called CC=2 SCAR=17.9
Pod documented
57 0 my $config = $self->config;
58 0 my $flavor = $self->flavor;
59 0 my %runs = map { $_ => 1 } $flavor->check_names;
60 my @wrong = (
61 0 ( map { "/skip/$_" } grep { !$runs{ $config->{skip}[$_] } } 0 .. $#{ $config->{skip} } ),
62 0 ( map { "/checks/$_" } grep { !$runs{$_} } sort keys %{ $config->{checks} } ),
63 );
64 0 ▶ if (@wrong) {
Branch: 1 branch
BranchTrueFalseTotal
if (@wrong) 0 0 0
65 0 my $name = $flavor->name;
66 0 Dist::Conformance::Schema::refuse( $Dist::Conformance::Config::FILE, map { "$_: names a check that the flavor $name does not run" } @wrong );
67 }
68 0 return { map { $_ => 1 } @{ $config->{skip} } };
69 }
70  
71  
72 0 ▶sub checks ($self) {
Subroutine checks: not called CC=2 SCAR=17.9
Pod documented
73 0 ▶ return $self->{checks} //= do {
Condition0%0/3
$$self{"checks"} //= do { my $flavor = $self->flavor; my $skipped = $self->skipped; my(%merged) = %{$flavor->checks;}; Dist::Conformance::Flavor::merge_checks(\%merged, $self->config->{"checks"}); my(%variables) = (%{$flavor->variables;}, %{$self->config->{"variables"};}); [map({local($_) = $_; $self->make_check($_, $merged{$_}, \%variables);} grep({not $$skipped{$_};} $flavor->check_names))] }
l!l&&r!l&&!r
000
MC/DC0%0/2
$$self{"checks"} //= do { my $flavor = $self->flavor; my $skipped = $self->skipped; my(%merged) = %{$flavor->checks;}; Dist::Conformance::Flavor::merge_checks(\%merged, $self->config->{"checks"}); my(%variables) = (%{$flavor->variables;}, %{$self->config->{"variables"};}); [map({local($_) = $_; $self->make_check($_, $merged{$_}, \%variables);} grep({not $$skipped{$_};} $flavor->check_names))] }
$$self{"checks"} do { my $flavor = $self->flavor; my $skipped = $self->skipped; my(%merged) = %{$flavor->checks;}; Dist::Conformance::Flavor::merge_checks(\%merged, $self->config->{"checks"}); my(%variables) = (%{$flavor->variables;}, %{$self->config->{"variables"};}); [map({local($_) = $_; $self->make_check($_, $merged{$_}, \%variables);} grep({not $$skipped{$_};} $flavor->check_names))] }
Truth table0%0/3
A //= B
A= $$self{"checks"}B= do { my $flavor = $self->flavor; my $skipped = $self->skipped; my(%merged) = %{$flavor->checks;}; Dist::Conformance::Flavor::merge_checks(\%merged, $self->config->{"checks"}); my(%variables) = (%{$flavor->variables;}, %{$self->config->{"variables"};}); [map({local($_) = $_; $self->make_check($_, $merged{$_}, \%variables);} grep({not $$skipped{$_};} $flavor->check_names))] }
ABresult
1X1
011
000
74 0 my $flavor = $self->flavor;
75 0 my $skipped = $self->skipped;
76 0 my %merged = %{ $flavor->checks };
77 0 Dist::Conformance::Flavor::merge_checks( \%merged, $self->config->{checks} );
78 0 my %variables = ( %{ $flavor->variables }, %{ $self->config->{variables} } );
79 [
80 0 map { local ($_) = $_; $self->make_check( $_, $merged{$_}, \%variables ) }
81 0 grep { !$skipped->{$_} } $flavor->check_names
82 ];
83 };
84 }
85  
86  
87 0 ▶sub make_check ( $self, $name, $config, $variables ) {
Subroutine make_check: not called CC=7 SCAR=40.3
Pod documented
88 0 my $flavor = $self->flavor->name;
89 0 ▶ my $module = $config->{module} // $name;
Condition0%0/3
$$config{"module"} // $name
l!l&&r!l&&!r
000
MC/DC0%0/2
$$config{"module"} // $name
$$config{"module"} $name
Truth table0%0/3
A // B
A= $$config{"module"}B= $name
ABresult
1X1
011
000
90 0 ▶ my $class = index( $module, '::' ) >= 0 ? $module : "Dist::Conformance::Check::$module";
Branch: 1 branch
BranchTrueFalseTotal
index($module, '::') != -1 ? : 0 0 0
91 0 ▶ if ( !Dist::Conformance::Schema::matches( $Dist::Conformance::Check::MODULE, $class ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (Dist::Conformance::Schema::matches($Dist::Conformance::Check::MODULE, $class)) 0 0 0
92 0 die "The flavor $flavor runs the check $name, but $class is not the name of a module\n";
93 }
94 0 ▶ if ( !eval { Module::Runtime::require_module($class); 1 } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { &Module::Runtime::require_module($class); 1 } }) 0 0 0
95 0 die( "The flavor $flavor runs the check $name, but its module $class does not load: " . Dist::Conformance::Schema::first_line($@), "\n" );
96 }
97 0 ▶ die "The flavor $flavor runs the check $name, but $class is not a Dist::Conformance::Check\n" if !$class->isa('Dist::Conformance::Check');
Branch: 1 branch
BranchTrueFalseTotal
unless $class->isa("Dist::Conformance::Check") 0 0 0
98 0 ▶ my $repo = exists $self->config->{checks}{$name} ? " with $Dist::Conformance::Config::FILE" : q{};
Branch: 1 branch
BranchTrueFalseTotal
exists $self->config->{'checks'}{$name} ? : 0 0 0
99 0 return $class->from_config(
100 name => $name,
101 config => $config,
102 source => $self->source,
103 variables => $variables,
104 where => "the check $name of the flavor $flavor$repo",
105 );
106 }
107  
108 1 our %STATUSES = map { $_ => 1 } qw{pass fail info};
109  
110  
111 0 ▶sub check ($self) {
Subroutine check: not called CC=8 SCAR=42.8
Pod documented
112 0 my $snapshot = $self->snapshot;
113 0 my %run = map { local ($_) = $_; $_->name => $_ } @{ $self->checks };
114 0 my @results;
115 0 for my $name ( $self->flavor->check_names ) {
116 0 my $check = $run{$name};
117 0 ▶ if ( !$check ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($check) 0 0 0
118 0 push @results, { check => $name, status => 'skip', detail => "skipped by $Dist::Conformance::Config::FILE" };
119 0 next;
120 }
121 0 my ( $status, $detail ) = eval { $check->check($snapshot) };
122 0 ▶ if ( !defined $status ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $status) { } 0 0 0
elsif (not $Dist::Conformance::STATUSES{$status}) { } 0 0 0
123 0 ( $status, $detail ) = ( 'fail', 'the check died: ' . Dist::Conformance::Schema::first_line($@) );
124 }
125 elsif ( !$STATUSES{$status} ) {
126 0 ( $status, $detail ) = ( 'fail', "the check returned the status $status, which is not pass, fail or info" );
127 }
128 0 ▶ $status = 'info' if $status eq 'fail' && $check->config->{level} eq 'info';
Branch: 1 branch
BranchTrueFalseTotal
if $status eq "fail" and $check->config->{"level"} eq "info" 0 0 0
Condition0%0/3
$status eq "fail" and $check->config->{"level"} eq "info"
!ll&&!rl&&r
000
MC/DC0%0/2
$status eq "fail" and $check->config->{"level"} eq "info"
$status eq "fail" $check->config->{"level"} eq "info"
Truth table0%0/3
A and B
A= $status eq "fail"B= $check->config->{"level"} eq "info"
ABresult
0X0
100
111
129 0 ▶ push @results, { check => $name, status => $status, detail => $detail // q{} };
Condition0%0/2
$detail // ""
l!l
00
MC/DC0%0/1
$detail // ""
$detail
Truth table0%0/2
A
A= $detail
Aresult
11
00
130 }
131 0 return \@results;
132 }
133  
134  
135 0 ▶sub update ( $self, %options ) {
Subroutine update: not called CC=4 SCAR=30.0
Pod documented
136 0 my @results;
137 0 for my $check ( @{ $self->checks } ) {
138 0 ▶ my $update = Dist::Conformance::Update->new( snapshot => $self->snapshot, dry_run => $options{dry_run} // 0 );
Condition0%0/2
$options{"dry_run"} // 0
l!l
00
MC/DC0%0/1
$options{"dry_run"} // 0
$options{"dry_run"}
Truth table0%0/2
A
A= $options{"dry_run"}
Aresult
11
00
139 0 ▶ if ( !eval { $check->update($update); 1 } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { $check->update($update); 1 } }) 0 0 0
140 0 $update->by_hand( 'The update died: ' . Dist::Conformance::Schema::first_line($@) );
141 }
142 0 push @results, { check => $check->name, changes => $update->changes, manual => $update->manual };
143 }
144 0 return \@results;
145 }
146  
147  
148 0 ▶sub adopt ($self) {
Subroutine adopt: not called CC=3 SCAR=24.8
Pod documented
149 0 my $snapshot = $self->snapshot;
150 0 my %adopted;
151 0 for my $check ( @{ $self->checks } ) {
152 0 ▶ my $answer = $check->adopt($snapshot) // next;
Condition0%0/2
$check->adopt($snapshot) // (next)
l!l
00
MC/DC0%0/1
$check->adopt($snapshot) // (next)
$check->adopt($snapshot)
Truth table0%0/2
A
A= $check->adopt($snapshot)
Aresult
11
00
153 0 $adopted{ $check->name } = $answer;
154 }
155 0 return \%adopted;
156 }
157  
158  
159 0 ▶sub failed ($results) {
Subroutine failed: not called CC=1 SCAR=6.9
Pod documented
160 0 ▶ return List::Util::any { $_->{status} eq 'fail' } @$results;
Subroutine __ANON__: not called CC=1 SCAR=6.9
161 }
162  
163 __END__
« Conformance/Check/GitHooks.pm ↑ Summary Conformance/Flavor.pm »