line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Goo::Thing::pm::PerlTidyManager; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
############################################################################### |
4
|
|
|
|
|
|
|
# Nigel Hamilton |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
# Copyright Nigel Hamilton 2005 |
7
|
|
|
|
|
|
|
# All Rights Reserved |
8
|
|
|
|
|
|
|
# |
9
|
|
|
|
|
|
|
# Author: Nigel Hamilton |
10
|
|
|
|
|
|
|
# Filename: Goo::Thing::pm::PerlTidyManager |
11
|
|
|
|
|
|
|
# Description: Tidy up a Perl program - make sure the indentation is correct |
12
|
|
|
|
|
|
|
# The tidy parameters are set on a per directory basis in the |
13
|
|
|
|
|
|
|
# perltidyrc file - if there is not one in the current directory |
14
|
|
|
|
|
|
|
# it looks in the home directory of the current user. |
15
|
|
|
|
|
|
|
# Update the perltidyrc file to change the main parts of perltidy. |
16
|
|
|
|
|
|
|
# The format is based on the Best Practices written by Damian |
17
|
|
|
|
|
|
|
# Conway - "Perl Best Practices".. |
18
|
|
|
|
|
|
|
# |
19
|
|
|
|
|
|
|
# Date Change |
20
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
21
|
|
|
|
|
|
|
# 05/09/2005 Auto generated file |
22
|
|
|
|
|
|
|
# 05/09/2005 Needed to wrap the Perl Tidy utility with my own options |
23
|
|
|
|
|
|
|
# |
24
|
|
|
|
|
|
|
############################################################################### |
25
|
|
|
|
|
|
|
|
26
|
1
|
|
|
1
|
|
8
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
40
|
|
27
|
|
|
|
|
|
|
|
28
|
1
|
|
|
1
|
|
7523
|
use Perl::Tidy; |
|
1
|
|
|
|
|
210669
|
|
|
1
|
|
|
|
|
122
|
|
29
|
1
|
|
|
1
|
|
9
|
use Goo::Prompter; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
20
|
|
30
|
1
|
|
|
1
|
|
5
|
use Goo::TabConverter; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
20
|
|
31
|
1
|
|
|
1
|
|
5
|
use Goo::FileUtilities; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
201
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
############################################################################### |
35
|
|
|
|
|
|
|
# |
36
|
|
|
|
|
|
|
# process - tidy a file |
37
|
|
|
|
|
|
|
# |
38
|
|
|
|
|
|
|
############################################################################### |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub process { |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
0
|
1
|
|
my ($filename) = @_; |
43
|
|
|
|
|
|
|
|
44
|
0
|
0
|
|
|
|
|
unless ( -e $filename ) { |
45
|
0
|
|
|
|
|
|
die("$filename does not exist. Unable to tidy."); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
my $tidy_file = $filename . ".tdy"; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# call perltidy on the file |
51
|
0
|
|
|
|
|
|
`perltidy -pro='$ENV{HOME}/.goo/perltidyrc' $filename > $tidy_file`; |
52
|
|
|
|
|
|
|
|
53
|
0
|
0
|
|
|
|
|
unless ( -e $tidy_file ) { |
54
|
0
|
|
|
|
|
|
Goo::Prompter::notify("perltidy failed to generate $tidy_file"); |
55
|
0
|
|
|
|
|
|
exit; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# add an extra space between subs |
59
|
|
|
|
|
|
|
# $file =~ s/^\}/\}\n/gms; |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
my @tidier_lines; |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
foreach my $line (Goo::FileUtilities::get_file_as_lines($tidy_file)) { |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# find any tabs in comments |
66
|
0
|
0
|
|
|
|
|
if ($line =~ /^\#.*\t/) { |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# convert tabs to 4 spaces |
69
|
0
|
|
|
|
|
|
$line = Goo::TabConverter::tabs_to_spaces($line, 4); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
push(@tidier_lines, $line); |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
Goo::FileUtilities::write_lines_as_file($filename, @tidier_lines); |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# remove the .tdy file |
79
|
0
|
|
|
|
|
|
unlink($tidy_file); |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
1; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
__END__ |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head1 NAME |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Goo::Thing::pm::PerlTidyManager - Tidy up a Perl program using PerlTidy |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 SYNOPSIS |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
use Goo::Thing::pm::PerlTidyManager; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 DESCRIPTION |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 METHODS |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=over |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=item process |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
tidy up a file after we've finished editing it |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=back |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 AUTHOR |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Nigel Hamilton <nigel@trexy.com> |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 SEE ALSO |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Perl::Tidy |