blib/lib/Template/Plugin/Filter/MinifyHTML.pm untested

filter: Statementstmt 0.0% 0 / 21 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 4 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 31 CC 3 SCAR 19.5
CC
3
Cov
0%
filter
12.0
init
2.0
BEGIN
2.0
CRAP 7.0
1 package Template::Plugin::Filter::MinifyHTML;
2  
3 our $VERSION = '0.02';
4  
5 use Template::Plugin::Filter;
6 use base qw( Template::Plugin::Filter );
7  
8 sub init {
9 my $self = shift;
10 $self->install_filter('minify_html');
11 $self->{_cfg} = shift;
12 return $self;
13 }
14  
15 sub filter {
16 my ($self, $text) = @_;
17  
18 for ($text) {
19 s/^\s+//; # Leading Whitespace
20 s/\s+$//; # Trailing Whitespace
21 s/[ \r\n\t]+/ /g; # More than one space
22 s/>\s+</></g; # Fix > <
23  
24 s/\s*\/>/>/g # Remove trailing / on self-closing elements
25 if ($self->{_cfg}->{html5});
26  
27 s/<!--[^[].*?[^]]-->//g # Remove HTML comments (leaving IE conditional comments alone (hopefully))
28 if ($self->{_cfg}->{comments});
29 }
30  
31 return $text;
32 }
33  
34 1;
35  
36 __END__