CriticDB/Collector.pm

filter: Statementstmt 24.2% 17 / 70 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 10 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 45.4% 5 / 11 Podpod 0.0% 0 / 5 totaltotal 18.9% 22 / 116 CC 16 SCAR 30.0
CC
16
Cov
18%
collect
42.0
new
30.0
_critique
20.0
CRAP 20.1
↑ Summary CriticDB/DB.pm »
1 package App::CriticDB::Collector;
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 2 ▶use Carp qw/confess/;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Perl::Critic;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Perl::Critic::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 our $VERSION='0.0.6';
10  
11 0 ▶sub new {
Subroutine new: not called CC=5 SCAR=34.0
Pod undocumented
12 0 my ($ref,%opt)=@_;
13 0 ▶ my $class=ref($ref)||$ref;
Condition0%0/3
ref $ref || $ref
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $ref || $ref
ref $ref $ref
Truth table0%0/3
A || B
A= ref $refB= $ref
ABresult
1X1
011
000
14 0 my %self=map {$_=>$opt{$_}} qw/store flush newer profile debug/;
15 0 ▶ $self{profile}//='';
Condition0%0/2
$self{"profile"} //= ""
l!l
00
MC/DC0%0/1
$self{"profile"} //= ""
$self{"profile"}
Truth table0%0/2
A
A= $self{"profile"}
Aresult
11
00
16 0 ▶ $self{debug}//={};
Condition0%0/2
$self{"debug"} //= {}
l!l
00
MC/DC0%0/1
$self{"debug"} //= {}
$self{"debug"}
Truth table0%0/2
A
A= $self{"debug"}
Aresult
11
00
17 0 foreach my $k (grep {'CODE' ne ref($self{$_})} qw/store flush newer/) { delete($self{$k}) }
18 0 return bless(\%self,$class);
19 }
20  
21 0 ▶sub store {
Subroutine store: not called CC=2 SCAR=17.9
Pod undocumented
22 0 my ($self,$fn,@violations)=@_;
23 0 ▶ if(!$$self{store}) { return $self }
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"store"}) 0 0 0
24 0 &{$$self{store}}(file=>$fn,violations=>\@violations);
25 }
26  
27 0 ▶sub flush {
Subroutine flush: not called CC=2 SCAR=17.9
Pod undocumented
28 0 my ($self,$fn)=@_;
29 0 ▶ if(!$$self{flush}) { return $self }
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"flush"}) 0 0 0
30 0 &{$$self{flush}}($fn);
31 }
32  
33 0 ▶sub newer {
Subroutine newer: not called CC=2 SCAR=17.9
Pod undocumented
34 0 my ($self,$fn)=@_;
35 0 ▶ if(!$$self{newer}) { return 1 }
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"newer"}) 0 0 0
36 0 &{$$self{newer}}($fn);
37 }
38  
39 0 ▶sub _critique {
Subroutine _critique: not called CC=4 SCAR=30.0
40 0 my ($self,$fn)=@_;
41 0 my @violations;
42 0 ▶ if($$self{debug}{critique}) { print STDERR "Critique $fn\n" }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"debug"}{"critique"}) 0 0 0
43 0 eval { @violations=$$self{critic}->critique($fn) };
44 0 ▶ if($@) { return {error=>$@} }
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
45 0 foreach my $v (grep {'ARRAY' eq ref($$_{_explanation})} @violations) { $$v{_explanation}=[@{$$v{_explanation}}] } # unbless ReadOnly objects
46 0 return @violations;
47 }
48  
49 0 ▶sub collect {
Subroutine collect: not called CC=6 SCAR=37.4
Pod undocumented
50 0 my ($self,@paths)=@_;
51 0 ▶ $$self{critic}//=Perl::Critic->new(-profile=>$$self{profile},-severity=>1,-top=>1e6,-verbose=>1);
Condition0%0/3
$self->{"critic"} //= "Perl::Critic"->new("-profile", $self->{"profile"}, "-severity", 1, "-top", 1000000, "-verbose", 1)
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"critic"} //= "Perl::Critic"->new("-profile", $self->{"profile"}, "-severity", 1, "-top", 1000000, "-verbose", 1)
$self->{"critic"} "Perl::Critic"->new("-profile", $self->{"profile"}, "-severity", 1, "-top", 1000000, "-verbose", 1)
Truth table0%0/3
A //= B
A= $self->{"critic"}B= "Perl::Critic"->new("-profile", $self->{"profile"}, "-severity", 1, "-top", 1000000, "-verbose", 1)
ABresult
1X1
011
000
52 0 my (@valid,@gone);
53 0 foreach my $path (@paths) {
54 0 ▶ if(-e $path) { push @valid,$path }
Branch: 1 branch
BranchTrueFalseTotal
if (-e $path) { } 0 0 0
55 0 else { push @gone,$path }
56 }
57 0 ▶ if(@gone) { confess("Unable to handle missing paths: @gone") }
Branch: 1 branch
BranchTrueFalseTotal
if (@gone) 0 0 0
58 0 foreach my $fn (sort {int(rand(3))-1} grep {$self->newer($_)} Perl::Critic::Utils::all_perl_files(@valid)) {
59 0 my @violations=$self->_critique($fn);
60 0 $self->store($fn,@violations);
61 0 $self->flush($fn);
62 }
63 }
64  
65 2 1;
66  
67 __END__
↑ Summary CriticDB/DB.pm »