line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Template::Plugin::PerlTidy; |
2
|
3
|
|
|
3
|
|
213350
|
use strict; |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
120
|
|
3
|
3
|
|
|
3
|
|
2719
|
use Template::Plugin::Filter; |
|
3
|
|
|
|
|
42901
|
|
|
3
|
|
|
|
|
99
|
|
4
|
3
|
|
|
3
|
|
28358
|
use Perl::Tidy; |
|
3
|
|
|
|
|
1126016
|
|
|
3
|
|
|
|
|
451
|
|
5
|
3
|
|
|
3
|
|
28
|
use base qw( Template::Plugin::Filter ); |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
359
|
|
6
|
3
|
|
|
3
|
|
16
|
use vars qw($VERSION); |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
168
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
$VERSION = 0.03; |
9
|
|
|
|
|
|
|
|
10
|
3
|
|
|
3
|
|
13
|
use vars qw( $DYNAMIC ); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
952
|
|
11
|
|
|
|
|
|
|
$DYNAMIC = 1; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=pod |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 NAME |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
Template::Plugin::PerlTidy - Perl::Tidy filter for Template Toolkit |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 SYNOPSIS |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# HTML Syntax Coloring, no reformatting |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
[% USE PerlTidy 'html' 'nnn' 'pre' %] |
24
|
|
|
|
|
|
|
[% FILTER $PerlTidy %] |
25
|
|
|
|
|
|
|
#!/usr/bin/perl -w |
26
|
|
|
|
|
|
|
use strict; |
27
|
|
|
|
|
|
|
my@foo=(1,2,'a',4); |
28
|
|
|
|
|
|
|
for(1,3,5){print" $_\n"}my %hash =( 1=>'foo',foo=>'bar',); |
29
|
|
|
|
|
|
|
[% END %] |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# Chained filter, code reformatting and syntax coloring |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
[%- USE PerlTidy -%] |
35
|
|
|
|
|
|
|
[%- FILTER $PerlTidy 'html' 'nnn' -%] |
36
|
|
|
|
|
|
|
[%- FILTER $PerlTidy i=10 -%] |
37
|
|
|
|
|
|
|
... perl code goes here ... |
38
|
|
|
|
|
|
|
[%- END -%] |
39
|
|
|
|
|
|
|
[%- END -%] |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 DESCRIPTION |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
This modules is a Template Toolkit Filter for Perl::Tidy. It can be used |
44
|
|
|
|
|
|
|
to automatically display coloured and formatted perl code in web pages. |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head1 OPTIONS |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
All the options available in perltidy should be also available in |
49
|
|
|
|
|
|
|
this plugin. |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
The options defined in Perl::Tidy::perltidy() are also supported |
52
|
|
|
|
|
|
|
(C<stderr>, C<perltidyrc>, C<logfile>, C<errorfile>). The C<source> and |
53
|
|
|
|
|
|
|
<destination> options are handled by the filter. |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
By default, the C<quiet> option is turned on, but you can disable it |
56
|
|
|
|
|
|
|
using the C<verbose> option. |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
Note that options which does not take any arguments (like -html or -pre) |
59
|
|
|
|
|
|
|
should be enclosed in quotes (i.e. C<[% USE PerlTidy 'html' %]>), and |
60
|
|
|
|
|
|
|
options which take an argument are not enclosed in quotes (i.e. C<[% USE |
61
|
|
|
|
|
|
|
PerlTidy i=8 %]>). |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=cut |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub filter { |
66
|
2
|
|
|
2
|
0
|
448
|
my ( $self, $text, $args, $conf ) = @_; |
67
|
|
|
|
|
|
|
|
68
|
2
|
|
|
|
|
21
|
$args = $self->merge_args($args); |
69
|
2
|
|
|
|
|
30
|
$conf = $self->merge_config($conf); |
70
|
|
|
|
|
|
|
|
71
|
2
|
|
|
|
|
17
|
my %options = %{$conf}; |
|
2
|
|
|
|
|
7
|
|
72
|
|
|
|
|
|
|
|
73
|
2
|
|
|
|
|
6
|
my ( $stderr, $perltidyrc, $logfile, $errorfile ) = |
74
|
|
|
|
|
|
|
@options{qw( stderr perltidyrc logfile errorfile )}; |
75
|
|
|
|
|
|
|
|
76
|
2
|
|
|
|
|
4
|
delete @options{qw( stderr perltidyrc logfile errorfile )}; |
77
|
|
|
|
|
|
|
|
78
|
2
|
|
|
|
|
4
|
foreach my $args ( @{$args} ) { |
|
2
|
|
|
|
|
6
|
|
79
|
6
|
50
|
|
|
|
29
|
$options{$args} = undef unless exists $options{$args}; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
2
|
|
|
|
|
4
|
my $argv; |
83
|
2
|
|
|
|
|
7
|
foreach my $key ( keys %options ) { |
84
|
6
|
50
|
|
|
|
16
|
next if $key eq 'verbose'; |
85
|
6
|
50
|
|
|
|
23
|
$argv .= $options{$key} ? qq' -$key="$options{$key}"' : " -$key"; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
2
|
50
|
|
|
|
14
|
if ( ! exists $options{verbose} ){ |
89
|
2
|
|
|
|
|
6
|
$argv .= ' -q'; # be quiet by default |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
2
|
|
|
|
|
2
|
my $formated; |
93
|
2
|
|
|
|
|
12
|
perltidy( |
94
|
|
|
|
|
|
|
source => \$text, |
95
|
|
|
|
|
|
|
destination => \$formated, |
96
|
|
|
|
|
|
|
argv => $argv, |
97
|
|
|
|
|
|
|
stderr => $stderr, |
98
|
|
|
|
|
|
|
perltidyrc => $perltidyrc, |
99
|
|
|
|
|
|
|
logfile => $logfile, |
100
|
|
|
|
|
|
|
errorfile => $errorfile, |
101
|
|
|
|
|
|
|
); |
102
|
|
|
|
|
|
|
|
103
|
2
|
|
|
|
|
488564
|
return $formated; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
1; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
__END__ |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=pod |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 BUGS |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Please report any bugs or comments using the Request Tracker interface: |
115
|
|
|
|
|
|
|
L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Template%3A%3APlugin%3A%3APerlTidy> |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head1 AUTHOR |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
Briac Pilpré <briac@cpan.org> |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Thanks to Steve Hancock for PerlTidy |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Thanks to BooK and echo for their help. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 COPYRIGHT |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
This module is distributed under the same terms as perl itself. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 SEE ALSO |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Template::Plugin::Filter, Perl::Tidy |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=cut |
135
|
|
|
|
|
|
|
|