| 1 | package HTML::Packer; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 11 | ▶ | use 5.008009; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 11 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 11 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 11 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 11 | ▶ | use Regexp::RegGrp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 11 | ▶ | use Digest::SHA qw(sha256_base64 sha384_base64 sha512_base64); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 11 | ▶ | use Safe::Isa; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 7 | our $VERSION = '2.11'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 7 | our @BOOLEAN_ACCESSORS = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 'remove_comments', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 'remove_comments_aggressive', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 'remove_newlines', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 'no_compress_comment', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 'html5', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 7 | our @JAVASCRIPT_OPTS = ( 'clean', 'obfuscate', 'shrink', 'best' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 7 | our @CSS_OPTS = ( 'minify', 'pretty' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 7 | our @CSP_OPTS = ( 'sha256', 'sha384', 'sha512' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 7 | our $REQUIRED_JAVASCRIPT_PACKER = '1.002001'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 7 | our $REQUIRED_CSS_PACKER = '1.000001'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 7 | our @SAVE_SPACE_ELEMENTS = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 'a', 'abbr', 'acronym', 'address', 'b', 'bdo', 'big', 'button', 'cite', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 'del', 'dfn', 'em', 'font', 'i', 'input', 'ins', 'kbd', 'label', 'q', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 's', 'samp', 'select', 'small', 'strike', 'strong', 'sub', 'sup', 'u', 'var' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 7 | our @VOID_ELEMENTS = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 'area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | # Some regular expressions are from HTML::Clean | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 7 | our $COMMENT = '((?>\s*))(<!--(?:.*?)?-->)((?>\s*))'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 7 | our $COMMENT_SAFE = '((?>\s*))(<!--(?:(?![#\[]| google_ad_section_).*?)?-->)((?>\s*))'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 7 | our $PACKER_COMMENT = '<!--\s*HTML::Packer\s*(\w+)\s*-->'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 7 | our $DOCTYPE = '<\!DOCTYPE[^>]*>'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 7 | our $DONT_CLEAN = '(<\s*(pre|code|textarea|script|style)[^>]*>)(.*?)(<\s*\/\2[^>]*>)'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | our $WHITESPACES = [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | regexp => qr/^\s*/s, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | replacement => '' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | regexp => qr/\s*$/s, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | replacement => '' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | regexp => '^\s*', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | replacement => '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | modifier => 'm' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | regexp => '[^\S\n]*$', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | replacement => '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | modifier => 'm' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | regexp => qr/(?<=>)[^<>]*(?=<)/sm, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 300 | ▶ | replacement => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 300 | my $match = $_[0]->{match}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 300 | $match =~ s/[^\S\n]{2,}/ /sg; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 300 | $match =~ s/\s*\n+\s*/\n/sg; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 300 | return $match; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | regexp => '<\s*(\/)?\s*', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 466 | ▶ | replacement => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 466 | return sprintf( '<%s', $_[0]->{submatches}->[0] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | modifier => 's' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | regexp => '\s*(\/)?\s*>', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 463 | ▶ | replacement => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 466 | return sprintf( '%s>', $_[0]->{submatches}->[0] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 7 | modifier => 's' | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | our $NEWLINES_TAGS = [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | regexp => '(\s*)(<\s*\/?\s*(?:' . join( '|', @SAVE_SPACE_ELEMENTS ) . ')\b[^>]*>)(\s*)', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 113 | ▶ | replacement => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 116 | ▶ | return sprintf( '%s%s%s', $_[0]->{submatches}->[0] ? ' ' : '', $_[0]->{submatches}->[1], $_[0]->{submatches}->[2] ? ' ' : '' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 7 | modifier => 'is' | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | our $NEWLINES = [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | regexp => '(.)\n(.)', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 94 | ▶ | replacement => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 94 | my ( $pre, $post ) = @{$_[0]->{submatches}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 94 | my $ret; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 94 | ▶ | if ( $pre eq '>' and $post eq '<' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
$pre eq ">" and $post eq "<"
MC/DC50%1/2
$pre eq ">" and $post eq "<"
$pre eq ">"
$post eq "<"
Truth table66%2/3
A and B
A= $pre eq ">"B= $post eq "<"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 64 | $ret = $pre . $post; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | ▶ | elsif ( $pre eq '-' and $post =~ /[\w]/ ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$pre eq "-" and $post =~ /[\w]/
MC/DC50%1/2
$pre eq "-" and $post =~ /[\w]/
$pre eq "-"
$post =~ /[\w]/
Truth table66%2/3
A and B
A= $pre eq "-"B= $post =~ /[\w]/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 2 | $ret = $pre . $post; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 30 | $ret = $pre . ' ' . $post; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 94 | return $ret; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 7 | ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 7 | our @REGGRPS = ( 'newlines', 'newlines_tags', 'whitespaces', 'void_elements' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 7 | our $GLOBAL_REGGRP = 'global'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | ########################################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 11 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 7 | foreach my $field ( @BOOLEAN_ACCESSORS ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 35 | ▶ | next if defined *{ __PACKAGE__ . '::' . $field }{CODE}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 35 | ▶ | *{ __PACKAGE__ . '::' . $field} = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 476 | my ( $self, $value ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 476 | ▶ | $self->{'_' . $field} = $value ? 1 : undef if ( defined( $value ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 476 | return $self->{'_' . $field}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 35 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 7 | foreach my $reggrp ( @REGGRPS, $GLOBAL_REGGRP ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 35 | ▶ | next if defined *{ __PACKAGE__ . '::reggrp_' . $reggrp }{CODE}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 35 | ▶ | *{ __PACKAGE__ . '::reggrp_' . $reggrp } = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 275 | my ( $self ) = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 275 | return $self->{ '_reggrp_' . $reggrp }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 35 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 95 | ▶ | sub do_javascript { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
do_javascript: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 95 | my ( $self, $value ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 95 | ▶ | if ( defined( $value ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 36 | ▶ | if ( grep( $value eq $_, @JAVASCRIPT_OPTS ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 33 | $self->{_do_javascript} = $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | elsif ( ! $value ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 2 | $self->{_do_javascript} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 95 | return $self->{_do_javascript}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 72 | ▶ | sub do_stylesheet { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
do_stylesheet: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 72 | my ( $self, $value ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 72 | ▶ | if ( defined( $value ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 14 | ▶ | if ( grep( $value eq $_, @CSS_OPTS ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 11 | $self->{_do_stylesheet} = $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | elsif ( ! $value ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 2 | $self->{_do_stylesheet} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 72 | return $self->{_do_stylesheet}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 58 | ▶ | sub do_csp { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
do_csp: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 58 | my ( $self, $value ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 58 | ▶ | if ( defined( $value ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 8 | ▶ | if ( grep( $value eq $_, @CSP_OPTS ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 6 | $self->{_do_csp} = $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | elsif ( ! $value ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 2 | $self->{_do_csp} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 58 | return $self->{_do_csp}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | # these variables are used in the closures defined in the init function | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | # below - we have to use globals as using $self within the closures leads | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | # to a reference cycle and thus memory leak, and we can't scope them to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | # the init method as they may change. they are set by the minify sub | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 7 | our $remove_comments; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 7 | our $remove_comments_aggressive; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 7 | our $remove_newlines; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 7 | our $html5; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 7 | our $do_javascript; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 7 | our $do_stylesheet; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 7 | our $do_csp; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 7 | our $js_packer; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 7 | our $css_packer; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 7 | our %csp; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 7 | our $reggrp_ws; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 40 | ▶ | sub init { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 40 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 40 | my $self = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 40 | bless( $self, $class ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 40 | $self->{whitespaces}->{reggrp_data} = $WHITESPACES; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 40 | $self->{newlines}->{reggrp_data} = $NEWLINES; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 40 | $self->{newlines_tags}->{reggrp_data} = $NEWLINES_TAGS; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | $self->{global}->{reggrp_data} = [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | regexp => $DOCTYPE, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 2 | ▶ | replacement => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 1 | return '<!--~' . $_[0]->{store_index} . '~-->'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 2 | ▶ | store => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 1 | my $doctype = $_[0]->{match}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 1 | $doctype =~ s/\s+/ /gsm; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 1 | return $doctype; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | # this is using a variable that won't be initialized until after we have | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | # called ->minify so we endup calling ->init again (see FIXME) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | regexp => $remove_comments_aggressive ? $COMMENT : $COMMENT_SAFE, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 37 | ▶ | replacement => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=17.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | return $remove_comments ? ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | $remove_newlines ? ' ' : ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | ( $_[0]->{submatches}->[0] =~ /\n/s or $_[0]->{submatches}->[2] =~ /\n/s ) ? "\n" : '' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 36 | ▶ | ) : '<!--~' . $_[0]->{store_index} . '~-->'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition33%1/3
$_[0]{"submatches"}[0] =~ /\n/s or $_[0]{"submatches"}[2] =~ /\n/s
MC/DC0%0/2
$_[0]{"submatches"}[0] =~ /\n/s or $_[0]{"submatches"}[2] =~ /\n/s
$_[0]{"submatches"}[0] =~ /\n/s
$_[0]{"submatches"}[2] =~ /\n/s
Truth table33%1/3
A or B
A= $_[0]{"submatches"}[0] =~ /\n/sB= $_[0]{"submatches"}[2] =~ /\n/s
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 37 | ▶ | store => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | my $ret = $remove_comments ? '' : ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | ( ( not $remove_newlines and $_[0]->{submatches}->[0] =~ /\n/s ) ? "\n" : '' ) . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | $_[0]->{submatches}->[1] . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 36 | ▶ | ( ( not $remove_newlines and $_[0]->{submatches}->[2] =~ /\n/s ) ? "\n" : '' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition83%5/6
not $HTML::Packer::remove_newlines and $_[0]{"submatches"}[0] =~ /\n/s
not $HTML::Packer::remove_newlines and $_[0]{"submatches"}[2] =~ /\n/s
MC/DC50%1/2
not $HTML::Packer::remove_newlines and $_[0]{"submatches"}[0] =~ /\n/s
not $HTML::Packer::remove_newlines
$_[0]{"submatches"}[0] =~ /\n/s
MC/DC100%2/2
not $HTML::Packer::remove_newlines and $_[0]{"submatches"}[2] =~ /\n/s
not $HTML::Packer::remove_newlines
$_[0]{"submatches"}[2] =~ /\n/s
Truth table66%2/3
not(A) and B
A= not $HTML::Packer::remove_newlinesB= $_[0]{"submatches"}[0] =~ /\n/s
Truth table100%3/3
not(A) and B
A= not $HTML::Packer::remove_newlinesB= $_[0]{"submatches"}[2] =~ /\n/s
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 36 | return $ret; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | regexp => $DONT_CLEAN, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 61 | ▶ | replacement => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 60 | return '<!--~' . $_[0]->{store_index} . '~-->'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 60 | ▶ | store => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=18 SCAR=29.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 60 | my ( $opening, undef, $content, $closing ) = @{$_[0]->{submatches}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 60 | ▶ | if ( $content ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 60 | ▶ | my $opening_script_re = '<\s*script' . ( $html5 ? '[^>]*>' : '[^>]*(?:java|ecma)script[^>]*>' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 60 | ▶ | my $opening_style_re = '<\s*style' . ( $html5 ? '[^>]*>' : '[^>]*text\/css[^>]*>' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 60 | my $js_type_re = q{type=['"]((((application|text)/){0,1}(x-){0,1}(java|ecma)script)|module)['"]}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 60 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%4/6
$opening =~ /$opening_script_re/i and $opening =~ /$js_type_re/i || !($opening =~ /type/i)
$opening =~ /$js_type_re/i or not $opening =~ /type/i
MC/DC33%1/3
$opening =~ /$opening_script_re/i and $opening =~ /$js_type_re/i || !($opening =~ /type/i)
$opening =~ /$opening_script_re/i
$opening =~ /$js_type_re/i
not $opening =~ /type/i
Truth table75%3/4
A and B or not(C)
A= $opening =~ /$opening_script_re/iB= $opening =~ /$js_type_re/iC= not $opening =~ /type/i
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | $opening =~ /$opening_script_re/i | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | && ( $opening =~ /$js_type_re/i || $opening !~ /type/i ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 36 | ▶ | $opening =~ s/ type="(text\/)?(java|ecma)script"//i if ( $html5 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 36 | ▶ | if ( $js_packer and $do_javascript ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$HTML::Packer::js_packer and $HTML::Packer::do_javascript
MC/DC50%1/2
$HTML::Packer::js_packer and $HTML::Packer::do_javascript
$HTML::Packer::js_packer
$HTML::Packer::do_javascript
Truth table66%2/3
A and B
A= $HTML::Packer::js_packerB= $HTML::Packer::do_javascript
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 27 | $js_packer->minify( \$content, { compress => $do_javascript } ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 27 | ▶ | unless ( $html5 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 25 | $content = '/*<![CDATA[*/' . $content . '/*]]>*/'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 36 | ▶ | if ( $do_csp ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 11 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 9 | push @{ $csp{'script-src'} }, &{ "${do_csp}_base64" } ( $content ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | elsif ( $opening =~ /$opening_style_re/i ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 16 | ▶ | $opening =~ s/ type="text\/css"//i if ( $html5 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 16 | ▶ | if ( $css_packer and $do_stylesheet ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$HTML::Packer::css_packer and $HTML::Packer::do_stylesheet
MC/DC50%1/2
$HTML::Packer::css_packer and $HTML::Packer::do_stylesheet
$HTML::Packer::css_packer
$HTML::Packer::do_stylesheet
Truth table66%2/3
A and B
A= $HTML::Packer::css_packerB= $HTML::Packer::do_stylesheet
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 7 | $css_packer->minify( \$content, { compress => $do_stylesheet } ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 7 | ▶ | $content = "\n" . $content if ( $do_stylesheet eq 'pretty' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 16 | ▶ | if ( $do_csp ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 11 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 9 | push @{ $csp{'style-src'} }, &{ "${do_csp}_base64" } ( $content ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | $content = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 60 | $reggrp_ws->exec( \$opening ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 60 | $reggrp_ws->exec( \$closing ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 60 | return $opening . $content . $closing; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 40 | ▶ | modifier => 'ism' | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | $self->{void_elements}->{reggrp_data} = [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | regexp => '<\s*((?:' . join( '|', @VOID_ELEMENTS ) . ')\b[^>]*)\s*\/>', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 2 | ▶ | replacement => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 2 | return '<' . $_[0]->{submatches}->[0] . '>'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 40 | modifier => 'ism' | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 40 | foreach ( @HTML::Packer::REGGRPS ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 157 | $self->{ '_reggrp_' . $_ } = Regexp::RegGrp->new( { reggrp => $self->{$_}->{reggrp_data} } ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | $self->{ '_reggrp_' . $GLOBAL_REGGRP } = Regexp::RegGrp->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | reggrp => $self->{$GLOBAL_REGGRP}->{reggrp_data}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 40 | restore_pattern => qr/<!--~(\d+)~-->/ | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 39 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 51 | ▶ | sub minify { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
minify: called CC=23 SCAR=32.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 51 | my ( $self, $input, $opts ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 51 | ▶ | unless ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $_[0] and $_[0]->$HTML::Packer::_isa(__PACKAGE__)
MC/DC0%0/2
ref $_[0] and $_[0]->$HTML::Packer::_isa(__PACKAGE__)
ref $_[0]
$_[0]->$HTML::Packer::_isa(__PACKAGE__)
Truth table33%1/3
A and B
A= ref $_[0]B= $_[0]->$HTML::Packer::_isa(__PACKAGE__)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | ref( $_[0] ) and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | $_[0]->$_isa( __PACKAGE__ ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | $self = __PACKAGE__->init(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | ▶ | shift( @_ ) unless ( ref( $_[0] ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | ( $input, $opts ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 51 | ( $self, $input, $opts ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 51 | ▶ | if ( ref( $input ) ne 'SCALAR' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 0 | carp( 'First argument must be a scalarref!' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 51 | my $html; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 51 | my $cont = 'void'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 51 | ▶ | if ( defined( wantarray ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 10 | ▶ | my $tmp_input = ref( $input ) ? ${$input} : $input; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 10 | $html = \$tmp_input; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 10 | $cont = 'scalar'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 41 | ▶ | $html = ref( $input ) ? $input : \$input; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 51 | ▶ | if ( ref( $opts ) eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 51 | foreach my $field ( @BOOLEAN_ACCESSORS ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 255 | ▶ | $self->$field( $opts->{$field} ) if ( defined( $opts->{$field} ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 51 | ▶ | $self->do_javascript( $opts->{do_javascript} ) if ( defined( $opts->{do_javascript} ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 51 | ▶ | $self->do_stylesheet( $opts->{do_stylesheet} ) if ( defined( $opts->{do_stylesheet} ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 51 | ▶ | $self->do_csp( $opts->{do_csp} ) if ( defined( $opts->{do_csp} ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 51 | ▶ | if ( not $self->no_compress_comment() and ${$html} =~ /$PACKER_COMMENT/s ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $self->no_compress_comment and ${$html;} =~ /$PACKER_COMMENT/s
MC/DC100%2/2
not $self->no_compress_comment and ${$html;} =~ /$PACKER_COMMENT/s
not $self->no_compress_comment
${$html;} =~ /$PACKER_COMMENT/s
Truth table100%3/3
not(A) and B
A= not $self->no_compress_commentB= ${$html;} =~ /$PACKER_COMMENT/s
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 1 | my $compress = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 1 | ▶ | if ( $compress eq '_no_compress_' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 0 | ▶ | return ( $cont eq 'scalar' ) ? ${$html} : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | # (re)initialize variables used in the closures | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 50 | ▶ | $remove_comments = $self->remove_comments || $self->remove_comments_aggressive; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$self->remove_comments || $self->remove_comments_aggressive
MC/DC100%2/2
$self->remove_comments || $self->remove_comments_aggressive
$self->remove_comments
$self->remove_comments_aggressive
Truth table100%3/3
A || B
A= $self->remove_commentsB= $self->remove_comments_aggressive
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 50 | $remove_comments_aggressive = $self->remove_comments_aggressive; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 50 | $remove_newlines = $self->remove_newlines; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 50 | $html5 = $self->html5; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 50 | $do_javascript = $self->do_javascript; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 50 | $do_stylesheet = $self->do_stylesheet; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 50 | $do_csp = $self->do_csp; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 50 | $js_packer = $self->javascript_packer; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 50 | $css_packer = $self->css_packer; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 50 | $reggrp_ws = $self->reggrp_whitespaces; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | # blank out the CSP hash before populating it again | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 50 | %csp = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | # FIXME: hacky way to get around ->init being called before ->minify | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 50 | ▶ | $self = ref( $self )->init if $remove_comments_aggressive; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 50 | $self->reggrp_global()->exec( $html ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 50 | $self->reggrp_whitespaces()->exec( $html ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 50 | ▶ | if ( $self->remove_newlines() ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 34 | $self->reggrp_newlines_tags()->exec( $html ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 34 | $self->reggrp_newlines()->exec( $html ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 50 | ▶ | if ( $self->html5() ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 6 | $self->reggrp_void_elements()->exec( $html ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 50 | $self->reggrp_global()->restore_stored( $html ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 50 | ▶ | return ${$html} if ( $cont eq 'scalar' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 51 | ▶ | sub javascript_packer { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
javascript_packer: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 51 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 51 | ▶ | unless ( $self->{_checked_javascript_packer} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 37 | ▶ | eval "use JavaScript::Packer $REQUIRED_JAVASCRIPT_PACKER;"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 37 | ▶ | unless ( $@ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 37 | $self->{_javascript_packer} = eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 37 | JavaScript::Packer->init(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 37 | $self->{_checked_javascript_packer} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 51 | return $self->{_javascript_packer}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 51 | ▶ | sub css_packer { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
css_packer: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 51 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 51 | ▶ | unless ( $self->{_checked_css_packer} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 37 | ▶ | eval "use CSS::Packer $REQUIRED_CSS_PACKER;"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 37 | ▶ | unless ( $@ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 37 | $self->{_css_packer} = eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 37 | CSS::Packer->init(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 37 | $self->{_checked_css_packer} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 51 | return $self->{_css_packer}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 7 | ▶ | sub csp { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
csp: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 7 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 7 | ▶ | return 'script-src' => [ ], 'style-src' => [ ] unless $do_csp and %csp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$do_csp and %csp
MC/DC100%2/2
$do_csp and %csp
$do_csp
%csp
Truth table100%3/3
A and B
A= $do_cspB= %csp
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | return | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 4 | 'script-src' => [ map "'$do_csp-$_='", @{ $csp{'script-src'} } ], | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 4 | 'style-src' => [ map "'$do_csp-$_='", @{ $csp{'style-src'} } ], | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 7 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||