line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
3
|
|
|
3
|
|
1316
|
use strict; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
208
|
|
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package HTML::FormFu::OutputProcessor::Indent; |
4
|
|
|
|
|
|
|
$HTML::FormFu::OutputProcessor::Indent::VERSION = '2.07'; |
5
|
|
|
|
|
|
|
# ABSTRACT: Nicely Indent HTML Output |
6
|
|
|
|
|
|
|
|
7
|
3
|
|
|
3
|
|
19
|
use Moose; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
25
|
|
8
|
3
|
|
|
3
|
|
21968
|
use MooseX::Attribute::Chained; |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
139
|
|
9
|
|
|
|
|
|
|
extends 'HTML::FormFu::OutputProcessor'; |
10
|
|
|
|
|
|
|
|
11
|
3
|
|
|
3
|
|
18
|
use HTML::FormFu::Constants qw( $EMPTY_STR $SPACE ); |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
405
|
|
12
|
3
|
|
|
3
|
|
1975
|
use HTML::TokeParser::Simple; |
|
3
|
|
|
|
|
55678
|
|
|
3
|
|
|
|
|
146
|
|
13
|
3
|
|
|
3
|
|
27
|
use List::Util 1.33 qw( any ); |
|
3
|
|
|
|
|
91
|
|
|
3
|
|
|
|
|
1879
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has indent => ( |
16
|
|
|
|
|
|
|
is => 'rw', |
17
|
|
|
|
|
|
|
default => "\t", |
18
|
|
|
|
|
|
|
lazy => 1, |
19
|
|
|
|
|
|
|
traits => ['Chained'], |
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
has preserve_tags => ( |
23
|
|
|
|
|
|
|
is => 'rw', |
24
|
|
|
|
|
|
|
default => sub { [qw( pre textarea )] }, |
25
|
|
|
|
|
|
|
lazy => 1, |
26
|
|
|
|
|
|
|
traits => ['Chained'], |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub process { |
30
|
5
|
|
|
5
|
0
|
22
|
my ( $self, $input ) = @_; |
31
|
|
|
|
|
|
|
|
32
|
5
|
|
|
|
|
162
|
my $indent = $self->indent; |
33
|
|
|
|
|
|
|
|
34
|
5
|
|
|
|
|
31
|
my $parser = HTML::TokeParser::Simple->new( \$input ); |
35
|
|
|
|
|
|
|
|
36
|
5
|
|
|
|
|
889
|
my @preserve_tags = @{ $self->preserve_tags }; |
|
5
|
|
|
|
|
183
|
|
37
|
5
|
|
|
|
|
11
|
my $count = 0; |
38
|
5
|
|
|
|
|
10
|
my $in_pre = 0; |
39
|
5
|
|
|
|
|
24
|
my $output = $EMPTY_STR; |
40
|
|
|
|
|
|
|
|
41
|
5
|
|
|
|
|
40
|
while ( my $token = $parser->get_token ) { |
42
|
|
|
|
|
|
|
|
43
|
116
|
100
|
|
|
|
8325
|
if ( $token->is_start_tag ) { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
44
|
33
|
|
|
|
|
210
|
my $tag = $token->get_tag; |
45
|
|
|
|
|
|
|
|
46
|
33
|
100
|
|
65
|
|
329
|
if ( any { $tag eq $_ } @preserve_tags ) { |
|
65
|
|
|
|
|
125
|
|
47
|
7
|
|
|
|
|
17
|
$in_pre = 1; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
33
|
|
|
|
|
115
|
$output .= $indent x $count; |
51
|
33
|
|
|
|
|
78
|
$output .= $token->as_is; |
52
|
|
|
|
|
|
|
|
53
|
33
|
100
|
100
|
|
|
205
|
if ( !defined $token->get_attrseq->[-1] |
54
|
|
|
|
|
|
|
|| $token->get_attrseq->[-1] ne "/" ) |
55
|
|
|
|
|
|
|
{ |
56
|
28
|
|
|
|
|
483
|
$count++; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
elsif ( $token->is_end_tag ) { |
60
|
28
|
|
|
|
|
227
|
my $tag = $token->get_tag; |
61
|
|
|
|
|
|
|
|
62
|
28
|
|
|
|
|
189
|
$count--; |
63
|
|
|
|
|
|
|
|
64
|
28
|
100
|
100
|
|
|
207
|
if ( $output =~ m/ > \s* \z /x && !$in_pre ) { |
65
|
15
|
|
|
|
|
72
|
$output .= "\n" . $indent x $count; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
28
|
100
|
|
55
|
|
127
|
if ( any { $tag eq $_ } @preserve_tags ) { |
|
55
|
|
|
|
|
111
|
|
69
|
7
|
|
|
|
|
11
|
$in_pre = 0; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
28
|
|
|
|
|
96
|
$output .= $token->as_is; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
elsif ( $token->is_text ) { |
75
|
55
|
|
|
|
|
456
|
my $text = $token->as_is; |
76
|
|
|
|
|
|
|
|
77
|
55
|
100
|
100
|
|
|
223
|
if ( length $parser->peek && !$in_pre ) { |
78
|
49
|
|
|
|
|
3086
|
$text =~ s/\A\s+/ /; |
79
|
49
|
|
|
|
|
154
|
$text =~ s/\s+\z/ /; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
55
|
100
|
66
|
|
|
482
|
if ( $text eq $SPACE && $parser->peek =~ m/ < /x ) { |
83
|
43
|
|
|
|
|
2780
|
$text = $EMPTY_STR; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
55
|
|
|
|
|
275
|
$output .= $text; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
else { |
89
|
0
|
|
|
|
|
0
|
$output .= $token->as_is; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
116
|
100
|
66
|
|
|
457
|
if ( $parser->peek =~ m{ < (?!/) }x && !$in_pre ) { |
93
|
28
|
|
|
|
|
1735
|
$output .= "\n"; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
5
|
|
|
|
|
302
|
return $output; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
1; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
__END__ |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=pod |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=encoding UTF-8 |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 NAME |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
HTML::FormFu::OutputProcessor::Indent - Nicely Indent HTML Output |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 VERSION |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
version 2.07 |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 SYNOPSIS |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
--- |
121
|
|
|
|
|
|
|
output_processors: |
122
|
|
|
|
|
|
|
- Indent |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 METHODS |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head2 indent |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Arguments: $string |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
Default Value: "\t" |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
The string to be used to indent the HTML. |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head2 preserve_tags |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Arguments: \@tags |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Default Value: ['pre', 'textarea'] |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
An arrayref of tag names who's contents should not be processed. |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 SEE ALSO |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
Is a sub-class of, and inherits methods from L<HTML::FormFu::OutputProcessor> |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
L<HTML::FormFu> |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head1 AUTHOR |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
Carl Franks C<cfranks@cpan.org> |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head1 LICENSE |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
This library is free software, you can redistribute it and/or modify it under |
155
|
|
|
|
|
|
|
the same terms as Perl itself. |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head1 AUTHOR |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
Carl Franks <cpan@fireartist.com> |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
This software is copyright (c) 2018 by Carl Franks. |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
166
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=cut |