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