-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtidy_project.pl
executable file
·65 lines (52 loc) · 1.59 KB
/
tidy_project.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env perl
use strict;
use warnings;
eval("require Perl::Tidy");
if ($@) {
die "Please install Perl::Tidy (e.g. cpan Perl::Tidy)";
}
my $ver = '20120714';
if ( $Perl::Tidy::VERSION ne $ver ) {
die "Please install version $ver of Perl::Tidy";
# Make sure everyone uses the exact same version!
}
#
use Cwd qw{ cwd };
use File::Spec::Functions qw{ catfile catdir };
use File::Find::Rule;
use FindBin qw{ $Bin };
# check if perltidyrc file exists
my $perltidyrc = catfile( $Bin, 'perltidyrc' );
die "cannot find perltidy configuration file: $perltidyrc\n"
unless -e $perltidyrc;
# build list of perl files to reformat
my @pmfiles =
@ARGV
? @ARGV
: grep {/^lib/} File::Find::Rule->file->name("*.pm")->relative->in(cwd);
my @tfiles =
@ARGV
? @ARGV
: grep {/^x?t/} File::Find::Rule->file->name("*.t")->relative->in(cwd);
my @incfiles =
@ARGV
? @ARGV
: grep {/^inc/} File::Find::Rule->file->name("*.pm")->relative->in(cwd);
my @examples =
@ARGV
? @ARGV
: grep {/^share.examples/} File::Find::Rule->file->name("*.pl")->relative->in(cwd);
my @files = ( @pmfiles, @tfiles, @incfiles, @examples );
my @extras = ( 'Makefile.PL', 'Build.PL', 'dev', 'script/padre', );
for my $extra (@extras) {
push @files, $extra if -f $extra;
}
# skip autogenerated perl files in the Padre::Wx::FBP name space
@files = grep { $_ !~ m{/Padre/Wx/FBP} } @files;
# formatting documents
eval { Perl::Tidy::perltidy( argv => "--backup-and-modify-in-place --profile=$perltidyrc @files" ); };
if ($@) {
print "Perl::Tidy failed with the following error:\n$@\n";
}
# removing backup files
unlink map {"$_.bak"} @files;