| 1 | package JavaScript::Packer; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use 5.008009; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use Regexp::RegGrp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | # =========================================================================== # | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 4 | our $VERSION = "2.11"; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 4 | our @BOOLEAN_ACCESSORS = ( 'no_compress_comment', 'remove_copyright' ); | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 4 | our @COPYRIGHT_ACCESSORS = ( 'copyright', 'copyright_comment' ); | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 4 | our @COMPRESS_OPTS = ( 'clean', 'obfuscate', 'shrink', 'best' ); | |||||||||||||||||||||||||||
| 18 | 4 | our $DEFAULT_COMPRESS = 'clean'; | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 4 | our $PACKER_COMMENT = '\/\*\s*JavaScript::Packer\s*(\w+)\s*\*\/'; | |||||||||||||||||||||||||||
| 21 | 4 | our $COPYRIGHT_COMMENT = '\/\*((?>[^\*]|\*[^\/])*copyright(?>[^\*]|\*[^\/])*)\*\/'; | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 4 | our $RESTORE_PATTERN = qr~\x01(\d+)\x01~; | |||||||||||||||||||||||||||
| 24 | 4 | our $RESTORE_REPLACEMENT = "\x01%d\x01"; | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 4 | our $SHRINK_VARS = { | |||||||||||||||||||||||||||
| 27 | BLOCK => qr/(((catch|do|if|while|with|function)\b[^~{};]*(\(\s*[^{};]*\s*\))\s*)?(\{[^{}]*\}))/, # function ( arg ) { ... } | ||||||||||||||||||||||||||||
| 28 | ENCODED_BLOCK => qr/~#?(\d+)~/, | ||||||||||||||||||||||||||||
| 29 | CALLER => qr/((?>[a-zA-Z0-9_\x24\.]+)\s*\([^\(\)]*\))(?=[,\)])/, # do_something( arg1, arg2 ) as argument of another function call | ||||||||||||||||||||||||||||
| 30 | BRACKETS => qr/\{[^{}]*\}|\[[^\[\]]*\]|\([^\(\)]*\)|~[^~]+~/, | ||||||||||||||||||||||||||||
| 31 | IDENTIFIER => qr~[a-zA-Z_\x24][a-zA-Z_0-9\\x24]*~, | ||||||||||||||||||||||||||||
| 32 | SCOPED => qr/~#(\d+)~/, | ||||||||||||||||||||||||||||
| 33 | VARS => qr~\b(?:var|function)\s+((?>[a-zA-Z0-9_\x24]+))~, # var x, funktion blah | ||||||||||||||||||||||||||||
| 34 | PREFIX => qr~\x02~, | ||||||||||||||||||||||||||||
| 35 | SHRUNK => qr~\x02\d+\b~ | ||||||||||||||||||||||||||||
| 36 | }; | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 4 | our $BASE62_VARS = { | |||||||||||||||||||||||||||
| 39 | WORDS => qr~(\b[0-9a-zA-Z]\b|(?>[a-zA-Z0-9_]{2,}))~, | ||||||||||||||||||||||||||||
| 40 | ENCODE10 => 'String', | ||||||||||||||||||||||||||||
| 41 | ENCODE36 => 'function(c){return c.toString(36)}', | ||||||||||||||||||||||||||||
| 42 | ENCODE62 => q~function(c){return(c<62?'':e(parseInt(c/62)))+((c=c%62)>35?String.fromCharCode(c+29):c.toString(36))}~, | ||||||||||||||||||||||||||||
| 43 | UNPACK => | ||||||||||||||||||||||||||||
| 44 | q~eval(function(p,a,c,k,e,r){e=%s;if('0'.replace(0,e)==0){while(c--)r[e(c)]=k[c];k=[function(e){return r[e]||e}];e=function(){return'%s'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\\\b'+e(c)+'\\\\b','g'),k[c]);return p}('%s',%s,%d,'%s'.split('|'),0,{}))~ | ||||||||||||||||||||||||||||
| 45 | }; | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 4 | our $DICTIONARY = { | |||||||||||||||||||||||||||
| 48 | STRING1 => qr~"(?>(?:(?>[^"\\]+)|\\.|\\")*)"~, | ||||||||||||||||||||||||||||
| 49 | STRING2 => qr~'(?>(?:(?>[^'\\]+)|\\.|\\')*)'~, | ||||||||||||||||||||||||||||
| 50 | STRING3 => qr~`(?>(?:(?>[^`\\]+)|\\.|\\`)*)`~, | ||||||||||||||||||||||||||||
| 51 | REGEXP => qr~\/(\\[\/\\]|[^*\/])(\\.|[^\/\n\\])*\/[gim]*~, | ||||||||||||||||||||||||||||
| 52 | OPERATOR => qr'return|typeof|[\[(\^=,{}:;&|!*?]', | ||||||||||||||||||||||||||||
| 53 | CONDITIONAL => qr~\/\*\@\w*|\w*\@\*\/|\/\/\@\w*|\@(?>\w+)~, | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | # single line comments | ||||||||||||||||||||||||||||
| 56 | COMMENT1 => qr~(:?)\/\/([\@#])?([^\n]*)?\n~, | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | # multline comments | ||||||||||||||||||||||||||||
| 59 | COMMENT2 => qr~\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/~ | ||||||||||||||||||||||||||||
| 60 | }; | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | our $DATA = [ | ||||||||||||||||||||||||||||
| 63 | { regexp => $DICTIONARY->{STRING1} }, | ||||||||||||||||||||||||||||
| 64 | { regexp => $DICTIONARY->{STRING2} }, | ||||||||||||||||||||||||||||
| 65 | { regexp => $DICTIONARY->{STRING3} }, | ||||||||||||||||||||||||||||
| 66 | { regexp => $DICTIONARY->{CONDITIONAL} }, | ||||||||||||||||||||||||||||
| 67 | { | ||||||||||||||||||||||||||||
| 68 | regexp => '(' . $DICTIONARY->{OPERATOR} . ')\s*(' . $DICTIONARY->{REGEXP} . ')', | ||||||||||||||||||||||||||||
| 69 | replacement => sub { | ||||||||||||||||||||||||||||
| 70 | 300 | ▶ | return sprintf( "%s%s", $_[0]->{submatches}->[0], $_[0]->{submatches}->[1] ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 71 | }, | ||||||||||||||||||||||||||||
| 72 | }, | ||||||||||||||||||||||||||||
| 73 | 4 | ]; | |||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | our $COMMENTS = [ | ||||||||||||||||||||||||||||
| 76 | { | ||||||||||||||||||||||||||||
| 77 | regexp => ';;;[^\n]*\n', | ||||||||||||||||||||||||||||
| 78 | replacement => '' | ||||||||||||||||||||||||||||
| 79 | }, | ||||||||||||||||||||||||||||
| 80 | { regexp => $DICTIONARY->{COMMENT1} . '\s*(' . $DICTIONARY->{REGEXP} . ')?', }, | ||||||||||||||||||||||||||||
| 81 | 4 | { regexp => '(' . $DICTIONARY->{COMMENT2} . ')\s*(' . $DICTIONARY->{REGEXP} . ')?' } | |||||||||||||||||||||||||||
| 82 | ]; | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | our $CLEAN = [ | ||||||||||||||||||||||||||||
| 85 | { | ||||||||||||||||||||||||||||
| 86 | regexp => '\(\s*([^;)]*)\s*;\s*([^;)]*)\s*;\s*([^;)]*)\)', | ||||||||||||||||||||||||||||
| 87 | 98 | ▶ | replacement => sub { return sprintf( "(%s;%s;%s)", @{ $_[0]->{submatches} } ); } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 88 | }, | ||||||||||||||||||||||||||||
| 89 | { regexp => 'throw[^};]+[};]' }, | ||||||||||||||||||||||||||||
| 90 | { | ||||||||||||||||||||||||||||
| 91 | regexp => ';+\s*([};])', | ||||||||||||||||||||||||||||
| 92 | 2715 | ▶ | replacement => sub { return $_[0]->{submatches}->[0]; } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | 4 | ]; | |||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | our $WHITESPACE = [ | ||||||||||||||||||||||||||||
| 97 | { regexp => '\/\/@[^\n]*\n' }, | ||||||||||||||||||||||||||||
| 98 | { | ||||||||||||||||||||||||||||
| 99 | regexp => '@\s+\b', | ||||||||||||||||||||||||||||
| 100 | replacement => '@ ' | ||||||||||||||||||||||||||||
| 101 | }, | ||||||||||||||||||||||||||||
| 102 | { | ||||||||||||||||||||||||||||
| 103 | regexp => '\b\s+@', | ||||||||||||||||||||||||||||
| 104 | replacement => ' @' | ||||||||||||||||||||||||||||
| 105 | }, | ||||||||||||||||||||||||||||
| 106 | { | ||||||||||||||||||||||||||||
| 107 | regexp => '(\d)\s+(\.\s*[a-z\x24_\[(])', | ||||||||||||||||||||||||||||
| 108 | 0 | ▶ | replacement => sub { return sprintf( "%s %s", @{ $_[0]->{submatches} } ); } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 109 | }, | ||||||||||||||||||||||||||||
| 110 | { | ||||||||||||||||||||||||||||
| 111 | regexp => '([+-])\s+([+-])', | ||||||||||||||||||||||||||||
| 112 | 0 | ▶ | replacement => sub { return sprintf( "%s %s", @{ $_[0]->{submatches} } ); } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 113 | }, | ||||||||||||||||||||||||||||
| 114 | { | ||||||||||||||||||||||||||||
| 115 | regexp => '(?>\s+)(\x24)(?>\s+)', | ||||||||||||||||||||||||||||
| 116 | 2 | ▶ | replacement => sub { return sprintf( " %s ", $_[0]->{submatches}->[0] ); } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 117 | }, | ||||||||||||||||||||||||||||
| 118 | { | ||||||||||||||||||||||||||||
| 119 | regexp => '(\x24)(?>\s+)(?!=)', | ||||||||||||||||||||||||||||
| 120 | 0 | ▶ | replacement => sub { return sprintf( "%s ", $_[0]->{submatches}->[0] ); } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 121 | }, | ||||||||||||||||||||||||||||
| 122 | { | ||||||||||||||||||||||||||||
| 123 | regexp => '(?<!=)(?>\s+)(\x24)', | ||||||||||||||||||||||||||||
| 124 | 813 | ▶ | replacement => sub { return sprintf( " %s", $_[0]->{submatches}->[0] ); } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 125 | }, | ||||||||||||||||||||||||||||
| 126 | { | ||||||||||||||||||||||||||||
| 127 | 4 | regexp => '\b\s+\b', | |||||||||||||||||||||||||||
| 128 | replacement => ' ' | ||||||||||||||||||||||||||||
| 129 | }, | ||||||||||||||||||||||||||||
| 130 | { | ||||||||||||||||||||||||||||
| 131 | regexp => '\s+', | ||||||||||||||||||||||||||||
| 132 | replacement => '' | ||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | ]; | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | our $TRIM = [ | ||||||||||||||||||||||||||||
| 137 | { | ||||||||||||||||||||||||||||
| 138 | regexp => '(\d)(?:\|\d)+\|(\d)', | ||||||||||||||||||||||||||||
| 139 | 3 | ▶ | replacement => sub { return sprintf( "%d-%d", $_[0]->{submatches}->[0] || 0, $_[0]->{submatches}->[1] || 0 ); } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=12.7
Condition50%2/4
$_[0]{'submatches'}[0] || 0
$_[0]{'submatches'}[1] || 0
MC/DC0%0/1
$_[0]{'submatches'}[0] || 0
$_[0]{'submatches'}[0]
MC/DC0%0/1
$_[0]{'submatches'}[1] || 0
$_[0]{'submatches'}[1]
Truth table50%1/2
A
A= $_[0]{'submatches'}[0]
Truth table50%1/2
A
A= $_[0]{'submatches'}[1]
| |||||||||||||||||||||||||||||
| 140 | }, | ||||||||||||||||||||||||||||
| 141 | { | ||||||||||||||||||||||||||||
| 142 | regexp => '([a-z])(?:\|[a-z])+\|([a-z])', | ||||||||||||||||||||||||||||
| 143 | 1 | ▶ | replacement => sub { return sprintf( "%s-%s", $_[0]->{submatches}->[0], $_[0]->{submatches}->[1] ); } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 144 | }, | ||||||||||||||||||||||||||||
| 145 | { | ||||||||||||||||||||||||||||
| 146 | regexp => '([A-Z])(?:\|[A-Z])+\|([A-Z])', | ||||||||||||||||||||||||||||
| 147 | 3 | ▶ | replacement => sub { return sprintf( "%s-%s", $_[0]->{submatches}->[0], $_[0]->{submatches}->[1] ); } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 148 | }, | ||||||||||||||||||||||||||||
| 149 | { | ||||||||||||||||||||||||||||
| 150 | 4 | regexp => '\|', | |||||||||||||||||||||||||||
| 151 | replacement => '' | ||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||
| 153 | ]; | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | 4 | our @REGGRPS = ( 'comments', 'clean', 'whitespace', 'concat', 'trim', 'data_store', 'concat_store' ); | |||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | # --------------------------------------------------------------------------- # | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | { | ||||||||||||||||||||||||||||
| 160 | 4 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | 4 | foreach my $field ( @BOOLEAN_ACCESSORS ) { | |||||||||||||||||||||||||||
| 163 | 8 | ▶ | next if defined *{ __PACKAGE__ . '::' . $field }{CODE}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | 8 | *{ __PACKAGE__ . '::' . $field } = sub { | |||||||||||||||||||||||||||
| 166 | 109 | ▶ | my ( $self, $value ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | 109 | ▶ | $self->{ '_' . $field } = $value ? 1 : undef if ( defined( $value ) ); | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | 109 | return $self->{ '_' . $field }; | |||||||||||||||||||||||||||
| 171 | 8 | }; | |||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | 4 | foreach my $field ( @COPYRIGHT_ACCESSORS ) { | |||||||||||||||||||||||||||
| 175 | 8 | ▶ | $field = '_' . $field if ( $field eq 'copyright_comment' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 176 | 8 | ▶ | next if defined *{ __PACKAGE__ . '::' . $field }{CODE}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | 8 | *{ __PACKAGE__ . '::' . $field } = sub { | |||||||||||||||||||||||||||
| 179 | 141 | ▶ | my ( $self, $value ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | 141 | ▶ | if ( defined( $value ) and not ref( $value ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $value and not ref $value
MC/DC50%1/2
defined $value and not ref $value
defined $value
not ref $value
Truth table66%2/3
A and not(B)
A= defined $valueB= not ref $value
| |||||||||||||||||||||||||||||
| 182 | 51 | $value =~ s/^\s*|\s*$//gs; | |||||||||||||||||||||||||||
| 183 | 51 | $self->{ '_' . $field } = $value; | |||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | 141 | my $ret = ''; | |||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | 141 | ▶ | if ( $self->{ '_' . $field } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 189 | 14 | $ret = '/* ' . $self->{ '_' . $field } . ' */' . "\n"; | |||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | 141 | return $ret; | |||||||||||||||||||||||||||
| 193 | 8 | }; | |||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | 4 | foreach my $reggrp ( @REGGRPS ) { | |||||||||||||||||||||||||||
| 197 | 28 | ▶ | next if defined *{ __PACKAGE__ . '::reggrp_' . $reggrp }{CODE}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | 28 | *{ __PACKAGE__ . '::reggrp_' . $reggrp } = sub { | |||||||||||||||||||||||||||
| 200 | 458 | ▶ | my ( $self ) = shift; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | 458 | return $self->{ '_reggrp_' . $reggrp }; | |||||||||||||||||||||||||||
| 203 | 28 | }; | |||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | sub compress { | ||||||||||||||||||||||||||||
| 208 | 178 | ▶ | my ( $self, $value ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
compress: called CC=5 SCAR=16.4
Pod
documented
| |||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | 178 | ▶ | if ( defined( $value ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 211 | 29 | ▶ | if ( grep( $value eq $_, @COMPRESS_OPTS ) ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 212 | 21 | $self->{_compress} = $value; | |||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||
| 214 | elsif ( !$value ) { | ||||||||||||||||||||||||||||
| 215 | 0 | $self->{_compress} = undef; | |||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||
| 219 | 178 | ▶ | $self->{_compress} ||= $DEFAULT_COMPRESS; | ||||||||||||||||||||||||||
|
Condition66%2/3
$self->{"_compress"} ||= $JavaScript::Packer::DEFAULT_COMPRESS
MC/DC0%0/2
$self->{"_compress"} ||= $JavaScript::Packer::DEFAULT_COMPRESS
$self->{"_compress"}
$JavaScript::Packer::DEFAULT_COMPRESS
Truth table66%2/3
A ||= B
A= $self->{"_compress"}B= $JavaScript::Packer::DEFAULT_COMPRESS
| |||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | 178 | return $self->{_compress}; | |||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | # these variables are used in the closures defined in the init function | ||||||||||||||||||||||||||||
| 225 | # below - we have to use globals as using $self within the closures leads | ||||||||||||||||||||||||||||
| 226 | # to a reference cycle and thus memory leak, and we can't scope them to | ||||||||||||||||||||||||||||
| 227 | # the init method as they may change. they are set by the minify sub | ||||||||||||||||||||||||||||
| 228 | 4 | our $reggrp_comments; | |||||||||||||||||||||||||||
| 229 | 4 | our $reggrp_clean; | |||||||||||||||||||||||||||
| 230 | 4 | our $reggrp_whitespace; | |||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||
| 232 | sub init { | ||||||||||||||||||||||||||||
| 233 | 32 | ▶ | my $class = shift; | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 234 | 32 | my $self = {}; | |||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||
| 236 | 32 | bless( $self, $class ); | |||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | 32 | @{ $self->{clean}->{reggrp_data} } = ( @$DATA, @$CLEAN ); | |||||||||||||||||||||||||||
| 239 | 32 | @{ $self->{whitespace}->{reggrp_data} } = ( @$DATA[ 0, 1, 2, 4 ], @$WHITESPACE ); | |||||||||||||||||||||||||||
| 240 | 32 | $self->{trim}->{reggrp_data} = $TRIM; | |||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||
| 242 | 32 | @{ $self->{data_store}->{reggrp_data} } = map { | |||||||||||||||||||||||||||
| 243 | 32 | { | |||||||||||||||||||||||||||
| 244 | regexp => $_->{regexp}, | ||||||||||||||||||||||||||||
| 245 | 792 | ▶ | store => sub { return sprintf( "%s", $_[0]->{match} ); }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 246 | replacement => sub { | ||||||||||||||||||||||||||||
| 247 | 792 | ▶ | return sprintf( $RESTORE_REPLACEMENT, $_[0]->{store_index} ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 248 | }, | ||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||
| 250 | 160 | } @$DATA; | |||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | $self->{data_store}->{reggrp_data}->[-1]->{replacement} = sub { | ||||||||||||||||||||||||||||
| 253 | 9 | ▶ | return sprintf( "%s$RESTORE_REPLACEMENT", $_[0]->{submatches}->[0], $_[0]->{store_index} ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 254 | 32 | }; | |||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||
| 256 | $self->{data_store}->{reggrp_data}->[-1]->{store} = sub { | ||||||||||||||||||||||||||||
| 257 | 9 | ▶ | return $_[0]->{submatches}->[1]; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 258 | 32 | }; | |||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||
| 260 | 32 | @{ $self->{concat_store}->{reggrp_data} } = map { | |||||||||||||||||||||||||||
| 261 | 32 | my $data = $_; | |||||||||||||||||||||||||||
| 262 | { | ||||||||||||||||||||||||||||
| 263 | regexp => $data->{regexp}, | ||||||||||||||||||||||||||||
| 264 | store => sub { | ||||||||||||||||||||||||||||
| 265 | 3226 | ▶ | my ( $quote, $string, $rest ) = $_[0]->{match} =~ /^(['"`])(.*)(['"`])$/; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 266 | 3226 | ▶ | return $_[0]->{match} if ! $rest; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||
| 268 | 3225 | return $string; | |||||||||||||||||||||||||||
| 269 | }, | ||||||||||||||||||||||||||||
| 270 | replacement => sub { | ||||||||||||||||||||||||||||
| 271 | 3226 | ▶ | my ( $quote, $string, $rest ) = $_[0]->{match} =~ /^(['"`])(.*)(['"`])$/; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 272 | 3226 | ▶ | return $_[0]->{match} if ! $rest; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||
| 274 | 3225 | return sprintf( "%s$RESTORE_REPLACEMENT%s", $quote, $_[0]->{store_index}, $quote ); | |||||||||||||||||||||||||||
| 275 | }, | ||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||
| 277 | 96 | }; | |||||||||||||||||||||||||||
| 278 | } @$DATA[ 0, 1, 2 ]; | ||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||
| 280 | 32 | @{ $self->{concat}->{reggrp_data} } = map { | |||||||||||||||||||||||||||
| 281 | 32 | my $quote = $_; | |||||||||||||||||||||||||||
| 282 | 96 | my $restore_pattern = $RESTORE_PATTERN; | |||||||||||||||||||||||||||
| 283 | 96 | $restore_pattern =~ s/\(\\d\+\)/\\d\+/g; | |||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||
| 285 | 96 | my $regexp = '(' . $quote . $restore_pattern . $quote . ')((?:\+' . $quote . $restore_pattern . $quote . ')+)'; | |||||||||||||||||||||||||||
| 286 | 96 | $regexp = qr/$regexp/; | |||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||
| 288 | { | ||||||||||||||||||||||||||||
| 289 | regexp => $regexp, | ||||||||||||||||||||||||||||
| 290 | replacement => sub { | ||||||||||||||||||||||||||||
| 291 | 16 | ▶ | my $submatches = $_[0]->{submatches}; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 292 | 16 | my $ret = $submatches->[0]; | |||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||
| 294 | 16 | my $next_str = '^\+(' . $quote . $restore_pattern . $quote . ')'; | |||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||
| 296 | 16 | ▶ | while ( my ( $next ) = $submatches->[1] =~ /$next_str/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 297 | 20 | chop( $ret ); | |||||||||||||||||||||||||||
| 298 | 20 | $ret .= substr( $next, 1 ); | |||||||||||||||||||||||||||
| 299 | 20 | $submatches->[1] =~ s/$next_str//; | |||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||
| 302 | 16 | return $ret; | |||||||||||||||||||||||||||
| 303 | }, | ||||||||||||||||||||||||||||
| 304 | 96 | }; | |||||||||||||||||||||||||||
| 305 | } ( '"', '\'', '\`' ); | ||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||
| 307 | 32 | @{ $self->{comments}->{reggrp_data} } = ( @$DATA[ 0, 1, 2, 4 ], @$COMMENTS ); | |||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||
| 309 | # single line comment | ||||||||||||||||||||||||||||
| 310 | $self->{comments}->{reggrp_data}->[-2]->{replacement} = sub { | ||||||||||||||||||||||||||||
| 311 | 1841 | ▶ | my $submatches = $_[0]->{submatches}; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||
| 313 | 1841 | ▶ | if ( $submatches->[0] eq ':' ) { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 314 | 1 | return sprintf( "://%s", $submatches->[2] ); | |||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||
| 316 | elsif ( $submatches->[1] eq '#' ) { | ||||||||||||||||||||||||||||
| 317 | 6 | my $cmnt = sprintf( "%s//%s%s__NEW_LINE__", @{$submatches}[0 .. 2] ); | |||||||||||||||||||||||||||
| 318 | 6 | return $cmnt; | |||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||
| 320 | elsif ( $submatches->[1] eq '@' ) { | ||||||||||||||||||||||||||||
| 321 | 4 | $reggrp_comments->exec( \$submatches->[2] ); | |||||||||||||||||||||||||||
| 322 | 4 | $reggrp_clean->exec( \$submatches->[2] ); | |||||||||||||||||||||||||||
| 323 | 4 | $reggrp_whitespace->exec( \$submatches->[2] ); | |||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||
| 325 | 4 | return sprintf( "%s//%s%s\n%s", @{$submatches}[0 .. 3] ); | |||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||
| 327 | 1830 | return sprintf( "\n%s", $submatches->[3] ); | |||||||||||||||||||||||||||
| 328 | 32 | }; | |||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||
| 330 | # multi line comments | ||||||||||||||||||||||||||||
| 331 | $self->{comments}->{reggrp_data}->[-1]->{replacement} = sub { | ||||||||||||||||||||||||||||
| 332 | 178 | ▶ | my $submatches = $_[0]->{submatches}; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 333 | 178 | ▶ | if ( $submatches->[0] =~ /^\/\*\@(.*)\@\*\/$/sm ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 334 | 7 | my $cmnt = $1; | |||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||
| 336 | 7 | $reggrp_comments->exec( \$cmnt ); | |||||||||||||||||||||||||||
| 337 | 7 | $reggrp_clean->exec( \$cmnt ); | |||||||||||||||||||||||||||
| 338 | 7 | $reggrp_whitespace->exec( \$cmnt ); | |||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||
| 340 | 7 | return sprintf( '/*@%s@*/ %s', $cmnt, $submatches->[1] ); | |||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||
| 342 | 171 | return sprintf( " %s", $submatches->[1] ); | |||||||||||||||||||||||||||
| 343 | 32 | }; | |||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||
| 345 | 32 | foreach my $reggrp ( @REGGRPS ) { | |||||||||||||||||||||||||||
| 346 | 224 | my $reggrp_args = { reggrp => $self->{$reggrp}->{reggrp_data} }; | |||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||
| 348 | 224 | ▶ | $reggrp_args->{restore_pattern} = $RESTORE_PATTERN if ( $reggrp eq 'data_store' or $reggrp eq 'concat_store' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$reggrp eq "data_store" or $reggrp eq "concat_store"
MC/DC100%2/2
$reggrp eq "data_store" or $reggrp eq "concat_store"
$reggrp eq "data_store"
$reggrp eq "concat_store"
Truth table100%3/3
A or B
A= $reggrp eq "data_store"B= $reggrp eq "concat_store"
| |||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||
| 350 | 224 | $self->{ '_reggrp_' . $reggrp } = Regexp::RegGrp->new( $reggrp_args ); | |||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||
| 353 | 32 | $self->{block_data} = []; | |||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||
| 355 | 32 | return $self; | |||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||
| 358 | sub minify { | ||||||||||||||||||||||||||||
| 359 | 47 | ▶ | my ( $self, $input, $opts ); | ||||||||||||||||||||||||||
|
Subroutine
minify: called CC=57 SCAR=41.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||
| 361 | 47 | ▶ | unless (ref( $_[0] ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $_[0] and ref $_[0] eq __PACKAGE__
MC/DC50%1/2
ref $_[0] and ref $_[0] eq __PACKAGE__
ref $_[0]
ref $_[0] eq __PACKAGE__
Truth table66%2/3
A and B
A= ref $_[0]B= ref $_[0] eq __PACKAGE__
| |||||||||||||||||||||||||||||
| 362 | and ref( $_[0] ) eq __PACKAGE__ ) | ||||||||||||||||||||||||||||
| 363 | { | ||||||||||||||||||||||||||||
| 364 | 9 | $self = __PACKAGE__->init(); | |||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||
| 366 | 9 | ▶ | shift( @_ ) unless ( ref( $_[0] ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||
| 368 | 9 | ( $input, $opts ) = @_; | |||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||
| 370 | else { | ||||||||||||||||||||||||||||
| 371 | 38 | ( $self, $input, $opts ) = @_; | |||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||
| 374 | 47 | ▶ | if ( ref( $input ) ne 'SCALAR' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 375 | 0 | carp( 'First argument must be a scalarref!' ); | |||||||||||||||||||||||||||
| 376 | 0 | return undef; | |||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||
| 379 | 47 | my $javascript = \''; | |||||||||||||||||||||||||||
| 380 | 47 | my $cont = 'void'; | |||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||
| 382 | 47 | ▶ | if ( defined( wantarray ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 383 | 5 | ▶ | my $tmp_input = ref( $input ) ? ${$input} : $input; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||
| 385 | 5 | $javascript = \$tmp_input; | |||||||||||||||||||||||||||
| 386 | 5 | $cont = 'scalar'; | |||||||||||||||||||||||||||
| 387 | } | ||||||||||||||||||||||||||||
| 388 | else { | ||||||||||||||||||||||||||||
| 389 | 42 | ▶ | $javascript = ref( $input ) ? $input : \$input; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||
| 392 | 47 | ▶ | if ( ref( $opts ) eq 'HASH' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 393 | 32 | foreach my $field ( @BOOLEAN_ACCESSORS ) { | |||||||||||||||||||||||||||
| 394 | 64 | ▶ | $self->$field( $opts->{$field} ) if ( defined( $opts->{$field} ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 395 | } | ||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||
| 397 | 32 | foreach my $field ( 'compress', 'copyright' ) { | |||||||||||||||||||||||||||
| 398 | 64 | ▶ | $self->$field( $opts->{$field} ) if ( defined( $opts->{$field} ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 399 | } | ||||||||||||||||||||||||||||
| 400 | } | ||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||
| 402 | # (re)initialize variables used in the closures | ||||||||||||||||||||||||||||
| 403 | 47 | $reggrp_comments = $self->reggrp_comments; | |||||||||||||||||||||||||||
| 404 | 47 | $reggrp_clean = $self->reggrp_clean; | |||||||||||||||||||||||||||
| 405 | 47 | $reggrp_whitespace = $self->reggrp_whitespace; | |||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||
| 407 | 47 | my $copyright_comment = ''; | |||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||
| 409 | 47 | ▶ | if ( ${$javascript} =~ /$COPYRIGHT_COMMENT/ism ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 410 | 3 | $copyright_comment = $1; | |||||||||||||||||||||||||||
| 411 | } | ||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||
| 413 | # Resets copyright_comment() if there is no copyright comment | ||||||||||||||||||||||||||||
| 414 | 47 | $self->_copyright_comment( $copyright_comment ); | |||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||
| 416 | 47 | ▶ | if ( not $self->no_compress_comment() and ${$javascript} =~ /$PACKER_COMMENT/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $self->no_compress_comment and ${$javascript;} =~ /$PACKER_COMMENT/
MC/DC100%2/2
not $self->no_compress_comment and ${$javascript;} =~ /$PACKER_COMMENT/
not $self->no_compress_comment
${$javascript;} =~ /$PACKER_COMMENT/
Truth table100%3/3
not(A) and B
A= not $self->no_compress_commentB= ${$javascript;} =~ /$PACKER_COMMENT/
| |||||||||||||||||||||||||||||
| 417 | 1 | my $compress = $1; | |||||||||||||||||||||||||||
| 418 | 1 | ▶ | if ( $compress eq '_no_compress_' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 419 | 1 | ▶ | return ${$javascript} if ( $cont eq 'scalar' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 420 | 1 | return; | |||||||||||||||||||||||||||
| 421 | } | ||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||
| 423 | 0 | $self->compress( $compress ); | |||||||||||||||||||||||||||
| 424 | } | ||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||
| 426 | 46 | ${$javascript} =~ s/\r//gsm; | |||||||||||||||||||||||||||
| 427 | 46 | ${$javascript} .= "\n"; | |||||||||||||||||||||||||||
| 428 | 46 | $self->reggrp_comments()->exec( $javascript ); | |||||||||||||||||||||||||||
| 429 | 46 | $self->reggrp_clean()->exec( $javascript ); | |||||||||||||||||||||||||||
| 430 | 46 | $self->reggrp_whitespace()->exec( $javascript ); | |||||||||||||||||||||||||||
| 431 | 46 | $self->reggrp_concat_store()->exec( $javascript ); | |||||||||||||||||||||||||||
| 432 | 46 | $self->reggrp_concat()->exec( $javascript ); | |||||||||||||||||||||||||||
| 433 | 46 | $self->reggrp_concat_store()->restore_stored( $javascript ); | |||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||
| 435 | 46 | ▶ | if ( $self->compress() ne 'clean' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 436 | 17 | $self->reggrp_data_store()->exec( $javascript ); | |||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||
| 438 | 17 | ▶ | while ( ${$javascript} =~ /$SHRINK_VARS->{BLOCK}/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 439 | 27 | ${$javascript} =~ s/$SHRINK_VARS->{BLOCK}/$self->_store_block_data( $1 )/egsm; | |||||||||||||||||||||||||||
| 440 | } | ||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||
| 442 | 17 | $self->_restore_data( $javascript, 'block_data', $SHRINK_VARS->{ENCODED_BLOCK} ); | |||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||
| 444 | 17 | my %shrunk_vars = map { $_ => 1 } ( ${$javascript} =~ /$SHRINK_VARS->{SHRUNK}/g ); | |||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||
| 446 | 17 | my $cnt = 0; | |||||||||||||||||||||||||||
| 447 | 17 | foreach my $shrunk_var ( sort keys( %shrunk_vars ) ) { | |||||||||||||||||||||||||||
| 448 | 58 | my $short_id; | |||||||||||||||||||||||||||
| 449 | do { | ||||||||||||||||||||||||||||
| 450 | 70 | $short_id = $self->_encode52( $cnt++ ); | |||||||||||||||||||||||||||
| 451 | 58 | ▶ | } while ( ${$javascript} =~ /[^a-zA-Z0-9_\\x24\.]\Q$short_id\E[^a-zA-Z0-9_\\x24:]/ ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||
| 453 | 58 | ${$javascript} =~ s/$shrunk_var/$short_id/g; | |||||||||||||||||||||||||||
| 454 | } | ||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||
| 456 | 17 | $self->reggrp_data_store()->restore_stored( $javascript ); | |||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||
| 458 | 17 | $self->{block_data} = []; | |||||||||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||
| 461 | 46 | ▶ | if ( $self->compress() eq 'obfuscate' or $self->compress() eq 'best' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->compress eq "obfuscate" or $self->compress eq "best"
MC/DC100%2/2
$self->compress eq "obfuscate" or $self->compress eq "best"
$self->compress eq "obfuscate"
$self->compress eq "best"
Truth table100%3/3
A or B
A= $self->compress eq "obfuscate"B= $self->compress eq "best"
| |||||||||||||||||||||||||||||
| 462 | 7 | my $words = {}; | |||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||
| 464 | 7 | my @words = ${$javascript} =~ /$BASE62_VARS->{WORDS}/g; | |||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||
| 466 | 7 | my $idx = 0; | |||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||
| 468 | 7 | foreach ( @words ) { | |||||||||||||||||||||||||||
| 469 | 10898 | $words->{$_}->{count}++; | |||||||||||||||||||||||||||
| 470 | } | ||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||
| 472 | 7 | WORD: foreach my $word ( sort { $words->{$b}->{count} <=> $words->{$a}->{count} } sort keys( %{$words} ) ) { | |||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||
| 474 | 3122 | ▶ | if ( exists( $words->{$word}->{encoded} ) and $words->{$word}->{encoded} eq $word ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $words->{$word}{"encoded"} and $words->{$word}{"encoded"} eq $word
MC/DC50%1/2
exists $words->{$word}{"encoded"} and $words->{$word}{"encoded"} eq $word
exists $words->{$word}{"encoded"}
$words->{$word}{"encoded"} eq $word
Truth table66%2/3
A and B
A= exists $words->{$word}{"encoded"}B= $words->{$word}{"encoded"} eq $word
| |||||||||||||||||||||||||||||
| 475 | 151 | next WORD; | |||||||||||||||||||||||||||
| 476 | } | ||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||
| 478 | 2971 | my $encoded = $self->_encode62( $idx ); | |||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||
| 480 | 2971 | ▶ | if ( exists( $words->{$encoded} ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 481 | 209 | my $next = 0; | |||||||||||||||||||||||||||
| 482 | 209 | ▶ | if ( exists( $words->{$encoded}->{encoded} ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 483 | 58 | $words->{$word}->{encoded} = $words->{$encoded}->{encoded}; | |||||||||||||||||||||||||||
| 484 | 58 | $words->{$word}->{index} = $words->{$encoded}->{index}; | |||||||||||||||||||||||||||
| 485 | 58 | $words->{$word}->{minus} = length( $word ) - length( $words->{$word}->{encoded} ); | |||||||||||||||||||||||||||
| 486 | 58 | $next = 1; | |||||||||||||||||||||||||||
| 487 | } | ||||||||||||||||||||||||||||
| 488 | 209 | $words->{$encoded}->{encoded} = $encoded; | |||||||||||||||||||||||||||
| 489 | 209 | $words->{$encoded}->{index} = $idx; | |||||||||||||||||||||||||||
| 490 | 209 | $words->{$encoded}->{minus} = 0; | |||||||||||||||||||||||||||
| 491 | 209 | $idx++; | |||||||||||||||||||||||||||
| 492 | 209 | ▶ | next WORD if ( $next ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 493 | 151 | redo WORD; | |||||||||||||||||||||||||||
| 494 | } | ||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||
| 496 | 2762 | $words->{$word}->{encoded} = $encoded; | |||||||||||||||||||||||||||
| 497 | 2762 | $words->{$word}->{index} = $idx; | |||||||||||||||||||||||||||
| 498 | 2762 | $words->{$word}->{minus} = length( $word ) - length( $encoded ); | |||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||
| 500 | 2762 | $idx++; | |||||||||||||||||||||||||||
| 501 | } | ||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||
| 503 | 7 | my $packed_length = length( ${$javascript} ); | |||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||
| 505 | 7 | my ( @pk, @pattern ) = ( (), () ); | |||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||
| 507 | 7 | foreach ( sort { $words->{$a}->{index} <=> $words->{$b}->{index} } sort keys( %{$words} ) ) { | |||||||||||||||||||||||||||
| 508 | 2971 | $packed_length -= ( $words->{$_}->{count} * $words->{$_}->{minus} ); | |||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||
| 510 | 2971 | ▶ | if ( $words->{$_}->{encoded} ne $_ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 511 | 2762 | push( @pk, $_ ); | |||||||||||||||||||||||||||
| 512 | 2762 | push( @pattern, $words->{$_}->{encoded} ); | |||||||||||||||||||||||||||
| 513 | } | ||||||||||||||||||||||||||||
| 514 | else { | ||||||||||||||||||||||||||||
| 515 | 209 | push( @pk, '' ); | |||||||||||||||||||||||||||
| 516 | 209 | push( @pattern, '' ); | |||||||||||||||||||||||||||
| 517 | } | ||||||||||||||||||||||||||||
| 518 | } | ||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||
| 520 | 7 | my $size = scalar( @pattern ); | |||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||
| 522 | 7 | ▶ | splice( @pattern, 62 ) if ( scalar( @pattern ) > 62 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||
| 524 | 7 | my $pd = join( '|', @pattern ); | |||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||
| 526 | 7 | $self->reggrp_trim()->exec( \$pd ); | |||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||
| 528 | 7 | ▶ | unless ( $pd ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 529 | 0 | $pd = '^$'; | |||||||||||||||||||||||||||
| 530 | } | ||||||||||||||||||||||||||||
| 531 | else { | ||||||||||||||||||||||||||||
| 532 | 7 | $pd = '[' . $pd . ']'; | |||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||
| 534 | 7 | ▶ | if ( $size > 62 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 535 | 3 | $pd = '(' . $pd . '|'; | |||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||
| 537 | 3 | my $enc = $self->_encode62( $size ); | |||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||
| 539 | 3 | my ( $c ) = $enc =~ /(^.)/; | |||||||||||||||||||||||||||
| 540 | 3 | my $ord = ord( $c ); | |||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||
| 542 | 3 | my $mul = length( $enc ) - 1; | |||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||
| 544 | 3 | my $is62 = 0; | |||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||
| 546 | 3 | ▶ | if ( $ord >= 65 ) { | ||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||
| 547 | 1 | ▶ | if ( $c eq 'Z' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 548 | 0 | $mul += 1; | |||||||||||||||||||||||||||
| 549 | 0 | $is62 = 1; | |||||||||||||||||||||||||||
| 550 | } | ||||||||||||||||||||||||||||
| 551 | else { | ||||||||||||||||||||||||||||
| 552 | 1 | $pd .= '[0-9a'; | |||||||||||||||||||||||||||
| 553 | 1 | ▶ | if ( $ord > 97 ) { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 554 | 0 | $pd .= '-' . $c; | |||||||||||||||||||||||||||
| 555 | } | ||||||||||||||||||||||||||||
| 556 | elsif ( $ord > 65 ) { | ||||||||||||||||||||||||||||
| 557 | 0 | $pd .= '-zA-' . $c; | |||||||||||||||||||||||||||
| 558 | } | ||||||||||||||||||||||||||||
| 559 | elsif ( $ord == 65 ) { | ||||||||||||||||||||||||||||
| 560 | 1 | $pd .= '-zA'; | |||||||||||||||||||||||||||
| 561 | } | ||||||||||||||||||||||||||||
| 562 | 1 | $pd .= ']'; | |||||||||||||||||||||||||||
| 563 | } | ||||||||||||||||||||||||||||
| 564 | } | ||||||||||||||||||||||||||||
| 565 | elsif ( $ord == 57 ) { | ||||||||||||||||||||||||||||
| 566 | 1 | $pd .= '[0-9]'; | |||||||||||||||||||||||||||
| 567 | } | ||||||||||||||||||||||||||||
| 568 | elsif ( $ord == 50 ) { | ||||||||||||||||||||||||||||
| 569 | 0 | $pd .= '[12]'; | |||||||||||||||||||||||||||
| 570 | } | ||||||||||||||||||||||||||||
| 571 | elsif ( $ord == 49 ) { | ||||||||||||||||||||||||||||
| 572 | 1 | $pd .= '1'; | |||||||||||||||||||||||||||
| 573 | } | ||||||||||||||||||||||||||||
| 574 | else { | ||||||||||||||||||||||||||||
| 575 | 0 | $pd .= '[0-' . ( $ord - 48 ) . ']'; | |||||||||||||||||||||||||||
| 576 | } | ||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||
| 578 | 3 | ▶ | $pd .= '[0-9a-zA-Z]' . ( ( $mul > 1 ) ? '{' . $mul . '}' : '' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 579 | |||||||||||||||||||||||||||||
| 580 | 3 | ▶ | $mul-- if ( $is62 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 581 | |||||||||||||||||||||||||||||
| 582 | 3 | ▶ | if ( $mul > 1 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 583 | 0 | ▶ | for ( my $i = $mul; $i >= 2; $i-- ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 584 | 0 | $pd .= '|[0-9a-zA-Z]{' . $i . '}'; | |||||||||||||||||||||||||||
| 585 | } | ||||||||||||||||||||||||||||
| 586 | } | ||||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||
| 588 | 3 | $pd .= ')'; | |||||||||||||||||||||||||||
| 589 | } | ||||||||||||||||||||||||||||
| 590 | } | ||||||||||||||||||||||||||||
| 591 | 7 | $packed_length += length( $pd ); | |||||||||||||||||||||||||||
| 592 | |||||||||||||||||||||||||||||
| 593 | 7 | my $pk = join( '|', @pk ); | |||||||||||||||||||||||||||
| 594 | 7 | $pk =~ s/(?>\|+)$//; | |||||||||||||||||||||||||||
| 595 | 7 | $packed_length += length( $pk ); | |||||||||||||||||||||||||||
| 596 | |||||||||||||||||||||||||||||
| 597 | 7 | ▶ | my $pc = length( $pk ) ? ( ( $pk =~ tr/|/|/ ) + 1 ) : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 598 | 7 | $packed_length += length( $pc ); | |||||||||||||||||||||||||||
| 599 | |||||||||||||||||||||||||||||
| 600 | 7 | my $pa = '[]'; | |||||||||||||||||||||||||||
| 601 | 7 | $packed_length += length( $pa ); | |||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||
| 603 | 7 | ▶ | my $pe = $BASE62_VARS->{ 'ENCODE' . ( $pc > 10 ? $pc > 36 ? 62 : 36 : 10 ) }; | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 604 | 7 | $packed_length += length( $pe ); | |||||||||||||||||||||||||||
| 605 | |||||||||||||||||||||||||||||
| 606 | 7 | $packed_length += length( $BASE62_VARS->{UNPACK} ); | |||||||||||||||||||||||||||
| 607 | 7 | $packed_length -= ( $BASE62_VARS->{UNPACK} =~ s/(%s|%d)/$1/g ) * 2; | |||||||||||||||||||||||||||
| 608 | |||||||||||||||||||||||||||||
| 609 | 7 | my ( @length_matches ) = ${$javascript} =~ s/((?>[\r\n]+))/$1/g; | |||||||||||||||||||||||||||
| 610 | 7 | foreach ( @length_matches ) { | |||||||||||||||||||||||||||
| 611 | 7 | $packed_length -= length( $_ ) - 3; | |||||||||||||||||||||||||||
| 612 | } | ||||||||||||||||||||||||||||
| 613 | |||||||||||||||||||||||||||||
| 614 | 7 | $packed_length += ${$javascript} =~ tr/\\\'/\\\'/; | |||||||||||||||||||||||||||
| 615 | |||||||||||||||||||||||||||||
| 616 | 7 | ▶ | if ( $self->compress() eq 'obfuscate' or $packed_length <= length( ${$javascript} ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->compress eq "obfuscate" or $packed_length <= length ${$javascript;}
MC/DC100%2/2
$self->compress eq "obfuscate" or $packed_length <= length ${$javascript;}
$self->compress eq "obfuscate"
$packed_length <= length ${$javascript;}
Truth table100%3/3
A or B
A= $self->compress eq "obfuscate"B= $packed_length <= length ${$javascript;}
| |||||||||||||||||||||||||||||
| 617 | |||||||||||||||||||||||||||||
| 618 | 5 | ${$javascript} =~ s/$BASE62_VARS->{WORDS}/sprintf( "%s", $words->{$1}->{encoded} )/eg; | |||||||||||||||||||||||||||
| 619 | |||||||||||||||||||||||||||||
| 620 | 5 | ${$javascript} =~ s/([\\'])/\\$1/g; | |||||||||||||||||||||||||||
| 621 | 5 | ${$javascript} =~ s/[\r\n]+/\\n/g; | |||||||||||||||||||||||||||
| 622 | |||||||||||||||||||||||||||||
| 623 | 5 | my $pp = ${$javascript}; | |||||||||||||||||||||||||||
| 624 | |||||||||||||||||||||||||||||
| 625 | 5 | ${$javascript} = sprintf( $BASE62_VARS->{UNPACK}, $pe, $pd, $pp, $pa, $pc, $pk ); | |||||||||||||||||||||||||||
| 626 | } | ||||||||||||||||||||||||||||
| 627 | |||||||||||||||||||||||||||||
| 628 | } | ||||||||||||||||||||||||||||
| 629 | |||||||||||||||||||||||||||||
| 630 | 46 | ▶ | if ( not $self->remove_copyright() ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 631 | 45 | ▶ | ${$javascript} = ( $self->copyright() || $self->_copyright_comment() ) . ${$javascript}; | ||||||||||||||||||||||||||
|
Condition100%3/3
$self->copyright || $self->_copyright_comment
MC/DC100%2/2
$self->copyright || $self->_copyright_comment
$self->copyright
$self->_copyright_comment
Truth table100%3/3
A || B
A= $self->copyrightB= $self->_copyright_comment
| |||||||||||||||||||||||||||||
| 632 | } | ||||||||||||||||||||||||||||
| 633 | |||||||||||||||||||||||||||||
| 634 | # GH #9 bodge for sourceMappingURL | ||||||||||||||||||||||||||||
| 635 | 46 | ${$javascript} =~ s/__NEW_LINE__/\n/xsmg; | |||||||||||||||||||||||||||
| 636 | 46 | ${$javascript} =~ s!//#sourceMappingURL!//# sourceMappingURL!g; | |||||||||||||||||||||||||||
| 637 | 46 | chomp( ${$javascript} ); | |||||||||||||||||||||||||||
| 638 | |||||||||||||||||||||||||||||
| 639 | 46 | ▶ | return ${$javascript} if ( $cont eq 'scalar' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 640 | } | ||||||||||||||||||||||||||||
| 641 | |||||||||||||||||||||||||||||
| 642 | sub _restore_data { | ||||||||||||||||||||||||||||
| 643 | 379 | ▶ | my ( $self, $string_ref, $data_name, $pattern ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_restore_data: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 644 | |||||||||||||||||||||||||||||
| 645 | 379 | ▶ | while ( ${$string_ref} =~ /$pattern/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 646 | 154 | ${$string_ref} =~ s/$pattern/$self->{$data_name}->[$1]/egsm; | |||||||||||||||||||||||||||
| 647 | } | ||||||||||||||||||||||||||||
| 648 | } | ||||||||||||||||||||||||||||
| 649 | |||||||||||||||||||||||||||||
| 650 | sub _store_block_data { | ||||||||||||||||||||||||||||
| 651 | 511 | ▶ | my ( $self, $match ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_store_block_data: called CC=13 SCAR=25.7
| |||||||||||||||||||||||||||||
| 652 | |||||||||||||||||||||||||||||
| 653 | 511 | my ( undef, $prefix, $blocktype, $args, $block ) = $match =~ /$SHRINK_VARS->{BLOCK}/; | |||||||||||||||||||||||||||
| 654 | |||||||||||||||||||||||||||||
| 655 | 511 | ▶ | $prefix ||= ''; | ||||||||||||||||||||||||||
|
Condition100%2/2
$prefix ||= ""
MC/DC100%1/1
$prefix ||= ""
$prefix
Truth table100%2/2
A
A= $prefix
| |||||||||||||||||||||||||||||
| 656 | 511 | ▶ | $blocktype ||= ''; | ||||||||||||||||||||||||||
|
Condition100%2/2
$blocktype ||= ""
MC/DC100%1/1
$blocktype ||= ""
$blocktype
Truth table100%2/2
A
A= $blocktype
| |||||||||||||||||||||||||||||
| 657 | 511 | ▶ | $args ||= ''; | ||||||||||||||||||||||||||
|
Condition100%2/2
$args ||= ""
MC/DC100%1/1
$args ||= ""
$args
Truth table100%2/2
A
A= $args
| |||||||||||||||||||||||||||||
| 658 | 511 | my $replacement = ''; | |||||||||||||||||||||||||||
| 659 | 511 | ▶ | if ( $blocktype eq 'function' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 660 | |||||||||||||||||||||||||||||
| 661 | 181 | $self->_restore_data( \$block, 'block_data', $SHRINK_VARS->{SCOPED} ); | |||||||||||||||||||||||||||
| 662 | |||||||||||||||||||||||||||||
| 663 | 181 | $args =~ s/\s*//g; | |||||||||||||||||||||||||||
| 664 | |||||||||||||||||||||||||||||
| 665 | 181 | $block = $args . $block; | |||||||||||||||||||||||||||
| 666 | 181 | $prefix =~ s/$SHRINK_VARS->{BRACKETS}//; | |||||||||||||||||||||||||||
| 667 | |||||||||||||||||||||||||||||
| 668 | 181 | $args =~ s/^\(|\)$//g; | |||||||||||||||||||||||||||
| 669 | |||||||||||||||||||||||||||||
| 670 | 181 | ▶ | while ( $args =~ /$SHRINK_VARS->{CALLER}/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 671 | 0 | $args =~ s/$SHRINK_VARS->{CALLER}//gsm; | |||||||||||||||||||||||||||
| 672 | } | ||||||||||||||||||||||||||||
| 673 | |||||||||||||||||||||||||||||
| 674 | 181 | my @vars = grep( $_, split( /\s*,\s*/, $args ) ); | |||||||||||||||||||||||||||
| 675 | 181 | ▶ | my $do_shrink = grep( $_ eq '_no_shrink_', @vars ) ? 0 : 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 676 | |||||||||||||||||||||||||||||
| 677 | 181 | my %block_vars = (); | |||||||||||||||||||||||||||
| 678 | 181 | ▶ | if ( $do_shrink ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 679 | 180 | %block_vars = map { $_ => 1 } ( $block =~ /$SHRINK_VARS->{VARS}/g ), grep( $_ ne '$super', @vars ); | |||||||||||||||||||||||||||
| 680 | } | ||||||||||||||||||||||||||||
| 681 | |||||||||||||||||||||||||||||
| 682 | 181 | $self->_restore_data( \$block, 'block_data', $SHRINK_VARS->{ENCODED_BLOCK} ); | |||||||||||||||||||||||||||
| 683 | |||||||||||||||||||||||||||||
| 684 | 181 | ▶ | if ( $do_shrink ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 685 | |||||||||||||||||||||||||||||
| 686 | 180 | my $cnt = 0; | |||||||||||||||||||||||||||
| 687 | 180 | foreach my $block_var ( sort keys( %block_vars ) ) { | |||||||||||||||||||||||||||
| 688 | 468 | ▶ | if ( length( $block_var ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 689 | 468 | ▶ | while ( $block =~ /$SHRINK_VARS->{PREFIX}\Q$cnt\E\b/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 690 | 16 | $cnt++; | |||||||||||||||||||||||||||
| 691 | } | ||||||||||||||||||||||||||||
| 692 | |||||||||||||||||||||||||||||
| 693 | 468 | ▶ | while ( $block =~ /[^a-zA-Z0-9_\\x24\.]\Q$block_var\E[^a-zA-Z0-9_\\x24:]/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 694 | 491 | $block =~ s/([^a-zA-Z0-9_\\x24\.])\Q$block_var\E([^a-zA-Z0-9_\\x24:])/sprintf( "%s\x02%d%s", $1, $cnt, $2 )/eg; | |||||||||||||||||||||||||||
| 695 | } | ||||||||||||||||||||||||||||
| 696 | |||||||||||||||||||||||||||||
| 697 | 468 | $block =~ s/([^{,a-zA-Z0-9_\\x24\.])\Q$block_var\E:/sprintf( "%s\x02%d:", $1, $cnt )/eg; | |||||||||||||||||||||||||||
| 698 | |||||||||||||||||||||||||||||
| 699 | 468 | $cnt++; | |||||||||||||||||||||||||||
| 700 | } | ||||||||||||||||||||||||||||
| 701 | } | ||||||||||||||||||||||||||||
| 702 | } | ||||||||||||||||||||||||||||
| 703 | 181 | $replacement = sprintf( "%s~%d~", $prefix, scalar( @{ $self->{block_data} } ) ); | |||||||||||||||||||||||||||
| 704 | |||||||||||||||||||||||||||||
| 705 | 181 | push( @{ $self->{block_data} }, $block ); | |||||||||||||||||||||||||||
| 706 | } | ||||||||||||||||||||||||||||
| 707 | else { | ||||||||||||||||||||||||||||
| 708 | 330 | $replacement = sprintf( "~#%d~", scalar( @{ $self->{block_data} } ) ); | |||||||||||||||||||||||||||
| 709 | |||||||||||||||||||||||||||||
| 710 | 330 | push( @{ $self->{block_data} }, $prefix . $block ); | |||||||||||||||||||||||||||
| 711 | } | ||||||||||||||||||||||||||||
| 712 | |||||||||||||||||||||||||||||
| 713 | 511 | return $replacement; | |||||||||||||||||||||||||||
| 714 | } | ||||||||||||||||||||||||||||
| 715 | |||||||||||||||||||||||||||||
| 716 | sub _encode52 { | ||||||||||||||||||||||||||||
| 717 | 70 | ▶ | my ( $self, $c ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_encode52: called CC=4 SCAR=15.0
| |||||||||||||||||||||||||||||
| 718 | |||||||||||||||||||||||||||||
| 719 | 70 | my $m = $c % 52; | |||||||||||||||||||||||||||
| 720 | |||||||||||||||||||||||||||||
| 721 | 70 | ▶ | my $ret = $m > 25 ? chr( $m + 39 ) : chr( $m + 97 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 722 | |||||||||||||||||||||||||||||
| 723 | 70 | ▶ | if ( $c >= 52 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 724 | 0 | $ret = $self->_encode52( int( $c / 52 ) ) . $ret; | |||||||||||||||||||||||||||
| 725 | } | ||||||||||||||||||||||||||||
| 726 | |||||||||||||||||||||||||||||
| 727 | 70 | ▶ | $ret = substr( $ret, 1 ) . '0' if ( $ret =~ /^(do|if|in)$/ ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 728 | |||||||||||||||||||||||||||||
| 729 | 70 | return $ret; | |||||||||||||||||||||||||||
| 730 | } | ||||||||||||||||||||||||||||
| 731 | |||||||||||||||||||||||||||||
| 732 | sub _encode62 { | ||||||||||||||||||||||||||||
| 733 | 5725 | ▶ | my ( $self, $c ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_encode62: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 734 | |||||||||||||||||||||||||||||
| 735 | 5725 | my $m = $c % 62; | |||||||||||||||||||||||||||
| 736 | |||||||||||||||||||||||||||||
| 737 | 5725 | ▶ | my $ret = $m > 35 ? chr( $m + 29 ) : $m > 9 ? chr( $m + 87 ) : $m; | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 738 | |||||||||||||||||||||||||||||
| 739 | 5725 | ▶ | if ( $c >= 62 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 740 | 2751 | $ret = $self->_encode62( int( $c / 62 ) ) . $ret; | |||||||||||||||||||||||||||
| 741 | } | ||||||||||||||||||||||||||||
| 742 | |||||||||||||||||||||||||||||
| 743 | 5725 | return $ret; | |||||||||||||||||||||||||||
| 744 | } | ||||||||||||||||||||||||||||
| 745 | |||||||||||||||||||||||||||||
| 746 | 4 | 1; | |||||||||||||||||||||||||||
| 747 | |||||||||||||||||||||||||||||
| 748 | __END__ | ||||||||||||||||||||||||||||