line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::FormFu::OutputProcessor::StripWhitespace; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
549
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
130
|
|
4
|
|
|
|
|
|
|
our $VERSION = '2.05'; # VERSION |
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
46
|
use Moose; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
14
|
|
7
|
2
|
|
|
2
|
|
8400
|
use MooseX::Attribute::FormFuChained; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
63
|
|
8
|
|
|
|
|
|
|
extends 'HTML::FormFu::OutputProcessor'; |
9
|
|
|
|
|
|
|
|
10
|
2
|
|
|
2
|
|
6
|
use HTML::FormFu::Constants qw( $EMPTY_STR ); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
186
|
|
11
|
2
|
|
|
2
|
|
564
|
use HTML::TokeParser::Simple; |
|
2
|
|
|
|
|
13850
|
|
|
2
|
|
|
|
|
59
|
|
12
|
2
|
|
|
2
|
|
10
|
use List::Util 1.33 qw( any ); |
|
2
|
|
|
|
|
196
|
|
|
2
|
|
|
|
|
941
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has collapse_tags => ( |
15
|
|
|
|
|
|
|
is => 'rw', |
16
|
|
|
|
|
|
|
default => sub { |
17
|
|
|
|
|
|
|
[ qw( |
18
|
|
|
|
|
|
|
fieldset |
19
|
|
|
|
|
|
|
form |
20
|
|
|
|
|
|
|
hr |
21
|
|
|
|
|
|
|
legend |
22
|
|
|
|
|
|
|
optgroup |
23
|
|
|
|
|
|
|
option |
24
|
|
|
|
|
|
|
table |
25
|
|
|
|
|
|
|
td |
26
|
|
|
|
|
|
|
th |
27
|
|
|
|
|
|
|
tr |
28
|
|
|
|
|
|
|
) ]; |
29
|
|
|
|
|
|
|
}, |
30
|
|
|
|
|
|
|
lazy => 1, |
31
|
|
|
|
|
|
|
traits => ['FormFuChained'], |
32
|
|
|
|
|
|
|
); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
has collapse_consecutive_tags => ( |
35
|
|
|
|
|
|
|
is => 'rw', |
36
|
|
|
|
|
|
|
default => sub { |
37
|
|
|
|
|
|
|
[ qw( |
38
|
|
|
|
|
|
|
span |
39
|
|
|
|
|
|
|
div |
40
|
|
|
|
|
|
|
) ]; |
41
|
|
|
|
|
|
|
}, |
42
|
|
|
|
|
|
|
lazy => 1, |
43
|
|
|
|
|
|
|
traits => ['FormFuChained'], |
44
|
|
|
|
|
|
|
); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub process { |
47
|
27
|
|
|
27
|
0
|
32
|
my ( $self, $input ) = @_; |
48
|
|
|
|
|
|
|
|
49
|
27
|
|
|
|
|
72
|
my $parser = HTML::TokeParser::Simple->new( \$input ); |
50
|
27
|
|
|
|
|
2361
|
my @tokens; |
51
|
|
|
|
|
|
|
|
52
|
27
|
|
|
|
|
62
|
while ( my $token = $parser->get_token ) { |
53
|
676
|
|
|
|
|
10456
|
push @tokens, $token; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
27
|
|
|
|
|
239
|
my $iter |
57
|
|
|
|
|
|
|
= HTML::FormFu::OutputProcessor::StripWhitespace::_iter->new(@tokens); |
58
|
|
|
|
|
|
|
|
59
|
27
|
|
|
|
|
18
|
my @collapse = @{ $self->collapse_tags }; |
|
27
|
|
|
|
|
882
|
|
60
|
27
|
|
|
|
|
28
|
my @consecutive = @{ $self->collapse_consecutive_tags }; |
|
27
|
|
|
|
|
766
|
|
61
|
27
|
|
|
|
|
77
|
my $output = $EMPTY_STR; |
62
|
|
|
|
|
|
|
|
63
|
27
|
|
|
|
|
95
|
while ( defined( my $token = $iter->next ) ) { |
64
|
|
|
|
|
|
|
|
65
|
676
|
100
|
|
|
|
890
|
if ( $token->is_start_tag ) { |
|
|
100
|
|
|
|
|
|
66
|
233
|
|
|
|
|
998
|
my $tag = $token->get_tag; |
67
|
233
|
|
|
|
|
880
|
my $prev_tag = $iter->prev_tag_name; |
68
|
|
|
|
|
|
|
|
69
|
233
|
100
|
|
2071
|
|
1052
|
if ( any { $tag eq $_ } @collapse ) { |
|
2071
|
50
|
|
|
|
1394
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# strip \s from before us |
72
|
80
|
|
|
|
|
467
|
$output =~ s/ \s+ \z //x; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
elsif ( defined $prev_tag ) { |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
# strip \s between <start> <start> |
77
|
153
|
|
|
|
|
125
|
for my $consec (@consecutive) { |
78
|
306
|
100
|
100
|
|
|
613
|
if ( $tag eq $consec && $tag eq $prev_tag ) { |
79
|
29
|
|
|
|
|
223
|
$output =~ s/ \s+ \z //x; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
elsif ( $token->is_end_tag ) { |
85
|
182
|
|
|
|
|
925
|
my $tag = $token->get_tag; |
86
|
182
|
|
|
|
|
649
|
my $prev_tag = $iter->prev_tag_name; |
87
|
|
|
|
|
|
|
|
88
|
182
|
100
|
|
1582
|
|
839
|
if ( any { $tag eq $_ } @collapse ) { |
|
1582
|
50
|
|
|
|
1068
|
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
# strip \s from before us |
91
|
77
|
|
|
|
|
514
|
$output =~ s/ \s+ \z //x; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
elsif ( defined $prev_tag ) { |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
# strip \s between </end> </end> |
96
|
105
|
|
|
|
|
87
|
for my $consec (@consecutive) { |
97
|
210
|
100
|
100
|
|
|
438
|
if ( $tag eq $consec && $tag eq $prev_tag ) { |
98
|
21
|
|
|
|
|
194
|
$output =~ s/ \s+ \z //x; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
676
|
|
|
|
|
1705
|
my $prev_tag = $iter->prev_tag_name; |
105
|
|
|
|
|
|
|
|
106
|
676
|
100
|
66
|
6083
|
|
3476
|
if ( defined $prev_tag && any { $prev_tag eq $_ } @collapse ) { |
|
6083
|
|
|
|
|
4216
|
|
107
|
208
|
|
|
|
|
1129
|
$output =~ s/ \s+ \z //x; |
108
|
|
|
|
|
|
|
|
109
|
208
|
|
|
|
|
324
|
my $part = $token->as_is; |
110
|
|
|
|
|
|
|
|
111
|
208
|
|
|
|
|
634
|
$part =~ s/ ^ \s+ //x; |
112
|
|
|
|
|
|
|
|
113
|
208
|
|
|
|
|
400
|
$output .= $part; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
else { |
116
|
468
|
|
|
|
|
653
|
$output .= $token->as_is; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
27
|
|
|
|
|
947
|
return $output; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
package HTML::FormFu::OutputProcessor::StripWhitespace::_iter; |
126
|
|
|
|
|
|
|
|
127
|
2
|
|
|
2
|
|
10
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
54
|
|
128
|
|
|
|
|
|
|
our $VERSION = '2.05'; # VERSION |
129
|
|
|
|
|
|
|
|
130
|
2
|
|
|
2
|
|
7
|
use Moose; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
10
|
|
131
|
2
|
|
|
2
|
|
8297
|
use MooseX::Attribute::FormFuChained; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
401
|
|
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub new { |
134
|
27
|
|
|
27
|
1
|
72
|
my ( $class, @tags ) = @_; |
135
|
|
|
|
|
|
|
|
136
|
27
|
|
|
|
|
72
|
my %self = ( |
137
|
|
|
|
|
|
|
tags => \@tags, |
138
|
|
|
|
|
|
|
i => 0, |
139
|
|
|
|
|
|
|
); |
140
|
|
|
|
|
|
|
|
141
|
27
|
|
|
|
|
58
|
return bless \%self, $class; |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
sub next { |
145
|
703
|
|
|
703
|
0
|
1749
|
my ($self) = @_; |
146
|
|
|
|
|
|
|
|
147
|
703
|
|
|
|
|
1141
|
return $self->{tags}[ $self->{i}++ ]; |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
sub prev_tag_name { |
151
|
1091
|
|
|
1091
|
0
|
716
|
my ($self) = @_; |
152
|
|
|
|
|
|
|
|
153
|
1091
|
|
|
|
|
848
|
my $i = $self->{i} - 2; |
154
|
|
|
|
|
|
|
|
155
|
1091
|
|
|
|
|
1489
|
while ( $i >= 0 ) { |
156
|
|
|
|
|
|
|
|
157
|
1557
|
100
|
|
|
|
2121
|
if ( $self->{tags}[$i]->is_tag ) { |
158
|
1037
|
50
|
|
|
|
4071
|
return if !$self->{tags}[$i]->is_tag; |
159
|
|
|
|
|
|
|
|
160
|
1037
|
|
|
|
|
3906
|
return $self->{tags}[$i]->get_tag; |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
520
|
|
|
|
|
1229
|
--$i; |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable( inline_constructor => 0 ); |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
1; |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
__END__ |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head1 NAME |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
HTML::FormFu::OutputProcessor::StripWhitespace - Strip shitespace from HTML output |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=head1 VERSION |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
version 2.05 |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=head1 SYNOPSIS |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
--- |
184
|
|
|
|
|
|
|
output_processors: |
185
|
|
|
|
|
|
|
- StripWhitespace |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=head1 METHODS |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=head2 collapse_tags |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=head2 collapse_consecutive_tags |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=head1 SEE ALSO |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
Is a sub-class of, and inherits methods from L<HTML::FormFu::OutputProcessor> |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
L<HTML::FormFu> |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=head1 AUTHOR |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
Carl Franks C<cfranks@cpan.org> |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=head1 LICENSE |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
This library is free software, you can redistribute it and/or modify it under |
206
|
|
|
|
|
|
|
the same terms as Perl itself. |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=cut |