| 1 | package Perl::Critic::Distribution 0.003; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # ABSTRACT: Parse a distribution once, for every policy that needs all of it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use 5.014; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use warnings FATAL => 'all'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | no autovivification; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use re '/aa'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use Readonly; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 2 | ▶ | use Cwd (); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 2 | ▶ | use Cpanel::JSON::XS (); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 2 | ▶ | use File::Basename (); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 2 | ▶ | use File::Find (); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 2 | ▶ | use File::Path (); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 2 | ▶ | use File::Slurper (); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 2 | ▶ | use File::Slurper::Temp (); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 2 | ▶ | use File::Spec (); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 2 | ▶ | use Digest::SHA (); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 2 | ▶ | use List::Util (); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 2 | ▶ | use IO::Compress::Gzip (); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 2 | ▶ | use IO::Uncompress::Gunzip (); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 2 | ▶ | use PPI (); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 2 | ▶ | use Time::HiRes (); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 2 | ▶ | use Perl::Critic::Utils qw{ all_perl_files }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | # One object per distribution root and cache directory, for the life of the | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | # process. our, so that a test can empty it and read the cache on disk as a | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | # new process does. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 2 | our %FOR; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | # The collectors registered in this process, by name. our for the same | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | # reason. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 2 | our %COLLECTORS; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 2 | Readonly::Array my @AREAS => qw{ bin lib t xt }; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 2 | Readonly::Array my @DIST_MARKERS => qw{ dist.ini Makefile.PL Build.PL META.json META.yml cpanfile .git }; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | # Change it when what the cache holds changes shape. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 2 | Readonly::Scalar my $CACHE_FORMAT => 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 2 | Readonly::Scalar my $CACHE_NAME => 'perl-critic-distribution'; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 2 | Readonly::Array my @CALLED_BY_PERL => qw{ | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | BEGIN END INIT CHECK UNITCHECK AUTOLOAD DESTROY import unimport CLONE CLONE_SKIP | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | BUILD BUILDARGS DEMOLISH FOREIGNBUILDARGS | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | TIESCALAR TIEARRAY TIEHASH TIEHANDLE FETCH STORE FETCHSIZE STORESIZE EXTEND | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | EXISTS DELETE CLEAR PUSH POP SHIFT UNSHIFT SPLICE FIRSTKEY NEXTKEY SCALAR UNTIE | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | PRINT PRINTF WRITE READ READLINE GETC CLOSE OPEN BINMODE EOF FILENO SEEK TELL | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | # What the files in the cache directory are named. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 2 | Readonly::Scalar my $CACHE_FILE_RX => qr/\A [[:xdigit:]]{40} [.]json[.]gz \z/xs; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 38 | ▶ | my $cache_path = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 38 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 38 | ▶ | return if !defined $self->{cache_dir}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 33 | return File::Spec->catfile( $self->{cache_dir}, Digest::SHA::sha1_hex( $self->{root} ) . '.json.gz' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 2 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | # The format of the cache and the stamp of this file. A cache made by another | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | # version of this module, or by this one before an edit, has a different key. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 25 | ▶ | my $cache_key = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 25 | ▶ | return join q{/}, $CACHE_FORMAT, __PACKAGE__->stamp(__FILE__) // q{}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
__PACKAGE__->stamp(__FILE__) // ""
MC/DC0%0/1
__PACKAGE__->stamp(__FILE__) // ""
__PACKAGE__->stamp(__FILE__)
Truth table50%1/2
A
A= __PACKAGE__->stamp(__FILE__)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 2 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | # Replaces the file whole, so a reader never sees half of it. A cache that | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | # cannot be written costs the next run a parse, and nothing else. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 18 | ▶ | my $write_cache = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 18 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 18 | ▶ | my $path = $self->$cache_path() or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 15 | my $json = Cpanel::JSON::XS->new->canonical->encode( { key => $cache_key->(), root => $self->{root}, files => $self->{files}, stash => $self->{stash} } ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | # The root goes in the gzip header too, so that the pruning below can read | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | # it without decompressing the file. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 15 | ▶ | IO::Compress::Gzip::gzip( \$json => \my $gz, Comment => $self->{root} ) or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 15 | File::Path::make_path( $self->{cache_dir}, { error => \my $errors } ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 15 | ▶ | return if @$errors; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 15 | ▶ | eval { File::Slurper::Temp::write_binary( $path, $gz ); 1 } or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | # Removes the cache of each root that is gone, such as a deleted checkout. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | # A file whose header cannot be read is removed too, since nothing can read | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | # it either. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 15 | my $dir = $self->{cache_dir}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | File::Find::find( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | no_chdir => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 32 | ▶ | wanted => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=9 SCAR=23.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 32 | ▶ | $File::Find::prune = 1 if -d $File::Find::name && $File::Find::name ne $dir; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
-d $File::Find::name and $File::Find::name ne $dir
MC/DC0%0/2
-d $File::Find::name and $File::Find::name ne $dir
-d $File::Find::name
$File::Find::name ne $dir
Truth table66%2/3
A and B
A= -d $File::Find::nameB= $File::Find::name ne $dir
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 32 | ▶ | return if File::Basename::basename($File::Find::name) !~ m/$CACHE_FILE_RX/xs; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 16 | my $z = IO::Uncompress::Gunzip->new($File::Find::name); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 16 | ▶ | my $header = $z && $z->getHeaderInfo(); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$z && $z->getHeaderInfo
MC/DC0%0/2
$z && $z->getHeaderInfo
$z
$z->getHeaderInfo
Truth table33%1/3
A && B
A= $zB= $z->getHeaderInfo
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 16 | ▶ | $z->close() if $z; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 16 | ▶ | my $root = ref $header eq 'HASH' ? $header->{Comment} : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 16 | ▶ | unlink $File::Find::name if !defined $root || !-d $root; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $root && -d $root
MC/DC50%1/2
defined $root && -d $root
defined $root
-d $root
Truth table66%2/3
A && B
A= defined $rootB= -d $root
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 15 | $dir | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 15 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 2 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | # Brings what each registered collector returned up to date, for each file of | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | # the distribution: from this object, then from the cache on disk, and by | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | # parsing what neither has. Each file is parsed at most once, whatever number | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | # of collectors need it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 28 | ▶ | my $refresh = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=29 SCAR=33.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 28 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | # Every registered collector, at its version, already has data for every | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | # file, in this process. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 28 | ▶ | return if $self->{files} && !List::Util::any { ( $self->{current}{$_} // q{} ) ne $COLLECTORS{$_}{version} } keys %COLLECTORS; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
Condition100%5/5
$$self{"files"} and not &List::Util::any(sub {
($$self{"current"}{$_} // "") ne $COLLECTORS{$_}{"version"};
}
, keys %Perl::Critic::Distribution::COLLECTORS)
$$self{"current"}{$_} // ""
MC/DC100%2/2
$$self{"files"} and not &List::Util::any(sub {
($$self{"current"}{$_} // "") ne $COLLECTORS{$_}{"version"};
}
, keys %Perl::Critic::Distribution::COLLECTORS)
$$self{"files"}
not &List::Util::any(sub {
($$self{"current"}{$_} // "") ne $COLLECTORS{$_}{"version"};
}
, keys %Perl::Critic::Distribution::COLLECTORS)
MC/DC100%1/1
$$self{"current"}{$_} // ""
$$self{"current"}{$_}
Truth table100%3/3
A and not(B)
A= $$self{"files"}B= not &List::Util::any(sub {
($$self{"current"}{$_} // "") ne $COLLECTORS{$_}{"version"};
}
, keys %Perl::Critic::Distribution::COLLECTORS)
Truth table100%2/2
A
A= $$self{"current"}{$_}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 21 | ▶ | my $cache = $self->{files} ? { files => $self->{files}, stash => $self->{stash} } : {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 21 | ▶ | if ( !$self->{files} && ( my $path = $self->$cache_path() ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $$self{"files"} and my $path = $self->$cache_path
MC/DC100%2/2
not $$self{"files"} and my $path = $self->$cache_path
not $$self{"files"}
my $path = $self->$cache_path
Truth table100%3/3
not(A) and B
A= not $$self{"files"}B= my $path = $self->$cache_path
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | # A cache that is not there fails to read, like one that is unreadable. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 18 | my $read = eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 18 | my $gz = File::Slurper::read_binary($path); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 12 | ▶ | IO::Uncompress::Gunzip::gunzip( \$gz => \my $json ) or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 11 | Cpanel::JSON::XS->new->decode($json); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 18 | ▶ | $cache = $read if ref $read eq 'HASH' && ( $read->{key} // q{} ) eq $cache_key->() && ref $read->{files} eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition75%6/8
ref $read eq "HASH" and ($$read{"key"} // "") eq &$cache_key() and ref $$read{"files"} eq "HASH"
ref $read eq "HASH" and ($$read{"key"} // "") eq &$cache_key()
$$read{"key"} // ""
MC/DC33%1/3
ref $read eq "HASH" and ($$read{"key"} // "") eq &$cache_key() and ref $$read{"files"} eq "HASH"
ref $read eq "HASH"
$$read{"key"}
ref $$read{"files"} eq "HASH"
Truth table50%2/4
A and B and C
A= ref $read eq "HASH"B= $$read{"key"}C= ref $$read{"files"} eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 21 | ▶ | my $cached = $cache->{files} // {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$$cache{"files"} // {}
MC/DC100%1/1
$$cache{"files"} // {}
$$cache{"files"}
Truth table100%2/2
A
A= $$cache{"files"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 21 | my %now; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 21 | my $changed = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 21 | foreach my $area (@AREAS) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 84 | my $path = File::Spec->catdir( $self->{root}, $area ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 84 | ▶ | next if !-d $path; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 84 | foreach my $file ( sort( all_perl_files($path) ) ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 103 | ▶ | my $stamp = $self->stamp($file) // next; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->stamp($file) // (next)
MC/DC0%0/1
$self->stamp($file) // (next)
$self->stamp($file)
Truth table50%1/2
A
A= $self->stamp($file)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 103 | my $entry = $cached->{$file}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 103 | ▶ | if ( ref $entry ne 'HASH' || ( $entry->{stamp} // q{} ) ne $stamp || ref $entry->{collected} ne 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition87%7/8
ref $entry ne "HASH" or ($$entry{"stamp"} // "") ne $stamp or ref $$entry{"collected"} ne "HASH"
ref $entry ne "HASH" or ($$entry{"stamp"} // "") ne $stamp
$$entry{"stamp"} // ""
MC/DC0%0/3
ref $entry ne "HASH" or ($$entry{"stamp"} // "") ne $stamp or ref $$entry{"collected"} ne "HASH"
ref $entry ne "HASH"
$$entry{"stamp"}
ref $$entry{"collected"} ne "HASH"
Truth table50%2/4
A or B or C
A= ref $entry ne "HASH"B= $$entry{"stamp"}C= ref $$entry{"collected"} ne "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 60 | $entry = { stamp => $stamp, area => $area, collected => {} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 60 | $changed = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | # The collectors that have nothing for this file, at their version. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | my @needed = grep { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 103 | my $held = $entry->{collected}{$_}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | !( ref $held eq 'HASH' && exists $held->{data} && ( $held->{version} // q{} ) eq $COLLECTORS{$_}{version} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 156 | ▶ | } sort keys %COLLECTORS; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition75%6/8
ref $held eq 'HASH' && exists $$held{'data'} && ($$held{'version'} // '') eq $Perl::Critic::Distribution::COLLECTORS{$_}{'version'}
ref $held eq "HASH" and exists $$held{"data"}
$$held{"version"} // ""
MC/DC33%1/3
ref $held eq 'HASH' && exists $$held{'data'} && ($$held{'version'} // '') eq $Perl::Critic::Distribution::COLLECTORS{$_}{'version'}
ref $held eq "HASH"
exists $$held{"data"}
$$held{"version"}
Truth table50%2/4
A and B && C
A= ref $held eq "HASH"B= exists $$held{"data"}C= $$held{"version"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 103 | ▶ | if (@needed) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | # Not kept, so a file that PPI cannot read is tried again by | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | # the next process, as it would be with no cache. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 75 | ▶ | my $ppi = PPI::Document->new($file) or next; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 75 | foreach my $name (@needed) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 95 | my $collector = $COLLECTORS{$name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 95 | $entry->{collected}{$name} = { version => $collector->{version}, data => $collector->{collect}->( $ppi, $file, $area ) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 75 | $changed = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 103 | $now{$file} = $entry; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | # A file in the cache that is gone is a change too. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 21 | ▶ | $changed ||= List::Util::any { !$now{$_} } keys %$cached; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Condition100%3/3
$changed ||= &List::Util::any(sub {
not $now{$_};
}
, keys %$cached)
MC/DC100%2/2
$changed ||= &List::Util::any(sub {
not $now{$_};
}
, keys %$cached)
$changed
&List::Util::any(sub {
not $now{$_};
}
, keys %$cached)
Truth table100%3/3
A ||= B
A= $changedB= &List::Util::any(sub {
not $now{$_};
}
, keys %$cached)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 21 | $self->{files} = \%now; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 21 | ▶ | $self->{stash} = ref $cache->{stash} eq 'HASH' ? $cache->{stash} : {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 21 | $self->{current} = { map { $_ => $COLLECTORS{$_}{version} } keys %COLLECTORS }; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 21 | ▶ | $self->$write_cache() if $changed; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 21 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 2 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 16 | ▶ | sub register { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
register: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 16 | my ( $class, %opts ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 16 | my $name = $opts{name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 16 | ▶ | die "A collector needs a name\n" if ( $name // q{} ) eq q{}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$name // ""
MC/DC100%1/1
$name // ""
$name
Truth table100%2/2
A
A= $name
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 15 | ▶ | die "The collector $name needs collect, a code reference\n" if ref $opts{collect} ne 'CODE'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 14 | ▶ | $COLLECTORS{$name} = { version => $opts{version} // q{}, collect => $opts{collect} }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$opts{"version"} // ""
MC/DC100%1/1
$opts{"version"} // ""
$opts{"version"}
Truth table100%2/2
A
A= $opts{"version"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 14 | return $name; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 129 | ▶ | sub stamp { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stamp: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 129 | my ( $class, $file ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 129 | ▶ | my @st = Time::HiRes::stat($file) or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 129 | return join q{:}, @st[ 0, 1, 7 ], map { sprintf '%.9f', $_ } @st[ 9, 10 ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 41 | ▶ | sub root_of { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
root_of: called CC=18 SCAR=28.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 41 | my ( $class, $file ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 41 | ▶ | return if !defined $file; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 40 | ▶ | my $path = Cwd::abs_path($file) // return; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
Cwd::abs_path($file) // (return)
MC/DC0%0/1
Cwd::abs_path($file) // (return)
Cwd::abs_path($file)
Truth table50%1/2
A
A= Cwd::abs_path($file)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 40 | my ( $volume, $directories ) = File::Spec->splitpath($path); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 40 | my @dirs = File::Spec->splitdir($directories); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 40 | ▶ | pop @dirs while @dirs && $dirs[-1] eq q{}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@dirs and $dirs[-1] eq ""
MC/DC50%1/2
@dirs and $dirs[-1] eq ""
@dirs
$dirs[-1] eq ""
Truth table66%2/3
A and B
A= @dirsB= $dirs[-1] eq ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 40 | my %area = map { $_ => 1 } @AREAS; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 40 | my @fallback; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 40 | foreach my $depth ( reverse 0 .. $#dirs ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 87 | my $ancestor = File::Spec->catpath( $volume, File::Spec->catdir( @dirs[ 0 .. $depth ] ), q{} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 87 | ▶ | my $area = $depth < $#dirs && $area{ $dirs[ $depth + 1 ] } ? $dirs[ $depth + 1 ] : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$depth < $#dirs and $area{$dirs[$depth + 1]}
MC/DC100%2/2
$depth < $#dirs and $area{$dirs[$depth + 1]}
$depth < $#dirs
$area{$dirs[$depth + 1]}
Truth table100%3/3
A and B
A= $depth < $#dirsB= $area{$dirs[$depth + 1]}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 87 | ▶ | $area //= 'lib' if $depth + 1 < $#dirs && $dirs[ $depth + 1 ] eq 'blib' && $dirs[ $depth + 2 ] eq 'lib'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition87%7/8
$depth + 1 < $#dirs and $dirs[$depth + 1] eq "blib" and $dirs[$depth + 2] eq "lib"
$depth + 1 < $#dirs and $dirs[$depth + 1] eq "blib"
$area //= "lib"
MC/DC100%3/3
$depth + 1 < $#dirs and $dirs[$depth + 1] eq "blib" and $dirs[$depth + 2] eq "lib"
$depth + 1 < $#dirs
$dirs[$depth + 1] eq "blib"
$dirs[$depth + 2] eq "lib"
MC/DC0%0/1
$area //= "lib"
$area
Truth table100%4/4
A and B and C
A= $depth + 1 < $#dirsB= $dirs[$depth + 1] eq "blib"C= $dirs[$depth + 2] eq "lib"
Truth table50%1/2
A
A= $area
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 87 | my $marked = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 87 | foreach my $marker (@DIST_MARKERS) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 375 | ▶ | $marked = -e File::Spec->catfile( $ancestor, $marker ) and last; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 87 | ▶ | if ($marked) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 39 | ▶ | return if !defined $area; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 36 | return ( $ancestor, $area ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 48 | ▶ | @fallback = ( $ancestor, $area ) if !@fallback && defined $area; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not @fallback and defined $area
MC/DC100%2/2
not @fallback and defined $area
not @fallback
defined $area
Truth table100%3/3
not(A) and B
A= not @fallbackB= defined $area
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 1 | return @fallback; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 31 | ▶ | sub default_cache_dir { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_cache_dir: called CC=4 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 31 | ▶ | my $base = $ENV{XDG_CACHE_HOME} || ( $ENV{HOME} && File::Spec->catdir( $ENV{HOME}, '.cache' ) ) or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$ENV{'XDG_CACHE_HOME'} || $ENV{'HOME'} && 'File::Spec'->catdir($ENV{'HOME'}, '.cache')
$ENV{"HOME"} and "File::Spec"->catdir($ENV{"HOME"}, ".cache")
MC/DC0%0/3
$ENV{'XDG_CACHE_HOME'} || $ENV{'HOME'} && 'File::Spec'->catdir($ENV{'HOME'}, '.cache')
$ENV{'XDG_CACHE_HOME'}
$ENV{"HOME"}
"File::Spec"->catdir($ENV{"HOME"}, ".cache")
Truth table50%2/4
A || B and C
A= $ENV{'XDG_CACHE_HOME'}B= $ENV{"HOME"}C= "File::Spec"->catdir($ENV{"HOME"}, ".cache")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 31 | return File::Spec->catdir( $base, $CACHE_NAME ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 32 | ▶ | sub for_file { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
for_file: called CC=9 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 32 | my ( $class, $file, %opts ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 32 | ▶ | my ($root) = $class->root_of($file) or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 31 | my $cache_dir = $class->default_cache_dir(); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 31 | ▶ | if ( exists $opts{cache} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 3 | ▶ | $cache_dir = !$opts{cache} ? undef : ( $opts{cache_dir} // q{} ) eq q{} ? $cache_dir : $opts{cache_dir}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition50%1/2
$opts{"cache_dir"} // ""
MC/DC0%0/1
$opts{"cache_dir"} // ""
$opts{"cache_dir"}
Truth table50%1/2
A
A= $opts{"cache_dir"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | elsif ( exists $opts{cache_dir} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 26 | $cache_dir = $opts{cache_dir}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 31 | ▶ | return $FOR{ join "\0", $root, $cache_dir // q{} } //= bless { root => $root, cache_dir => $cache_dir }, $class; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%4/4
$Perl::Critic::Distribution::FOR{join "\0", $root, $cache_dir // ""} //= bless({"root", $root, "cache_dir", $cache_dir}, $class)
$cache_dir // ""
MC/DC100%1/1
$Perl::Critic::Distribution::FOR{join "\0", $root, $cache_dir // ""} //= bless({"root", $root, "cache_dir", $cache_dir}, $class)
$Perl::Critic::Distribution::FOR{join "\0", $root, $cache_dir // ""}
MC/DC100%1/1
$cache_dir // ""
$cache_dir
Truth table100%2/2
A
A= $Perl::Critic::Distribution::FOR{join "\0", $root, $cache_dir // ""}
Truth table100%2/2
A
A= $cache_dir
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 1 | ▶ | sub root { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
root: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 1 | return $self->{root}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 21 | ▶ | sub collected { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
collected: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 21 | my ( $self, $name ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 21 | ▶ | die "No collector is registered as $name\n" if !$COLLECTORS{$name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 20 | $self->$refresh(); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 20 | my $files = $self->{files}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 20 | return { map { $_ => $files->{$_}{collected}{$name}{data} } keys %$files }; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 2 | ▶ | sub area_of { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
area_of: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 2 | my ( $self, $file ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 2 | $self->$refresh(); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 2 | ▶ | my $entry = $self->{files}{$file} or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 1 | return $entry->{area}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 1 | ▶ | sub stamp_of { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stamp_of: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 1 | my ( $self, $file ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 1 | $self->$refresh(); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 1 | ▶ | my $entry = $self->{files}{$file} or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 1 | return $entry->{stamp}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 4 | ▶ | sub stash { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stash: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 4 | my ( $self, $name ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 4 | ▶ | die "No collector is registered as $name\n" if !$COLLECTORS{$name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 4 | $self->$refresh(); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 4 | my $kept = $self->{stash}{$name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 4 | ▶ | return if ref $kept ne 'HASH' || ( $kept->{version} // q{} ) ne $COLLECTORS{$name}{version}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition80%4/5
ref $kept ne "HASH" or ($$kept{"version"} // "") ne $Perl::Critic::Distribution::COLLECTORS{$name}{"version"}
$$kept{"version"} // ""
MC/DC0%0/2
ref $kept ne "HASH" or ($$kept{"version"} // "") ne $Perl::Critic::Distribution::COLLECTORS{$name}{"version"}
ref $kept ne "HASH"
$$kept{"version"}
Truth table66%2/3
A or B
A= ref $kept ne "HASH"B= $$kept{"version"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 2 | return $kept->{data}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 1 | ▶ | sub keep { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
keep: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 1 | my ( $self, $name, $data ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 1 | ▶ | die "No collector is registered as $name\n" if !$COLLECTORS{$name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 1 | $self->$refresh(); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 1 | $self->{stash}{$name} = { version => $COLLECTORS{$name}{version}, data => $data }; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 1 | return $self->$write_cache(); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 1 | ▶ | sub policy_parameters { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
policy_parameters: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 1 | name => 'cache', | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | description => 'Keep what was read of each distribution on disk between runs.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | default_string => '1', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | behavior => 'boolean', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | name => 'cache_dir', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | description => 'Where it is kept. Empty means the default of Perl::Critic::Distribution.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | default_string => q{}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | behavior => 'string', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 1 | ▶ | sub called_by_perl { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
called_by_perl: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 1 | return @CALLED_BY_PERL; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 3 | ▶ | sub walk { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
walk: called CC=10 SCAR=23.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 3 | my ( $class, $node, $visit, %context ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | # Each frame is the children of a node, how far through them the walk is, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | # and the package and the sub there. A loop and not recursion, because a deep | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | # document would otherwise warn of deep recursion, which is fatal here. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 3 | ▶ | my @frames = ( [ [ $node->children() ], 0, $context{package} // 'main', $context{sub} ] ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$context{"package"} // "main"
MC/DC100%1/1
$context{"package"} // "main"
$context{"package"}
Truth table100%2/2
A
A= $context{"package"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 3 | ▶ | while (@frames) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 190 | my $frame = $frames[-1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 190 | my ( $children, $at, $package, $sub ) = @$frame; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 190 | my $child = $children->[$at]; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 190 | ▶ | if ( !defined $child ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 49 | pop @frames; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 49 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 141 | $frame->[1]++; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 141 | $visit->( $child, $package, $sub ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 141 | ▶ | if ( $child->isa('PPI::Statement::Package') ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 4 | my ($block) = grep { $_->isa('PPI::Structure::Block') } $child->schildren(); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 4 | ▶ | if ($block) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 2 | push @frames, [ [ $block->children() ], 0, $child->namespace(), $sub ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 2 | $frame->[2] = $child->namespace(); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | ▶ | elsif ( $child->isa('PPI::Statement::Sub') && !$child->forward() ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$child->isa("PPI::Statement::Sub") and not $child->forward
MC/DC100%2/2
$child->isa("PPI::Statement::Sub") and not $child->forward
$child->isa("PPI::Statement::Sub")
not $child->forward
Truth table100%3/3
A and not(B)
A= $child->isa("PPI::Statement::Sub")B= not $child->forward
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 8 | ( my $name = $child->name() ) =~ s/\A::/main::/xs; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 8 | ▶ | push @frames, [ [ $child->children() ], 0, $package, index( $name, '::' ) >= 0 ? $name : "${package}::$name" ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | elsif ( $child->isa('PPI::Node') ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 36 | push @frames, [ [ $child->children() ], 0, $package, $sub ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 3 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||