lib/Dist/Zilla/Plugin/PerlTidy/WithExclusions.pm

filter: Statementstmt 37.7% 17 / 45 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 44.4% 4 / 9 Podpod 50.0% 1 / 2 totaltotal 26.1% 22 / 84 CC 14 SCAR 40.0
CC
14
Cov
24%
_munge_perl
110.0
munge_file
20.0
munge_files
6.0
CRAP 54.5
↑ Summary lib/Dist/Zilla/PluginBundle/Author/CSJEWELL.pm »
1 package Dist::Zilla::Plugin::PerlTidy::WithExclusions;
2  
3 1 our $VERSION = v0.001;
4  
5 1 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Perl::Tidy qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 with(
9 'Dist::Zilla::Role::FileMunger',
10 'Dist::Zilla::Role::FileFinderUser' => {
11 default_finders => [':AllFiles'],
12 },
13 );
14  
15 1 has 'perltidyrc' => (is => 'ro');
16  
17 has exclusions => (
18 is => 'ro',
19 isa => 'ArrayRef[Str]',
20 0 ▶ default => sub { [] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
21 1 );
22  
23 0 ▶sub mvp_multivalue_args {qw(exclusions)}
Subroutine mvp_multivalue_args: not called CC=1 SCAR=6.9
24  
25 0 ▶sub munge_files {
Subroutine munge_files: not called CC=2 SCAR=17.9
Pod undocumented
26 0 my ($self) = @_;
27  
28 0 $self->munge_file($_) for @{ $self->found_files };
29 }
30  
31 0 ▶sub munge_file {
Subroutine munge_file: not called CC=4 SCAR=30.0
Pod documented
32 0 my ($self, $file) = @_;
33  
34 0 ▶ return $self->_munge_perl($file) if $file->name =~ /\.(?:pm|pl|t)$/i;
Branch: 1 branch
BranchTrueFalseTotal
if $file->name =~ /\.(?:pm|pl|t)$/i 0 0 0
35 0 ▶ return if -B $file->name; # do not try to read binary file
Branch: 1 branch
BranchTrueFalseTotal
if -B $file->name 0 0 0
36 0 ▶ return $self->_munge_perl($file) if $file->content =~ /^#!.*\bperl\b/;
Branch: 1 branch
BranchTrueFalseTotal
if $file->content =~ /^#!.*\bperl\b/ 0 0 0
37 0 return;
38 }
39  
40 0 ▶sub _munge_perl {
Subroutine _munge_perl: not called CC=10 SCAR=47.0
41 0 my ($self, $file) = @_;
42  
43 0 ▶ return if ref($file) eq 'Dist::Zilla::File::FromCode';
Branch: 1 branch
BranchTrueFalseTotal
if ref $file eq "Dist::Zilla::File::FromCode" 0 0 0
44 0 ▶ return if $file->name && $file->name =~ m{^blib/};
Branch: 1 branch
BranchTrueFalseTotal
if $file->name and $file->name =~ m[^blib/] 0 0 0
Condition0%0/3
$file->name and $file->name =~ m[^blib/]
!ll&&!rl&&r
000
MC/DC0%0/2
$file->name and $file->name =~ m[^blib/]
$file->name $file->name =~ m[^blib/]
Truth table0%0/3
A and B
A= $file->nameB= $file->name =~ m[^blib/]
ABresult
0X0
100
111
45 return
46 if $file->name
47 0 ▶ and scalar grep { $file->name =~ /$_/ } @{ $self->exclusions };
Branch: 1 branch
BranchTrueFalseTotal
if $file->name and scalar grep({$file->name =~ /$_/;} @{$self->exclusions;}) 0 0 0
Condition0%0/2
$file->name and scalar grep({$file->name =~ /$_/;} @{$self->exclusions;})
!ll
00
MC/DC0%0/1
$file->name and scalar grep({$file->name =~ /$_/;} @{$self->exclusions;})
$file->name
Truth table0%0/2
A
A= $file->name
Aresult
00
11
48  
49 0 my $perltidyrc;
50 0 ▶ if (defined $self->perltidyrc) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->perltidyrc) 0 0 0
51 0 ▶ if (-r $self->perltidyrc) {
Branch: 1 branch
BranchTrueFalseTotal
if (-r $self->perltidyrc) { } 0 0 0
52 0 $perltidyrc = $self->perltidyrc;
53 } else {
54 0 $self->log_fatal([ 'specified perltidyrc is not readable: %s', $perltidyrc ]);
55 }
56 }
57  
58 # make Perl::Tidy happy
59 0 local @ARGV = ();
60  
61 0 $self->log_debug([ 'Perltidying %s', $file->name, ]);
62  
63 0 my $source = $file->content;
64 0 my ($destination, $errors);
65 0 ▶ Perl::Tidy::perltidy(
Branch: 1 branch
BranchTrueFalseTotal
$perltidyrc ? : 0 0 0
66 source => \$source,
67 destination => \$destination,
68 stderr => \$errors,
69 argv => ['--standard-error-output'],
70 ($perltidyrc ? (perltidyrc => $perltidyrc) : ()),
71 );
72  
73 0 ▶ $self->log([ 'Errors from perltidying %s: %s', $file->name, $errors, ])
Branch: 1 branch
BranchTrueFalseTotal
if $errors 0 0 0
74 if $errors;
75  
76 0 $file->content($destination);
77 } ## end sub _munge_perl
78  
79 1 __PACKAGE__->meta->make_immutable;
80 1 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
81  
82 1 1;
83  
84 __END__
↑ Summary lib/Dist/Zilla/PluginBundle/Author/CSJEWELL.pm »