| 1 | package Javascript::Closure; | ||||||||||||||||||||||||||||
| 2 | 4 | ▶ | use 5.008008; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use LWP::UserAgent; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 4 | our $VERSION = 0.07; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 4 | ▶ | use constant { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 4 | WHITESPACE_ONLY => 'WHITESPACE_ONLY', | |||||||||||||||||||||||||||
| 11 | SIMPLE_OPTIMIZATIONS => 'SIMPLE_OPTIMIZATIONS', | ||||||||||||||||||||||||||||
| 12 | ADVANCED_OPTIMIZATIONS => 'ADVANCED_OPTIMIZATIONS', | ||||||||||||||||||||||||||||
| 13 | QUIET => 'QUIET', | ||||||||||||||||||||||||||||
| 14 | DEFAULT => 'DEFAULT', | ||||||||||||||||||||||||||||
| 15 | VERBOSE => 'VERBOSE', | ||||||||||||||||||||||||||||
| 16 | COMPILED_CODE => 'compiled_code', | ||||||||||||||||||||||||||||
| 17 | WARNINGS => 'warnings', | ||||||||||||||||||||||||||||
| 18 | ERRORS => 'errors', | ||||||||||||||||||||||||||||
| 19 | STATISTICS => 'statistics', | ||||||||||||||||||||||||||||
| 20 | TEXT => 'text', | ||||||||||||||||||||||||||||
| 21 | JSON => 'json', | ||||||||||||||||||||||||||||
| 22 | XML => 'xml', | ||||||||||||||||||||||||||||
| 23 | CLOSURE_COMPILER_SERVICE=>'http://closure-compiler.appspot.com/compile' | ||||||||||||||||||||||||||||
| 24 | 4 | }; | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 4 | my @compilation_level = qw(WHITESPACE_ONLY SIMPLE_OPTIMIZATIONS ADVANCED_OPTIMIZATIONS); | |||||||||||||||||||||||||||
| 27 | 4 | my @output_info = qw(COMPILED_CODE WARNINGS ERRORS STATISTICS); | |||||||||||||||||||||||||||
| 28 | 4 | my @output_format = qw(TEXT JSON XML); | |||||||||||||||||||||||||||
| 29 | 4 | my @warning_level = qw(QUIET DEFAULT VERBOSE); | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 4 | require Exporter; | |||||||||||||||||||||||||||
| 32 | 4 | our @ISA = qw(Exporter); | |||||||||||||||||||||||||||
| 33 | 4 | our @EXPORT_OK = ('minify',@compilation_level,@output_info,@output_format,@warning_level); | |||||||||||||||||||||||||||
| 34 | 4 | our %EXPORT_TAGS = (CONSTANTS => [@compilation_level,@output_info,@output_format,@warning_level]); | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 4 | our $TIMEOUT = 5; | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 0 | ▶ | sub minify { | ||||||||||||||||||||||||||
|
Subroutine
minify: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||
| 39 | 0 | my %args = @_; | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 0 | my %send = (); | |||||||||||||||||||||||||||
| 42 | 0 | ▶ | $send{output_info} = _verify(\@output_info, $args{output_info} ,'lower') || COMPILED_CODE; | ||||||||||||||||||||||||||
|
Condition0%0/2
_verify(\@output_info, $args{'output_info'}, 'lower') || 'compiled_code'
MC/DC0%0/1
_verify(\@output_info, $args{'output_info'}, 'lower') || 'compiled_code'
_verify(\@output_info, $args{'output_info'}, 'lower')
Truth table0%0/2
A
A= _verify(\@output_info, $args{'output_info'}, 'lower')
| |||||||||||||||||||||||||||||
| 43 | 0 | ▶ | $send{output_format} = _verify(\@output_format, $args{output_format} ,'lower') || TEXT; | ||||||||||||||||||||||||||
|
Condition0%0/2
_verify(\@output_format, $args{'output_format'}, 'lower') || 'text'
MC/DC0%0/1
_verify(\@output_format, $args{'output_format'}, 'lower') || 'text'
_verify(\@output_format, $args{'output_format'}, 'lower')
Truth table0%0/2
A
A= _verify(\@output_format, $args{'output_format'}, 'lower')
| |||||||||||||||||||||||||||||
| 44 | 0 | ▶ | $send{compilation_level} = _verify(\@compilation_level,$args{compilation_level} ) || WHITESPACE_ONLY; | ||||||||||||||||||||||||||
|
Condition0%0/2
_verify(\@compilation_level, $args{'compilation_level'}) || 'WHITESPACE_ONLY'
MC/DC0%0/1
_verify(\@compilation_level, $args{'compilation_level'}) || 'WHITESPACE_ONLY'
_verify(\@compilation_level, $args{'compilation_level'})
Truth table0%0/2
A
A= _verify(\@compilation_level, $args{'compilation_level'})
| |||||||||||||||||||||||||||||
| 45 | 0 | ▶ | $send{warning_level} = _verify(\@warning_level ,$args{warning_level} ) || DEFAULT; | ||||||||||||||||||||||||||
|
Condition0%0/2
_verify(\@warning_level, $args{'warning_level'}) || 'DEFAULT'
MC/DC0%0/1
_verify(\@warning_level, $args{'warning_level'}) || 'DEFAULT'
_verify(\@warning_level, $args{'warning_level'})
Truth table0%0/2
A
A= _verify(\@warning_level, $args{'warning_level'})
| |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 0 | ▶ | my $js = $args{input} || 'var test=true;//this is a test'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$args{'input'} || 'var test=true;//this is a test'
MC/DC0%0/1
$args{'input'} || 'var test=true;//this is a test'
$args{'input'}
Truth table0%0/2
A
A= $args{'input'}
| |||||||||||||||||||||||||||||
| 48 | #create the user agent | ||||||||||||||||||||||||||||
| 49 | 0 | my $ua = _create_ua(); | |||||||||||||||||||||||||||
| 50 | 0 | my $source = _cleanup_code_source($ua,$js); | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 0 | ▶ | $send{js_code} = $source->{js_code} if(@{ $source->{js_code} } > 0); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | 0 | ▶ | $send{code_url} = $source->{code_url} if(@{ $source->{code_url} } > 0); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 0 | return _compile($ua,\%send); | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | #hacky i know | ||||||||||||||||||||||||||||
| 59 | 0 | ▶ | sub _verify { | ||||||||||||||||||||||||||
|
Subroutine
_verify: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||
| 60 | 0 | my ($vars,$value,$lower) = @_; | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 0 | ▶ | return undef if(!$value);#set default value | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 0 | ▶ | $value = [$value] if(ref($value) ne 'ARRAY'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 0 | my $choice = join(',',@$vars); | |||||||||||||||||||||||||||
| 67 | 0 | ▶ | $choice = "\L$choice" if($lower); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 0 | foreach my $val (@$value){ | |||||||||||||||||||||||||||
| 70 | 0 | ▶ | croak $val.' is not in:'.$choice if($val && !grep(/^$val$/i,@$vars)); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$val and not grep(/^$val$/i, @$vars)
MC/DC0%0/2
$val and not grep(/^$val$/i, @$vars)
$val
not grep(/^$val$/i, @$vars)
Truth table0%0/3
A and not(B)
A= $valB= not grep(/^$val$/i, @$vars)
| |||||||||||||||||||||||||||||
| 71 | 0 | ▶ | $val = ($lower) ? "\L$val" :"\U$val"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | 0 | return $value; | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 0 | ▶ | sub _create_ua { | ||||||||||||||||||||||||||
|
Subroutine
_create_ua: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 77 | 0 | my $ua = LWP::UserAgent->new; | |||||||||||||||||||||||||||
| 78 | 0 | $ua-> agent(__PACKAGE__."/".$VERSION); | |||||||||||||||||||||||||||
| 79 | 0 | $ua-> timeout($TIMEOUT); | |||||||||||||||||||||||||||
| 80 | 0 | return $ua; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 0 | ▶ | sub _compile { | ||||||||||||||||||||||||||
|
Subroutine
_compile: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 84 | 0 | my ($ua,$args)=@_; | |||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 0 | my $res = $ua->post(CLOSURE_COMPILER_SERVICE,$args); | |||||||||||||||||||||||||||
| 87 | 0 | ▶ | return $res->content if ($res->is_success); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 0 | croak 'Fail to connect to '.CLOSURE_COMPILER_SERVICE.':'.$res->as_string; | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 0 | ▶ | sub _cleanup_code_source { | ||||||||||||||||||||||||||
|
Subroutine
_cleanup_code_source: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||
| 93 | 0 | my ($ua,$code_source) = @_; | |||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 0 | ▶ | $code_source = [$code_source] if(ref($code_source) ne 'ARRAY'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 0 | my (@str,@urls); | |||||||||||||||||||||||||||
| 98 | 0 | foreach my $js (@$code_source) { | |||||||||||||||||||||||||||
| 99 | 0 | ▶ | if($js!~m{^http://}){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | 0 | push @str,$js; next; | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | 0 | ▶ | if($ua->get($js)->is_success){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | 0 | push @urls,$js; | |||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | else { | ||||||||||||||||||||||||||||
| 106 | 0 | carp 'The following url could not be fetched:'.$js; | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | return { | ||||||||||||||||||||||||||||
| 110 | 0 | js_code =>\@str, | |||||||||||||||||||||||||||
| 111 | code_url =>\@urls | ||||||||||||||||||||||||||||
| 112 | }; | ||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 4 | "The earth is blue like an orange."; | |||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | __END__ | ||||||||||||||||||||||||||||