| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
2
|
|
|
2
|
|
827
|
use strict; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
120
|
|
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package HTML::FormFu::OutputProcessor::StripWhitespace; |
|
4
|
|
|
|
|
|
|
$HTML::FormFu::OutputProcessor::StripWhitespace::VERSION = '2.07'; |
|
5
|
|
|
|
|
|
|
# ABSTRACT: Strip shitespace from HTML output |
|
6
|
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
14
|
use Moose; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
16
|
|
|
8
|
2
|
|
|
2
|
|
14097
|
use MooseX::Attribute::Chained; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
83
|
|
|
9
|
|
|
|
|
|
|
extends 'HTML::FormFu::OutputProcessor'; |
|
10
|
|
|
|
|
|
|
|
|
11
|
2
|
|
|
2
|
|
13
|
use HTML::FormFu::Constants qw( $EMPTY_STR ); |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
267
|
|
|
12
|
2
|
|
|
2
|
|
528
|
use HTML::TokeParser::Simple; |
|
|
2
|
|
|
|
|
18597
|
|
|
|
2
|
|
|
|
|
76
|
|
|
13
|
2
|
|
|
2
|
|
13
|
use List::Util 1.33 qw( any ); |
|
|
2
|
|
|
|
|
48
|
|
|
|
2
|
|
|
|
|
1308
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has collapse_tags => ( |
|
16
|
|
|
|
|
|
|
is => 'rw', |
|
17
|
|
|
|
|
|
|
default => sub { |
|
18
|
|
|
|
|
|
|
[ qw( |
|
19
|
|
|
|
|
|
|
fieldset |
|
20
|
|
|
|
|
|
|
form |
|
21
|
|
|
|
|
|
|
hr |
|
22
|
|
|
|
|
|
|
legend |
|
23
|
|
|
|
|
|
|
optgroup |
|
24
|
|
|
|
|
|
|
option |
|
25
|
|
|
|
|
|
|
table |
|
26
|
|
|
|
|
|
|
td |
|
27
|
|
|
|
|
|
|
th |
|
28
|
|
|
|
|
|
|
tr |
|
29
|
|
|
|
|
|
|
) ]; |
|
30
|
|
|
|
|
|
|
}, |
|
31
|
|
|
|
|
|
|
lazy => 1, |
|
32
|
|
|
|
|
|
|
traits => ['Chained'], |
|
33
|
|
|
|
|
|
|
); |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
has collapse_consecutive_tags => ( |
|
36
|
|
|
|
|
|
|
is => 'rw', |
|
37
|
|
|
|
|
|
|
default => sub { |
|
38
|
|
|
|
|
|
|
[ qw( |
|
39
|
|
|
|
|
|
|
span |
|
40
|
|
|
|
|
|
|
div |
|
41
|
|
|
|
|
|
|
) ]; |
|
42
|
|
|
|
|
|
|
}, |
|
43
|
|
|
|
|
|
|
lazy => 1, |
|
44
|
|
|
|
|
|
|
traits => ['Chained'], |
|
45
|
|
|
|
|
|
|
); |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub process { |
|
48
|
27
|
|
|
27
|
0
|
58
|
my ( $self, $input ) = @_; |
|
49
|
|
|
|
|
|
|
|
|
50
|
27
|
|
|
|
|
131
|
my $parser = HTML::TokeParser::Simple->new( \$input ); |
|
51
|
27
|
|
|
|
|
3847
|
my @tokens; |
|
52
|
|
|
|
|
|
|
|
|
53
|
27
|
|
|
|
|
84
|
while ( my $token = $parser->get_token ) { |
|
54
|
676
|
|
|
|
|
20913
|
push @tokens, $token; |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
|
|
57
|
27
|
|
|
|
|
452
|
my $iter |
|
58
|
|
|
|
|
|
|
= HTML::FormFu::OutputProcessor::StripWhitespace::_iter->new(@tokens); |
|
59
|
|
|
|
|
|
|
|
|
60
|
27
|
|
|
|
|
51
|
my @collapse = @{ $self->collapse_tags }; |
|
|
27
|
|
|
|
|
1108
|
|
|
61
|
27
|
|
|
|
|
54
|
my @consecutive = @{ $self->collapse_consecutive_tags }; |
|
|
27
|
|
|
|
|
958
|
|
|
62
|
27
|
|
|
|
|
116
|
my $output = $EMPTY_STR; |
|
63
|
|
|
|
|
|
|
|
|
64
|
27
|
|
|
|
|
164
|
while ( defined( my $token = $iter->next ) ) { |
|
65
|
|
|
|
|
|
|
|
|
66
|
676
|
100
|
|
|
|
1435
|
if ( $token->is_start_tag ) { |
|
|
|
100
|
|
|
|
|
|
|
67
|
233
|
|
|
|
|
1327
|
my $tag = $token->get_tag; |
|
68
|
233
|
|
|
|
|
1618
|
my $prev_tag = $iter->prev_tag_name; |
|
69
|
|
|
|
|
|
|
|
|
70
|
233
|
100
|
|
2071
|
|
1900
|
if ( any { $tag eq $_ } @collapse ) { |
|
|
2071
|
50
|
|
|
|
3023
|
|
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# strip \s from before us |
|
73
|
80
|
|
|
|
|
654
|
$output =~ s/ \s+ \z //x; |
|
74
|
|
|
|
|
|
|
} |
|
75
|
|
|
|
|
|
|
elsif ( defined $prev_tag ) { |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# strip \s between <start> <start> |
|
78
|
153
|
|
|
|
|
284
|
for my $consec (@consecutive) { |
|
79
|
306
|
100
|
100
|
|
|
807
|
if ( $tag eq $consec && $tag eq $prev_tag ) { |
|
80
|
29
|
|
|
|
|
298
|
$output =~ s/ \s+ \z //x; |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
} |
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
elsif ( $token->is_end_tag ) { |
|
86
|
182
|
|
|
|
|
1377
|
my $tag = $token->get_tag; |
|
87
|
182
|
|
|
|
|
1264
|
my $prev_tag = $iter->prev_tag_name; |
|
88
|
|
|
|
|
|
|
|
|
89
|
182
|
100
|
|
1582
|
|
1500
|
if ( any { $tag eq $_ } @collapse ) { |
|
|
1582
|
50
|
|
|
|
2322
|
|
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
# strip \s from before us |
|
92
|
77
|
|
|
|
|
708
|
$output =~ s/ \s+ \z //x; |
|
93
|
|
|
|
|
|
|
} |
|
94
|
|
|
|
|
|
|
elsif ( defined $prev_tag ) { |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
# strip \s between </end> </end> |
|
97
|
105
|
|
|
|
|
190
|
for my $consec (@consecutive) { |
|
98
|
210
|
100
|
100
|
|
|
570
|
if ( $tag eq $consec && $tag eq $prev_tag ) { |
|
99
|
21
|
|
|
|
|
233
|
$output =~ s/ \s+ \z //x; |
|
100
|
|
|
|
|
|
|
} |
|
101
|
|
|
|
|
|
|
} |
|
102
|
|
|
|
|
|
|
} |
|
103
|
|
|
|
|
|
|
} |
|
104
|
|
|
|
|
|
|
|
|
105
|
676
|
|
|
|
|
2552
|
my $prev_tag = $iter->prev_tag_name; |
|
106
|
|
|
|
|
|
|
|
|
107
|
676
|
100
|
66
|
6083
|
|
5879
|
if ( defined $prev_tag && any { $prev_tag eq $_ } @collapse ) { |
|
|
6083
|
|
|
|
|
8821
|
|
|
108
|
208
|
|
|
|
|
1487
|
$output =~ s/ \s+ \z //x; |
|
109
|
|
|
|
|
|
|
|
|
110
|
208
|
|
|
|
|
479
|
my $part = $token->as_is; |
|
111
|
|
|
|
|
|
|
|
|
112
|
208
|
|
|
|
|
1205
|
$part =~ s/ ^ \s+ //x; |
|
113
|
|
|
|
|
|
|
|
|
114
|
208
|
|
|
|
|
658
|
$output .= $part; |
|
115
|
|
|
|
|
|
|
} |
|
116
|
|
|
|
|
|
|
else { |
|
117
|
468
|
|
|
|
|
1020
|
$output .= $token->as_is; |
|
118
|
|
|
|
|
|
|
} |
|
119
|
|
|
|
|
|
|
} |
|
120
|
|
|
|
|
|
|
|
|
121
|
27
|
|
|
|
|
1140
|
return $output; |
|
122
|
|
|
|
|
|
|
} |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
|
125
|
|
|
|
|
|
|
|
|
126
|
2
|
|
|
2
|
|
18
|
use strict; |
|
|
2
|
|
|
|
|
6
|
|
|
|
2
|
|
|
|
|
102
|
|
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
package HTML::FormFu::OutputProcessor::StripWhitespace::_iter; |
|
129
|
|
|
|
|
|
|
$HTML::FormFu::OutputProcessor::StripWhitespace::_iter::VERSION = '2.07'; |
|
130
|
2
|
|
|
2
|
|
21
|
use Moose; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
14
|
|
|
131
|
2
|
|
|
2
|
|
13923
|
use MooseX::Attribute::Chained; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
505
|
|
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub new { |
|
134
|
27
|
|
|
27
|
1
|
110
|
my ( $class, @tags ) = @_; |
|
135
|
|
|
|
|
|
|
|
|
136
|
27
|
|
|
|
|
90
|
my %self = ( |
|
137
|
|
|
|
|
|
|
tags => \@tags, |
|
138
|
|
|
|
|
|
|
i => 0, |
|
139
|
|
|
|
|
|
|
); |
|
140
|
|
|
|
|
|
|
|
|
141
|
27
|
|
|
|
|
83
|
return bless \%self, $class; |
|
142
|
|
|
|
|
|
|
} |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
sub next { |
|
145
|
703
|
|
|
703
|
0
|
3423
|
my ($self) = @_; |
|
146
|
|
|
|
|
|
|
|
|
147
|
703
|
|
|
|
|
1810
|
return $self->{tags}[ $self->{i}++ ]; |
|
148
|
|
|
|
|
|
|
} |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
sub prev_tag_name { |
|
151
|
1091
|
|
|
1091
|
0
|
1904
|
my ($self) = @_; |
|
152
|
|
|
|
|
|
|
|
|
153
|
1091
|
|
|
|
|
1764
|
my $i = $self->{i} - 2; |
|
154
|
|
|
|
|
|
|
|
|
155
|
1091
|
|
|
|
|
2592
|
while ( $i >= 0 ) { |
|
156
|
|
|
|
|
|
|
|
|
157
|
1557
|
100
|
|
|
|
3150
|
if ( $self->{tags}[$i]->is_tag ) { |
|
158
|
1037
|
50
|
|
|
|
8224
|
return if !$self->{tags}[$i]->is_tag; |
|
159
|
|
|
|
|
|
|
|
|
160
|
1037
|
|
|
|
|
8122
|
return $self->{tags}[$i]->get_tag; |
|
161
|
|
|
|
|
|
|
} |
|
162
|
|
|
|
|
|
|
|
|
163
|
520
|
|
|
|
|
1852
|
--$i; |
|
164
|
|
|
|
|
|
|
} |
|
165
|
|
|
|
|
|
|
} |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable( inline_constructor => 0 ); |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
1; |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
__END__ |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=pod |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=encoding UTF-8 |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=head1 NAME |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
HTML::FormFu::OutputProcessor::StripWhitespace - Strip shitespace from HTML output |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=head1 VERSION |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
version 2.07 |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
--- |
|
188
|
|
|
|
|
|
|
output_processors: |
|
189
|
|
|
|
|
|
|
- StripWhitespace |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=head1 METHODS |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=head2 collapse_tags |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=head2 collapse_consecutive_tags |
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
Is a sub-class of, and inherits methods from L<HTML::FormFu::OutputProcessor> |
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
L<HTML::FormFu> |
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=head1 AUTHOR |
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
Carl Franks C<cfranks@cpan.org> |
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=head1 LICENSE |
|
208
|
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
This library is free software, you can redistribute it and/or modify it under |
|
210
|
|
|
|
|
|
|
the same terms as Perl itself. |
|
211
|
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=head1 AUTHOR |
|
213
|
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
Carl Franks <cpan@fireartist.com> |
|
215
|
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
217
|
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
This software is copyright (c) 2018 by Carl Franks. |
|
219
|
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
221
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
222
|
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=cut |