line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package PerlTidy::Run; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# all interactions with Perl::Tidy are via this module |
4
|
2
|
|
|
2
|
|
12
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
71
|
|
5
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
52
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
12
|
use Data::Dumper; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
102
|
|
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
2475
|
use Log::Log4perl qw(get_logger); |
|
2
|
|
|
|
|
122309
|
|
|
2
|
|
|
|
|
14
|
|
10
|
|
|
|
|
|
|
|
11
|
2
|
|
|
2
|
|
12769
|
use Perl::Tidy; |
|
2
|
|
|
|
|
473663
|
|
|
2
|
|
|
|
|
269
|
|
12
|
|
|
|
|
|
|
|
13
|
2
|
|
|
2
|
|
662
|
use TidyView::Options; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
411
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub execute { |
16
|
0
|
|
|
0
|
0
|
0
|
my (undef, %args) = @_; |
17
|
|
|
|
|
|
|
|
18
|
0
|
|
|
|
|
0
|
my ($fileToTidy) = @args{qw(file)}; |
19
|
|
|
|
|
|
|
|
20
|
0
|
|
|
|
|
0
|
my $options = TidyView::Options->assembleOptions(separator => "\n"); |
21
|
|
|
|
|
|
|
|
22
|
0
|
|
|
|
|
0
|
my $resultString = ""; |
23
|
0
|
|
|
|
|
0
|
my $argv = ""; # prevent perltidy from seeing our @ARGV |
24
|
0
|
|
|
|
|
0
|
my $stderrCapture = ""; # possible error output here |
25
|
|
|
|
|
|
|
|
26
|
0
|
|
|
|
|
0
|
Perl::Tidy::perltidy( |
27
|
|
|
|
|
|
|
argv => \$argv, |
28
|
|
|
|
|
|
|
stderr => \$stderrCapture, |
29
|
|
|
|
|
|
|
perltidyrc => \$options, |
30
|
|
|
|
|
|
|
source => $fileToTidy, |
31
|
|
|
|
|
|
|
destination => \$resultString |
32
|
|
|
|
|
|
|
); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
|
35
|
0
|
0
|
|
|
|
0
|
return wantarray ? split(/^/m, $resultString) : $resultString; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# get all the option names, types, ranges and defaults from Perl::Tidy, and place them various data structures |
39
|
|
|
|
|
|
|
# for PerlTidy::Options to work with from then on |
40
|
|
|
|
|
|
|
sub collectOptionStructures { |
41
|
1
|
|
|
1
|
0
|
7
|
my (undef, %args) = @_; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
#cant create a logger - this function is called in an INIT block, so no initialisation has occurred |
44
|
|
|
|
|
|
|
|
45
|
1
|
|
|
|
|
6
|
my ($nameType, $nameSection, $nameRange, $nameDefault, $sectionNameType, $sectionList) = @args{qw(types |
46
|
|
|
|
|
|
|
sections |
47
|
|
|
|
|
|
|
ranges |
48
|
|
|
|
|
|
|
defaults |
49
|
|
|
|
|
|
|
sectionNameType |
50
|
|
|
|
|
|
|
sectionList |
51
|
|
|
|
|
|
|
) |
52
|
|
|
|
|
|
|
}; |
53
|
|
|
|
|
|
|
|
54
|
1
|
|
|
|
|
2
|
my $stderrCapture = ""; |
55
|
1
|
|
|
|
|
2
|
my $argv = ""; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# get the option names, ranges, types and defaults from Perl::Tidy |
58
|
|
|
|
|
|
|
|
59
|
1
|
|
|
|
|
9
|
Perl::Tidy::perltidy( |
60
|
|
|
|
|
|
|
dump_getopt_flags => $nameType, # gives the option => type map |
61
|
|
|
|
|
|
|
dump_options_category => $nameSection, # gives the option => section map |
62
|
|
|
|
|
|
|
dump_options_range => $nameRange, # gives the option => range map |
63
|
|
|
|
|
|
|
dump_options => $nameDefault, # gives the option => default map |
64
|
|
|
|
|
|
|
dump_options_type => 'full', # get map for all options, not just parsed ones |
65
|
|
|
|
|
|
|
stderr => \$stderrCapture, |
66
|
|
|
|
|
|
|
argv => \$argv, |
67
|
|
|
|
|
|
|
); |
68
|
|
|
|
|
|
|
|
69
|
1
|
50
|
|
|
|
89965
|
die "error calling Perl::Tidy::perltidy :: $stderrCapture" if $stderrCapture; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# extract the sections |
72
|
1
|
|
|
|
|
27
|
foreach my $name (keys %$nameSection) { |
73
|
|
|
|
|
|
|
# we need to ignore a few options for now - eventually these kind of policy decisions may be inside Perl::Tidy::perltidy() |
74
|
|
|
|
|
|
|
|
75
|
245
|
100
|
|
|
|
581
|
next if $name =~ m/^(?:entab-leading-whitespace | |
76
|
|
|
|
|
|
|
starting-indentation-level | |
77
|
|
|
|
|
|
|
output-line-ending | |
78
|
|
|
|
|
|
|
tabs | |
79
|
|
|
|
|
|
|
preserve-line-endings |
80
|
|
|
|
|
|
|
)/x; |
81
|
|
|
|
|
|
|
|
82
|
240
|
|
|
|
|
210
|
my $type; |
83
|
|
|
|
|
|
|
|
84
|
240
|
50
|
|
|
|
361
|
unless (exists $nameType->{$name}) { |
85
|
0
|
|
|
|
|
0
|
warn( "Unknown value type for option $name" ); |
86
|
|
|
|
|
|
|
} else { |
87
|
240
|
|
|
|
|
301
|
$type = $nameType->{$name}; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
240
|
100
|
66
|
|
|
754
|
if (exists $nameRange->{$name} and |
|
|
|
66
|
|
|
|
|
91
|
|
|
|
|
|
|
defined $nameRange->{$name} and |
92
|
|
|
|
|
|
|
ref($nameRange->{$name}) =~ m/^ARRAY$/) { |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
# replace with the more specific range type |
95
|
20
|
|
|
|
|
56
|
$sectionNameType->{$nameSection->{$name}}->{$name} = $nameRange->{$name}; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
} else { |
98
|
|
|
|
|
|
|
|
99
|
220
|
|
|
|
|
574
|
$sectionNameType->{$nameSection->{$name}}->{$name} = $type; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
{ |
106
|
1
|
|
|
1
|
|
6
|
no warnings 'numeric'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
201
|
|
|
1
|
|
|
|
|
13
|
|
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
# we take advantage of the fact that sections have the form "number. name" |
109
|
|
|
|
|
|
|
|
110
|
1
|
|
|
|
|
9
|
@$sectionList = sort {$a <=> $b} keys %$sectionNameType; |
|
39
|
|
|
|
|
66
|
|
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
# delete from sections list as that appears inthe GUI, but dont delete from sectionNameType as we |
114
|
|
|
|
|
|
|
# use that to test if a parsed option is unsupported |
115
|
|
|
|
|
|
|
|
116
|
1
|
|
|
|
|
3
|
shift @$sectionList; # drop off first section "I/O control" |
117
|
1
|
|
|
|
|
12
|
pop @$sectionList; # drop off last section "Debugging" |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
# given a file handle, ask Perl::Tidy to parse the file and report on any problems |
122
|
|
|
|
|
|
|
sub parseConfig { |
123
|
0
|
|
|
0
|
0
|
|
my (undef, %args) = @_; |
124
|
|
|
|
|
|
|
|
125
|
0
|
|
|
|
|
|
my ($fileHandle, $destination, ) = @args{qw(handle destination)}; |
126
|
|
|
|
|
|
|
|
127
|
0
|
|
|
|
|
|
my $stderrCapture = ""; # try to capture error messages |
128
|
0
|
|
|
|
|
|
my $argv = ""; # do not let perltidy see our @ARGV |
129
|
|
|
|
|
|
|
|
130
|
0
|
|
|
|
|
|
Perl::Tidy::perltidy( |
131
|
|
|
|
|
|
|
perltidyrc => $fileHandle, |
132
|
|
|
|
|
|
|
dump_options => $destination, |
133
|
|
|
|
|
|
|
stderr => \$stderrCapture, |
134
|
|
|
|
|
|
|
argv => \$argv, |
135
|
|
|
|
|
|
|
); |
136
|
|
|
|
|
|
|
|
137
|
0
|
|
|
|
|
|
return $stderrCapture; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
1; |