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