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.011;
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 # The source that the C<source> key of the configuration describes, with
38 # L</standards>, L</cache> and L</offline> applied: a directory for
39 # L</standards> or for C<directory>, and else a git repository.
40 # @returns InstanceOf["Dist::Conformance::Source"] the new source
41 # @example my $source = $conformance->build_source;
42 0 ▶sub build_source ($self) {
Subroutine build_source: not called CC=8 SCAR=42.8
Pod documented
43 0 my $config = $self->config->{source};
44 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
45 0 ▶ if ( defined $self->standards ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->standards) 0 0 0
46 0 return Dist::Conformance::Source::Directory->new( directory => $self->standards, %path );
47 }
48 0 ▶ if ( defined $config->{git} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$config{"git"}) 0 0 0
49 0 my %options = ( url => $config->{git}, offline => $self->offline, %path );
50 0 ▶ $options{ref} = $config->{ref} if defined $config->{ref};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$config{"ref"} 0 0 0
51 0 ▶ $options{cache} = $self->cache if defined $self->cache;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->cache 0 0 0
52 0 return Dist::Conformance::Source::Git->new(%options);
53 }
54 0 my $directory = Mojo::File->new( $config->{directory} );
55 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
56 0 return Dist::Conformance::Source::Directory->new( directory => "$directory", %path );
57 }
58  
59 # The names of the checks that F<.conformance.yml> skips.
60 # @returns HashRef from the name of each skipped check to 1
61 # @throws when F<.conformance.yml> skips or configures a check that the flavor
62 # does not run, with a message that starts with C<.conformance.yml is not valid:>
63 # @example my $skipped = $conformance->skipped;
64 0 ▶sub skipped ($self) {
Subroutine skipped: not called CC=2 SCAR=17.9
Pod documented
65 0 my $config = $self->config;
66 0 my $flavor = $self->flavor;
67 0 my %runs = map { $_ => 1 } $flavor->check_names;
68 my @wrong = (
69 0 ( map { "/skip/$_" } grep { !$runs{ $config->{skip}[$_] } } 0 .. $#{ $config->{skip} } ),
70 0 ( map { "/checks/$_" } grep { !$runs{$_} } sort keys %{ $config->{checks} } ),
71 );
72 0 ▶ if (@wrong) {
Branch: 1 branch
BranchTrueFalseTotal
if (@wrong) 0 0 0
73 0 my $name = $flavor->name;
74 0 Dist::Conformance::Schema::refuse( $Dist::Conformance::Config::FILE, map { "$_: names a check that the flavor $name does not run" } @wrong );
75 }
76 0 return { map { $_ => 1 } @{ $config->{skip} } };
77 }
78  
79 # The L<Dist::Conformance::Check> objects that run, in order, with the
80 # configuration of the flavor and of F<.conformance.yml> merged and validated.
81 # Memoized.
82 # @returns ArrayRef[InstanceOf["Dist::Conformance::Check"]] the checks
83 # @throws on a check whose module does not load or is not a check, and on a
84 # configuration that its schema refuses; each message names the check and the
85 # flavor
86 # @example say $_->name for @{ $conformance->checks };
87 0 ▶sub checks ($self) {
Subroutine checks: not called CC=2 SCAR=17.9
Pod documented
88 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
89 0 my $flavor = $self->flavor;
90 0 my $skipped = $self->skipped;
91 0 my %merged = %{ $flavor->checks };
92 0 Dist::Conformance::Flavor::merge_checks( \%merged, $self->config->{checks} );
93 0 my %variables = ( %{ $flavor->variables }, %{ $self->config->{variables} } );
94 [
95 0 map { local ($_) = $_; $self->make_check( $_, $merged{$_}, \%variables ) }
96 0 grep { !$skipped->{$_} } $flavor->check_names
97 ];
98 };
99 }
100  
101 # The check C<$name> of the flavor, from its merged configuration.
102 # @param name Str the name of the check in the flavor
103 # @param config HashRef its merged configuration, with C<module> when the module is not
104 # the name
105 # @param variables HashRef the values of the placeholders of the templates
106 # @returns InstanceOf["Dist::Conformance::Check"] the check
107 # @throws when the module of the check is not the name of a module, does not
108 # load, or is not a L<Dist::Conformance::Check>, and when the schema of the check
109 # refuses the configuration
110 # @example my $check = $conformance->make_check( 'ClaudeMd', { file => 'CLAUDE.md', mentions => [] }, {} );
111 0 ▶sub make_check ( $self, $name, $config, $variables ) {
Subroutine make_check: not called CC=7 SCAR=40.3
Pod documented
112 0 my $flavor = $self->flavor->name;
113 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
114 0 ▶ my $class = index( $module, '::' ) >= 0 ? $module : "Dist::Conformance::Check::$module";
Branch: 1 branch
BranchTrueFalseTotal
index($module, '::') != -1 ? : 0 0 0
115 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
116 0 die "The flavor $flavor runs the check $name, but $class is not the name of a module\n";
117 }
118 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
119 0 die( "The flavor $flavor runs the check $name, but its module $class does not load: " . Dist::Conformance::Schema::first_line($@), "\n" );
120 }
121 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
122 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
123 0 return $class->from_config(
124 name => $name,
125 config => $config,
126 source => $self->source,
127 variables => $variables,
128 where => "the check $name of the flavor $flavor$repo",
129 );
130 }
131  
132 1 our %STATUSES = map { $_ => 1 } qw{pass fail info};
133  
134 # Runs every check of the flavor against the snapshot.
135 #
136 # A check that dies, or returns a status that is not one of the three, fails, and
137 # its detail says so. A failure of a check at C<level: info> is reported as
138 # C<info>.
139 # @returns ArrayRef of hash references, one for each check of the flavor, in the order of
140 # their names: C<check>, the name; C<status>, which is C<pass>, C<fail>, C<info>,
141 # or C<skip> for a check that F<.conformance.yml> skips; and C<detail>
142 # @throws when the checks cannot be made, as L</checks> says
143 # @example my $results = $conformance->check;
144 0 ▶sub check ($self) {
Subroutine check: not called CC=8 SCAR=42.8
Pod documented
145 0 my $snapshot = $self->snapshot;
146 0 my %run = map { local ($_) = $_; $_->name => $_ } @{ $self->checks };
147 0 my @results;
148 0 for my $name ( $self->flavor->check_names ) {
149 0 my $check = $run{$name};
150 0 ▶ if ( !$check ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($check) 0 0 0
151 0 push @results, { check => $name, status => 'skip', detail => "skipped by $Dist::Conformance::Config::FILE" };
152 0 next;
153 }
154 0 my ( $status, $detail ) = eval { $check->check($snapshot) };
155 0 ▶ if ( !defined $status ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $status) { } 0 0 0
elsif (not $Dist::Conformance::STATUSES{$status}) { } 0 0 0
156 0 ( $status, $detail ) = ( 'fail', 'the check died: ' . Dist::Conformance::Schema::first_line($@) );
157 }
158 elsif ( !$STATUSES{$status} ) {
159 0 ( $status, $detail ) = ( 'fail', "the check returned the status $status, which is not pass, fail or info" );
160 }
161 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
162 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
163 }
164 0 return \@results;
165 }
166  
167 # Runs the update of every check that is not skipped on the checkout, after
168 # fetching the standards when the source is git. A check whose update dies has
169 # the error in C<manual>, and the other checks still run.
170 # @param dry_run Bool optional: when true, writes nothing, and says what it would write
171 # @returns ArrayRef of hash references, one for each check that ran, in order: C<check>, the
172 # name; C<changes>, what it changed or would change, each with an C<action> and a
173 # C<path>; and C<manual>, what is left for a person
174 # @throws when the checks cannot be made, as L</checks> says
175 # @example my $results = $conformance->update( dry_run => 1 );
176 0 ▶sub update ( $self, %options ) {
Subroutine update: not called CC=4 SCAR=30.0
Pod documented
177 0 my @results;
178 0 for my $check ( @{ $self->checks } ) {
179 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
180 0 ▶ if ( !eval { $check->update($update); 1 } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { $check->update($update); 1 } }) 0 0 0
181 0 $update->by_hand( 'The update died: ' . Dist::Conformance::Schema::first_line($@) );
182 }
183 0 push @results, { check => $check->name, changes => $update->changes, manual => $update->manual };
184 }
185 0 return \@results;
186 }
187  
188 # Asks every check that is not skipped what configuration would accept the
189 # checkout as it is now, through L<Dist::Conformance::Check/adopt>.
190 # @returns HashRef from the name of each check that has an answer to the answer,
191 # which is what the check would take under C<checks> in F<.conformance.yml>
192 # @throws when the checks cannot be made, as L</checks> says, and when the adopt
193 # of a check dies
194 # @example my $adopted = $conformance->adopt;
195 0 ▶sub adopt ($self) {
Subroutine adopt: not called CC=3 SCAR=24.8
Pod documented
196 0 my $snapshot = $self->snapshot;
197 0 my %adopted;
198 0 for my $check ( @{ $self->checks } ) {
199 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
200 0 $adopted{ $check->name } = $answer;
201 }
202 0 return \%adopted;
203 }
204  
205  
206 0 ▶sub failed ($results) {
Subroutine failed: not called CC=1 SCAR=6.9
Pod documented
207 0 ▶ return List::Util::any { $_->{status} eq 'fail' } @$results;
Subroutine __ANON__: not called CC=1 SCAR=6.9
208 }
209  
210 __END__
« Conformance/Check/GitHooks.pm ↑ Summary Conformance/Flavor.pm »