| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Mason::Tidy::App; |
|
2
|
|
|
|
|
|
|
BEGIN { |
|
3
|
1
|
|
|
1
|
|
20
|
$Mason::Tidy::App::VERSION = '2.57'; |
|
4
|
|
|
|
|
|
|
} |
|
5
|
1
|
|
|
1
|
|
6
|
use Config; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
38
|
|
|
6
|
1
|
|
|
1
|
|
5
|
use File::Slurp; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
80
|
|
|
7
|
1
|
|
|
1
|
|
5
|
use Getopt::Long; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
8
|
|
|
8
|
1
|
|
|
1
|
|
146
|
use Mason::Tidy; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
20
|
|
|
9
|
1
|
|
|
1
|
|
6
|
use Method::Signatures::Simple; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
9
|
|
|
10
|
1
|
|
|
1
|
|
418
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
37
|
|
|
11
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
|
1
|
|
|
|
|
8
|
|
|
|
1
|
|
|
|
|
65
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my $usage = 'Usage: masontidy [options] [file] ... |
|
14
|
|
|
|
|
|
|
See https://metacpan.org/module/masontidy for full documentation. |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
Options: |
|
17
|
|
|
|
|
|
|
-h, --help Print help message |
|
18
|
|
|
|
|
|
|
-m <1|2> Mason major version - required |
|
19
|
|
|
|
|
|
|
-p, --pipe Pipe from stdin to stdout |
|
20
|
|
|
|
|
|
|
-r, --replace Replace file(s) in-place |
|
21
|
|
|
|
|
|
|
-indent-block <num> Number of spaces to initially indent code block lines |
|
22
|
|
|
|
|
|
|
-indent-perl-block <num> Number of spaces to initially indent <%perl> block lines |
|
23
|
|
|
|
|
|
|
-perltidy-argv=<argv> perltidy arguments to use everywhere |
|
24
|
|
|
|
|
|
|
-perltidy-block-argv=<argv> perltidy arguments to use for code blocks |
|
25
|
|
|
|
|
|
|
-perltidy-line-argv=<argv> perltidy arguments to use for %-lines |
|
26
|
|
|
|
|
|
|
-perltidy-tag-argv=<argv> perltidy arguments to use for <% %> and <& &> tags |
|
27
|
|
|
|
|
|
|
--version Print version |
|
28
|
|
|
|
|
|
|
'; |
|
29
|
|
|
|
|
|
|
|
|
30
|
1
|
|
|
1
|
|
428
|
func usage ($msg) { |
|
|
5
|
|
|
5
|
|
10
|
|
|
|
5
|
|
|
|
|
9
|
|
|
31
|
5
|
50
|
|
|
|
25
|
my $full_msg = ( $msg ? "$msg\n" : "" ) . $usage; |
|
32
|
5
|
|
|
|
|
42
|
die $full_msg; |
|
33
|
|
|
|
|
|
|
} |
|
34
|
|
|
|
|
|
|
|
|
35
|
1
|
|
|
1
|
|
490
|
func version () { |
|
|
0
|
|
|
0
|
|
0
|
|
|
36
|
0
|
|
0
|
|
|
0
|
my $version = $Mason::Tidy::VERSION || 'unknown'; |
|
37
|
0
|
|
|
|
|
0
|
print "masontidy $version on perl $] built for $Config{archname}\n"; |
|
38
|
0
|
|
|
|
|
0
|
exit; |
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
|
|
41
|
1
|
|
|
1
|
|
438
|
method run () { |
|
|
9
|
|
|
9
|
|
18
|
|
|
|
9
|
|
|
|
|
14
|
|
|
42
|
9
|
|
|
|
|
33
|
my @argv = @ARGV; |
|
43
|
9
|
50
|
|
|
|
42
|
if ( my $envvar = $ENV{MASONTIDY_OPT} ) { |
|
44
|
0
|
|
|
|
|
0
|
push( @argv, split( /\s+/, $envvar ) ); |
|
45
|
|
|
|
|
|
|
} |
|
46
|
9
|
|
|
|
|
15
|
my $source = $_[0]; |
|
47
|
9
|
0
|
33
|
|
|
30
|
usage() if !@argv && !$source; |
|
48
|
|
|
|
|
|
|
|
|
49
|
9
|
|
|
|
|
16
|
my ( %params, $help, $pipe, $replace, $version ); |
|
50
|
|
|
|
|
|
|
{ |
|
51
|
9
|
|
|
|
|
13
|
local @ARGV = @argv; |
|
|
9
|
|
|
|
|
58
|
|
|
52
|
9
|
50
|
|
|
|
109
|
GetOptions( |
|
53
|
|
|
|
|
|
|
'h|help' => \$help, |
|
54
|
|
|
|
|
|
|
'm|mason-version=i' => \$params{mason_version}, |
|
55
|
|
|
|
|
|
|
'p|pipe' => \$pipe, |
|
56
|
|
|
|
|
|
|
'r|replace' => \$replace, |
|
57
|
|
|
|
|
|
|
'indent-block=i' => \$params{indent_block}, |
|
58
|
|
|
|
|
|
|
'indent-perl-block=i' => \$params{indent_perl_block}, |
|
59
|
|
|
|
|
|
|
'perltidy-argv=s' => \$params{perltidy_argv}, |
|
60
|
|
|
|
|
|
|
'perltidy-block-argv=s' => \$params{perltidy_block_argv}, |
|
61
|
|
|
|
|
|
|
'perltidy-line-argv=s' => \$params{perltidy_line_argv}, |
|
62
|
|
|
|
|
|
|
'perltidy-tag-argv=s' => \$params{perltidy_tag_argv}, |
|
63
|
|
|
|
|
|
|
'version' => \$version, |
|
64
|
|
|
|
|
|
|
) or usage(); |
|
65
|
9
|
|
|
|
|
8710
|
@argv = @ARGV; |
|
66
|
|
|
|
|
|
|
} |
|
67
|
9
|
|
|
|
|
33
|
%params = map { ( $_, $params{$_} ) } grep { defined( $params{$_} ) } keys(%params); |
|
|
16
|
|
|
|
|
60
|
|
|
|
63
|
|
|
|
|
120
|
|
|
68
|
|
|
|
|
|
|
|
|
69
|
9
|
50
|
|
|
|
34
|
version() if $version; |
|
70
|
9
|
50
|
|
|
|
24
|
usage() if $help; |
|
71
|
9
|
100
|
|
|
|
26
|
usage("-m|mason-version required (1 or 2)") unless defined( $params{mason_version} ); |
|
72
|
8
|
100
|
|
|
|
41
|
usage("-m|mason-version must be 1 or 2") unless $params{mason_version} =~ /^[12]$/; |
|
73
|
7
|
100
|
66
|
|
|
37
|
usage("-p|--pipe not compatible with filenames") if $pipe && @argv; |
|
74
|
6
|
50
|
33
|
|
|
36
|
usage("must pass either filenames or -p|--pipe") if !$pipe && !@argv && !defined($source); |
|
|
|
|
66
|
|
|
|
|
|
75
|
5
|
100
|
100
|
|
|
27
|
usage("must pass -r/--replace with multiple filenames") if @argv > 1 && !$replace; |
|
76
|
|
|
|
|
|
|
|
|
77
|
4
|
|
|
|
|
133
|
my $mt = Mason::Tidy->new(%params); |
|
78
|
4
|
50
|
|
|
|
38
|
if ( defined($source) ) { |
|
|
|
50
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
0
|
return $mt->tidy($source); |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
elsif ($pipe) { |
|
82
|
0
|
|
|
|
|
0
|
my $source = do { local $/; <STDIN> }; |
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
83
|
0
|
|
|
|
|
0
|
print $mt->tidy($source); |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
else { |
|
86
|
4
|
|
|
|
|
43
|
foreach my $file (@argv) { |
|
87
|
5
|
100
|
|
|
|
364
|
print "$file\n" if @argv > 1; |
|
88
|
5
|
|
|
|
|
31
|
my $source = read_file($file); |
|
89
|
5
|
|
|
|
|
666
|
my $dest = $mt->tidy($source); |
|
90
|
5
|
100
|
|
|
|
19
|
if ($replace) { |
|
91
|
2
|
|
|
|
|
15
|
write_file( $file, $dest ); |
|
92
|
|
|
|
|
|
|
} |
|
93
|
|
|
|
|
|
|
else { |
|
94
|
3
|
|
|
|
|
325
|
print $dest; |
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
} |
|
97
|
|
|
|
|
|
|
} |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
1; |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=pod |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 NAME |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
Mason::Tidy::App - Implements masontidy command |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 VERSION |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
version 2.57 |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
L<masontidy>, L<Mason::Tidy> |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 AUTHOR |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Jonathan Swartz <swartz@pobox.com> |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
This software is copyright (c) 2011 by Jonathan Swartz. |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
127
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=cut |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
__END__ |
|
133
|
|
|
|
|
|
|
|