| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Dist::Zilla::App::Command::perltidy; |
|
2
|
|
|
|
|
|
|
$Dist::Zilla::App::Command::perltidy::VERSION = '0.21'; |
|
3
|
1
|
|
|
1
|
|
1312
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
51
|
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
47
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# ABSTRACT: perltidy your dist |
|
7
|
1
|
|
|
1
|
|
635
|
use Dist::Zilla::App -command; |
|
|
1
|
|
|
|
|
23487
|
|
|
|
1
|
|
|
|
|
19
|
|
|
8
|
1
|
|
|
1
|
|
10414
|
use Path::Iterator::Rule; |
|
|
1
|
|
|
|
|
12526
|
|
|
|
1
|
|
|
|
|
42
|
|
|
9
|
1
|
|
|
1
|
|
847
|
use File::Copy; |
|
|
1
|
|
|
|
|
2807
|
|
|
|
1
|
|
|
|
|
880
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
0
|
|
|
0
|
1
|
|
sub abstract {'perltidy your dist'} |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my $backends = { |
|
14
|
|
|
|
|
|
|
vanilla => sub { |
|
15
|
|
|
|
|
|
|
local @ARGV = (); |
|
16
|
|
|
|
|
|
|
require Perl::Tidy; |
|
17
|
|
|
|
|
|
|
return sub { |
|
18
|
|
|
|
|
|
|
local @ARGV = (); |
|
19
|
|
|
|
|
|
|
Perl::Tidy::perltidy(@_); |
|
20
|
|
|
|
|
|
|
}; |
|
21
|
|
|
|
|
|
|
}, |
|
22
|
|
|
|
|
|
|
sweet => sub { |
|
23
|
|
|
|
|
|
|
local @ARGV = (); |
|
24
|
|
|
|
|
|
|
require Perl::Tidy::Sweetened; |
|
25
|
|
|
|
|
|
|
return sub { |
|
26
|
|
|
|
|
|
|
local @ARGV = (); |
|
27
|
|
|
|
|
|
|
Perl::Tidy::Sweetened::perltidy(@_); |
|
28
|
|
|
|
|
|
|
}; |
|
29
|
|
|
|
|
|
|
}, |
|
30
|
|
|
|
|
|
|
}; |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub opt_spec { |
|
33
|
0
|
|
|
0
|
1
|
|
[ 'backend|b=s', 'tidy backend to use', { default => 'vanilla' } ]; |
|
34
|
|
|
|
|
|
|
} |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub execute { |
|
37
|
0
|
|
|
0
|
1
|
|
my ( $self, $opt, $arg ) = @_; |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# use perltidyrc from command line or from config |
|
40
|
0
|
|
|
|
|
|
my $perltidyrc; |
|
41
|
0
|
0
|
0
|
|
|
|
if ( scalar @$arg and -r $arg->[0] ) { |
|
42
|
0
|
|
|
|
|
|
$perltidyrc = $arg->[0]; |
|
43
|
|
|
|
|
|
|
} else { |
|
44
|
0
|
|
|
|
|
|
my $plugin = $self->zilla->plugin_named('PerlTidy'); |
|
45
|
0
|
0
|
0
|
|
|
|
if ( defined $plugin and defined $plugin->perltidyrc ) { |
|
46
|
0
|
|
|
|
|
|
$perltidyrc = $plugin->perltidyrc; |
|
47
|
|
|
|
|
|
|
} |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# Verify that if a file is specified it is readable |
|
51
|
0
|
0
|
0
|
|
|
|
if ( defined $perltidyrc and not -r $perltidyrc ) { |
|
52
|
0
|
|
|
|
|
|
$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
|
0
|
0
|
|
|
|
|
if ( not exists $backends->{ $opt->{backend} } ) { |
|
60
|
0
|
|
|
|
|
|
$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
|
0
|
|
|
|
|
|
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
|
0
|
|
|
|
|
|
my $rule = Path::Iterator::Rule->new(); |
|
72
|
0
|
|
|
|
|
|
$rule->skip_vcs; |
|
73
|
|
|
|
|
|
|
$rule->skip( |
|
74
|
|
|
|
|
|
|
sub { |
|
75
|
0
|
0
|
|
0
|
|
|
return if not -d $_; |
|
76
|
0
|
0
|
|
|
|
|
if ( $_[1] =~ qr/^\.build$/ ) { |
|
77
|
0
|
|
|
|
|
|
$self->zilla->log_debug('Ignoring .build'); |
|
78
|
0
|
|
|
|
|
|
return 1; |
|
79
|
|
|
|
|
|
|
} |
|
80
|
0
|
0
|
|
|
|
|
if ( $_[1] =~ qr/^[A-Za-z].*-[0-9.]+(-TRIAL)?$/ ) { |
|
81
|
0
|
|
|
|
|
|
$self->zilla->log_debug('Ignoring dzil build tree'); |
|
82
|
0
|
|
|
|
|
|
return 1; |
|
83
|
|
|
|
|
|
|
} |
|
84
|
0
|
|
|
|
|
|
return; |
|
85
|
|
|
|
|
|
|
} |
|
86
|
0
|
|
|
|
|
|
); |
|
87
|
0
|
|
|
|
|
|
$rule->file->nonempty; |
|
88
|
0
|
|
|
|
|
|
$rule->file->not_binary; |
|
89
|
0
|
|
|
|
|
|
$rule->file->perl_file; |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
# $rule->file->line_match(qr/\s\n/); |
|
92
|
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
my $next = $rule->iter( |
|
94
|
|
|
|
|
|
|
'.' => { |
|
95
|
|
|
|
|
|
|
follow_symlinks => 0, |
|
96
|
|
|
|
|
|
|
sorted => 0, |
|
97
|
|
|
|
|
|
|
} |
|
98
|
|
|
|
|
|
|
); |
|
99
|
|
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
|
while ( my $file = $next->() ) { |
|
101
|
0
|
|
|
|
|
|
my $tidyfile = $file . '.tdy'; |
|
102
|
0
|
|
|
|
|
|
$self->zilla->log_debug( [ 'Tidying %s', $file ] ); |
|
103
|
0
|
0
|
|
|
|
|
if ( my $pid = fork() ) { |
|
104
|
0
|
|
|
|
|
|
waitpid $pid, 0; |
|
105
|
0
|
0
|
|
|
|
|
$self->zilla->log_fatal( |
|
106
|
|
|
|
|
|
|
[ 'Child exited with nonzero status: %s', $? ] ) |
|
107
|
|
|
|
|
|
|
if $? > 0; |
|
108
|
0
|
|
|
|
|
|
File::Copy::move( $tidyfile, $file ); |
|
109
|
0
|
|
|
|
|
|
next; |
|
110
|
|
|
|
|
|
|
} |
|
111
|
0
|
0
|
|
|
|
|
$tidy->( |
|
112
|
|
|
|
|
|
|
source => $file, |
|
113
|
|
|
|
|
|
|
destination => $tidyfile, |
|
114
|
|
|
|
|
|
|
argv => [qw( -nst -nse )], |
|
115
|
|
|
|
|
|
|
( $perltidyrc ? ( perltidyrc => $perltidyrc ) : () ), |
|
116
|
|
|
|
|
|
|
); |
|
117
|
0
|
|
|
|
|
|
exit 0; |
|
118
|
|
|
|
|
|
|
} |
|
119
|
|
|
|
|
|
|
|
|
120
|
0
|
|
|
|
|
|
return 1; |
|
121
|
|
|
|
|
|
|
} |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
1; |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
__END__ |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=pod |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=encoding UTF-8 |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head1 NAME |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
Dist::Zilla::App::Command::perltidy - perltidy your dist |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head1 VERSION |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
version 0.21 |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head2 SYNOPSIS |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
$ dzil perltidy |
|
142
|
|
|
|
|
|
|
# OR |
|
143
|
|
|
|
|
|
|
$ dzil perltidy .myperltidyrc |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head2 CONFIGURATION |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
In your global dzil setting (which is '~/.dzil' or '~/.dzil/config.ini'), |
|
148
|
|
|
|
|
|
|
you can config the perltidyrc like: |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
[PerlTidy] |
|
151
|
|
|
|
|
|
|
perltidyrc = /home/fayland/somewhere/.perltidyrc |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head2 DEFAULTS |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
If you do not specify a specific perltidyrc in dist.ini it will try to use |
|
156
|
|
|
|
|
|
|
the same defaults as Perl::Tidy. |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head2 SEE ALSO |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
L<Perl::Tidy> |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head1 AUTHORS |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=over 4 |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=item * |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
Fayland Lam <fayland@gmail.com> |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=item * |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
Mark Gardner <mjgardner@cpan.org> |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=item * |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
Kent Fredric <kentfredric@gmail.com> |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=back |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
This software is copyright (c) 2015 by Fayland Lam. |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
185
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=cut |