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

filter: Statementstmt 33.3% 11 / 33 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 40.0% 2 / 5 Podpod 50.0% 1 / 2 totaltotal 22.9% 14 / 61 CC 11 SCAR 34.8
CC
11
Cov
21%
_munge_perl
56.0
munge_file
20.0
munge_files
6.0
CRAP 32.4
↑ Summary blib/lib/Dist/Zilla/App/Command/perltidy.pm »
1 package Dist::Zilla::Plugin::PerlTidy;
2 4 $Dist::Zilla::Plugin::PerlTidy::VERSION = '0.21';
3  
4 # ABSTRACT: PerlTidy in Dist::Zilla
5  
6 4 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 with(
8 'Dist::Zilla::Role::FileMunger',
9 'Dist::Zilla::Role::FileFinderUser' => {
10 default_finders => [ ':InstallModules', ':ExecFiles', ':TestFiles' ],
11 },
12 );
13  
14 4 has 'perltidyrc' => ( is => 'ro' );
15  
16 0 ▶sub munge_files {
Subroutine munge_files: not called CC=2 SCAR=17.9
Pod undocumented
17 0 my ($self) = @_;
18  
19 0 $self->munge_file($_) for @{ $self->found_files };
20 }
21  
22 0 ▶sub munge_file {
Subroutine munge_file: not called CC=4 SCAR=30.0
Pod documented
23 0 my ( $self, $file ) = @_;
24  
25 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
26 0 ▶ return if -B $file->name; # do not try to read binary file
Branch: 1 branch
BranchTrueFalseTotal
if -B $file->name 0 0 0
27 0 ▶ return $self->_munge_perl($file) if $file->content =~ /^#!.*\bperl\b/;
Branch: 1 branch
BranchTrueFalseTotal
if $file->content =~ /^#!.*\bperl\b/ 0 0 0
28 0 return;
29 }
30  
31 0 ▶sub _munge_perl {
Subroutine _munge_perl: not called CC=7 SCAR=40.3
32 0 my ( $self, $file ) = @_;
33  
34 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
35 return
36 0 ▶ if $file->name
Branch: 1 branch
BranchTrueFalseTotal
if $file->name and $file->name eq "t/00-compile.t" 0 0 0
Condition0%0/3
$file->name and $file->name eq "t/00-compile.t"
!ll&&!rl&&r
000
MC/DC0%0/2
$file->name and $file->name eq "t/00-compile.t"
$file->name $file->name eq "t/00-compile.t"
Truth table0%0/3
A and B
A= $file->nameB= $file->name eq "t/00-compile.t"
ABresult
0X0
100
111
37 and $file->name eq 't/00-compile.t'
38 ; # simply skip Dist::Zilla::Plugin::Test::Compile (RT 88601)
39  
40 0 my $source = $file->content;
41  
42 0 my $perltidyrc;
43 0 ▶ if ( defined $self->perltidyrc ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->perltidyrc) 0 0 0
44 0 ▶ if ( -r $self->perltidyrc ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-r $self->perltidyrc) { } 0 0 0
45 0 $perltidyrc = $self->perltidyrc;
46 } else {
47 0 $self->log_fatal(
48 [ "specified perltidyrc is not readable: %s", $perltidyrc ] );
49 }
50 }
51  
52 # make Perl::Tidy happy
53 0 local @ARGV = ();
54  
55 0 my $destination;
56 0 require Perl::Tidy;
57 0 ▶ Perl::Tidy::perltidy(
Branch: 1 branch
BranchTrueFalseTotal
$perltidyrc ? : 0 0 0
58 source => \$source,
59 destination => \$destination,
60 ( $perltidyrc ? ( perltidyrc => $perltidyrc ) : () ),
61 );
62  
63 0 $file->content($destination);
64 }
65  
66 4 __PACKAGE__->meta->make_immutable;
67 4 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
68  
69 4 1;
70  
71 __END__
↑ Summary blib/lib/Dist/Zilla/App/Command/perltidy.pm »