line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Dist::Zilla::Plugin::PerlTidy; |
2
|
|
|
|
|
|
|
$Dist::Zilla::Plugin::PerlTidy::VERSION = '0.19'; |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
# ABSTRACT: PerlTidy in Dist::Zilla |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
16572
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
with( |
8
|
|
|
|
|
|
|
'Dist::Zilla::Role::FileMunger', |
9
|
|
|
|
|
|
|
'Dist::Zilla::Role::FileFinderUser' => { |
10
|
|
|
|
|
|
|
default_finders => [ ':InstallModules', ':ExecFiles', ':TestFiles' ], |
11
|
|
|
|
|
|
|
}, |
12
|
|
|
|
|
|
|
); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has 'perltidyrc' => ( is => 'ro' ); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub munge_files { |
17
|
|
|
|
|
|
|
my ($self) = @_; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
$self->munge_file($_) for @{ $self->found_files }; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub munge_file { |
23
|
|
|
|
|
|
|
my ( $self, $file ) = @_; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
return $self->_munge_perl($file) if $file->name =~ /\.(?:pm|pl|t)$/i; |
26
|
|
|
|
|
|
|
return if -B $file->name; # do not try to read binary file |
27
|
|
|
|
|
|
|
return $self->_munge_perl($file) if $file->content =~ /^#!.*\bperl\b/; |
28
|
|
|
|
|
|
|
return; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub _munge_perl { |
32
|
|
|
|
|
|
|
my ( $self, $file ) = @_; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
return if ref($file) eq 'Dist::Zilla::File::FromCode'; |
35
|
|
|
|
|
|
|
return |
36
|
|
|
|
|
|
|
if $file->name |
37
|
|
|
|
|
|
|
and $file->name eq 't/00-compile.t' |
38
|
|
|
|
|
|
|
; # simply skip Dist::Zilla::Plugin::Test::Compile (RT 88601) |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
my $source = $file->content; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
my $perltidyrc; |
43
|
|
|
|
|
|
|
if ( defined $self->perltidyrc ) { |
44
|
|
|
|
|
|
|
if ( -r $self->perltidyrc ) { |
45
|
|
|
|
|
|
|
$perltidyrc = $self->perltidyrc; |
46
|
|
|
|
|
|
|
} else { |
47
|
|
|
|
|
|
|
$self->log_fatal( |
48
|
|
|
|
|
|
|
[ "specified perltidyrc is not readable: %s", $perltidyrc ] ); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# make Perl::Tidy happy |
53
|
|
|
|
|
|
|
local @ARGV = (); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
my $destination; |
56
|
|
|
|
|
|
|
require Perl::Tidy; |
57
|
|
|
|
|
|
|
Perl::Tidy::perltidy( |
58
|
|
|
|
|
|
|
source => \$source, |
59
|
|
|
|
|
|
|
destination => \$destination, |
60
|
|
|
|
|
|
|
( $perltidyrc ? ( perltidyrc => $perltidyrc ) : () ), |
61
|
|
|
|
|
|
|
); |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
$file->content($destination); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
67
|
|
|
|
|
|
|
no Moose; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
1; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
__END__ |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=pod |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=encoding UTF-8 |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 NAME |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
Dist::Zilla::Plugin::PerlTidy - PerlTidy in Dist::Zilla |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 VERSION |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
version 0.19 |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 METHODS |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head2 munge_file |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Implements the required munge_file method for the |
90
|
|
|
|
|
|
|
L<Dist::Zilla::Role::FileMunger> role, munging each Perl file it finds. |
91
|
|
|
|
|
|
|
Files whose names do not end in C<.pm>, C<.pl>, or C<.t>, or whose contents |
92
|
|
|
|
|
|
|
do not begin with C<#!perl> are left alone. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head2 SYNOPSIS |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
# dist.ini |
97
|
|
|
|
|
|
|
[PerlTidy] |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
# or |
100
|
|
|
|
|
|
|
[PerlTidy] |
101
|
|
|
|
|
|
|
perltidyrc = xt/.perltidyrc |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head2 DEFAULTS |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
If you do not specify a specific perltidyrc in dist.ini it will try to use |
106
|
|
|
|
|
|
|
the same defaults as Perl::Tidy. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head2 SEE ALSO |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
L<Perl::Tidy> |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 AUTHORS |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=over 4 |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=item * |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
Fayland Lam <fayland@gmail.com> |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=item * |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Mark Gardner <mjgardner@cpan.org> |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=item * |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Kent Fredric <kentfredric@gmail.com> |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=back |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
This software is copyright (c) 2014 by Fayland Lam. |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
135
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=cut |