blib/lib/Dist/Zilla/App/Command/perltidy.pm

filter: Statementstmt 66.6% 46 / 69 Branchbran 50.0% 11 / 22 Conditioncond 66.6% 6 / 9 MC/DCmcdc 50.0% 3 / 6 Subroutinesub 76.9% 10 / 13 Podpod 100% 3 / 3 totaltotal 64.7% 79 / 122 CC 15 SCAR 24.6
CC
15
Cov
63%
execute
23.3
__ANON__
5.3
__ANON__
2.0
CRAP 11.7
« blib/lib/Dist/Zilla/Plugin/PerlTidy.pm ↑ Summary
1 package Dist::Zilla::App::Command::perltidy;
2 8 $Dist::Zilla::App::Command::perltidy::VERSION = '0.21';
3 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 # ABSTRACT: perltidy your dist
7 8 ▶use Dist::Zilla::App -command;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 8 ▶use Path::Iterator::Rule;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 8 ▶use File::Copy;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 3 ▶sub abstract {'perltidy your dist'}
Subroutine abstract: called CC=1 SCAR=0.0
Pod documented
12  
13 my $backends = {
14 2 ▶ vanilla => sub {
Subroutine __ANON__: called CC=1 SCAR=0.6
15 2 local @ARGV = ();
16 2 require Perl::Tidy;
17 0 ▶ return sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
18 0 local @ARGV = ();
19 0 Perl::Tidy::perltidy(@_);
20 2 };
21 },
22 0 ▶ sweet => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
23 0 local @ARGV = ();
24 0 require Perl::Tidy::Sweetened;
25 0 ▶ return sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
26 0 local @ARGV = ();
27 0 Perl::Tidy::Sweetened::perltidy(@_);
28 0 };
29 },
30 8 };
31  
32 3 ▶sub opt_spec {
Subroutine opt_spec: called CC=1 SCAR=0.0
Pod documented
33 3 [ 'backend|b=s', 'tidy backend to use', { default => 'vanilla' } ];
34 }
35  
36 3 ▶sub execute {
Subroutine execute: called CC=12 SCAR=31.5
Pod documented
37 3 my ( $self, $opt, $arg ) = @_;
38  
39 # use perltidyrc from command line or from config
40 3 my $perltidyrc;
41 3 ▶ if ( scalar @$arg and -r $arg->[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$arg and -r $arg->[0]) { } 0 3 3
Condition33%1/3
scalar @$arg and -r $arg->[0]
!ll&&!rl&&r
300
MC/DC0%0/2
scalar @$arg and -r $arg->[0]
scalar @$arg -r $arg->[0]
Truth table33%1/3
A and B
A= scalar @$argB= -r $arg->[0]
ABresult
0X0
100
111
42 0 $perltidyrc = $arg->[0];
43 } else {
44 3 my $plugin = $self->zilla->plugin_named('PerlTidy');
45 3 ▶ if ( defined $plugin and defined $plugin->perltidyrc ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $plugin and defined $plugin->perltidyrc) 1 2 3
Condition100%3/3
defined $plugin and defined $plugin->perltidyrc
!ll&&!rl&&r
111
MC/DC100%2/2
defined $plugin and defined $plugin->perltidyrc
defined $plugin defined $plugin->perltidyrc
Truth table100%3/3
A and B
A= defined $pluginB= defined $plugin->perltidyrc
ABresult
0X0
100
111
46 1 $perltidyrc = $plugin->perltidyrc;
47 }
48 }
49  
50 # Verify that if a file is specified it is readable
51 3 ▶ if ( defined $perltidyrc and not -r $perltidyrc ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $perltidyrc and not -r $perltidyrc) 1 2 3
Condition66%2/3
defined $perltidyrc and not -r $perltidyrc
!ll&&!rl&&r
201
MC/DC50%1/2
defined $perltidyrc and not -r $perltidyrc
defined $perltidyrc not -r $perltidyrc
Truth table66%2/3
A and not(B)
A= defined $perltidyrcB= not -r $perltidyrc
ABresult
0X0
100
111
52 1 $self->zilla->log_fatal(
53 [ "specified perltidyrc is not readable: %s ,\nNote: ~ and other shell expansions are not applicable",
54 $perltidyrc
55 ]
56 );
57 }
58  
59 2 ▶ if ( not exists $backends->{ $opt->{backend} } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $$backends{$opt->{"backend"}}) 0 2 2
60 $self->zilla->log_fatal(
61 [ "specified backend not known, known backends are: %s ",
62 0 join q[,], sort keys %{$backends}
63 ]
64 );
65 }
66  
67 2 my $tidy = $backends->{ $opt->{backend} }->();
68  
69 # RT 91288
70 # copied from https://metacpan.org/source/KENTNL/Dist-Zilla-PluginBundle-Author-KENTNL-2.007000/utils/strip_eol.pl
71 2 my $rule = Path::Iterator::Rule->new();
72 2 $rule->skip_vcs;
73 $rule->skip(
74 4 ▶ sub {
Subroutine __ANON__: called CC=4 SCAR=16.6
75 4 ▶ return if not -d $_;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $_ 2 2 4
76 2 ▶ if ( $_[1] =~ qr/^\.build$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[1] =~ qr/^\.build$/) 0 2 2
77 0 $self->zilla->log_debug('Ignoring .build');
78 0 return 1;
79 }
80 2 ▶ if ( $_[1] =~ qr/^[A-Za-z].*-[0-9.]+(-TRIAL)?$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[1] =~ qr/^[A-Za-z].*-[0-9.]+(-TRIAL)?$/) 0 2 2
81 0 $self->zilla->log_debug('Ignoring dzil build tree');
82 0 return 1;
83 }
84 2 return;
85 }
86 2 );
87 2 $rule->file->nonempty;
88 2 $rule->file->not_binary;
89 2 $rule->file->perl_file;
90  
91 # $rule->file->line_match(qr/\s\n/);
92  
93 2 my $next = $rule->iter(
94 '.' => {
95 follow_symlinks => 0,
96 sorted => 0,
97 }
98 );
99  
100 2 ▶ while ( my $file = $next->() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $file = &$next()) 0 2 2
101 0 my $tidyfile = $file . '.tdy';
102 0 $self->zilla->log_debug( [ 'Tidying %s', $file ] );
103 0 ▶ if ( my $pid = fork() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $pid = fork) 0 0 0
104 0 waitpid $pid, 0;
105 0 ▶ $self->zilla->log_fatal(
Branch: 1 branch
BranchTrueFalseTotal
if $? > 0 0 0 0
106 [ 'Child exited with nonzero status: %s', $? ] )
107 if $? > 0;
108 0 File::Copy::move( $tidyfile, $file );
109 0 next;
110 }
111 0 ▶ $tidy->(
Branch: 1 branch
BranchTrueFalseTotal
$perltidyrc ? : 0 0 0
112 source => $file,
113 destination => $tidyfile,
114 argv => [qw( -nst -nse )],
115 ( $perltidyrc ? ( perltidyrc => $perltidyrc ) : () ),
116 );
117 0 exit 0;
118 }
119  
120 2 return 1;
121 }
122  
123 8 1;
124  
125 __END__
« blib/lib/Dist/Zilla/Plugin/PerlTidy.pm ↑ Summary