Closure.pm

filter: Statementstmt 88.5% 54 / 61 Branchbran 83.3% 5 / 6 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 91.6% 11 / 12 Podpod 100% 1 / 1 totaltotal 84.7% 72 / 85 CC 7 SCAR 12.0
CC
7
Cov
86%
compile
6.3
_set_file
6.0
BEGIN
1.0
CRAP 3.3
↑ Summary Closure/Response.pm »
1 package WebService::Google::Closure;
2  
3 3 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use MooseX::Types::Moose qw( ArrayRef Str Int );
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use File::Slurp qw( slurp );
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 3 ▶use WebService::Google::Closure::Types qw( ArrayRefOfStrings CompilationLevel );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use WebService::Google::Closure::Response;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 3 our $VERSION = '0.13';
13 3 $VERSION = eval $VERSION;
14  
15 3 has js_code => (
16 is => 'rw',
17 isa => Str,
18 );
19  
20 3 has file => (
21 is => 'ro',
22 isa => ArrayRefOfStrings,
23 trigger => \&_set_file,
24 coerce => 1,
25 );
26  
27 3 has code_url => (
28 is => 'ro',
29 isa => ArrayRefOfStrings,
30 init_arg => 'url',
31 coerce => 1,
32 );
33  
34 3 has compilation_level => (
35 is => 'ro',
36 isa => CompilationLevel,
37 coerce => 1,
38 );
39  
40 3 has timeout => (
41 is => 'ro',
42 isa => Int,
43 default => 10,
44 );
45  
46 3 has post_url => (
47 is => 'ro',
48 isa => Str,
49 default => 'https://closure-compiler.appspot.com/compile',
50 init_arg => undef,
51 );
52  
53 3 has output_format => (
54 is => 'ro',
55 isa => Str,
56 default => 'json',
57 init_arg => undef,
58 );
59  
60 3 has output_info => (
61 is => 'ro',
62 isa => ArrayRef[Str],
63 init_arg => undef,
64 lazy_build => 1,
65 );
66  
67 3 has ua => (
68 is => 'ro',
69 init_arg => undef,
70 lazy_build => 1,
71 );
72  
73 0 ▶sub _set_file {
Subroutine _set_file: not called CC=2 SCAR=17.9
74 0 my $self = shift;
75 0 my $content = '';
76 0 foreach my $f ( @{ $self->file } ) {
77 0 $content .= slurp( $f );
78 }
79 0 $self->js_code( $content );
80 }
81  
82 2 ▶sub _build_ua {
Subroutine _build_ua: called CC=1 SCAR=0.0
83 2 my $self = shift;
84 2 my $ua = LWP::UserAgent->new;
85 2 $ua->timeout( $self->timeout );
86 2 $ua->env_proxy;
87 2 $ua->agent( __PACKAGE__ . '/' . $VERSION );
88 2 return $ua;
89 }
90  
91 2 ▶sub _build_output_info {
Subroutine _build_output_info: called CC=1 SCAR=0.0
92 2 return [ qw( compiled_code statistics warnings errors ) ];
93 }
94  
95 2 ▶sub compile {
Subroutine compile: called CC=6 SCAR=18.4
Pod documented
96 2 my $self = shift;
97  
98 2 ▶ if ( $self->compilation_level && $self->compilation_level eq 'NOOP' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->compilation_level and $self->compilation_level eq "NOOP") 0 2 2
Condition33%1/3
$self->compilation_level and $self->compilation_level eq "NOOP"
!ll&&!rl&&r
020
MC/DC0%0/2
$self->compilation_level and $self->compilation_level eq "NOOP"
$self->compilation_level $self->compilation_level eq "NOOP"
Truth table33%1/3
A and B
A= $self->compilation_levelB= $self->compilation_level eq "NOOP"
ABresult
0X0
100
111
99 # Don't bother the compiler
100 0 return WebService::Google::Closure::Response->new(
101 format => $self->output_format,
102 code => $self->js_code,
103 );
104 }
105  
106 2 my $post_args = {};
107 2 foreach my $arg (qw( js_code code_url compilation_level output_format output_info )) {
108 10 ▶ next unless $self->$arg;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->$arg 2 8 10
109 8 $post_args->{ $arg } = $self->$arg;
110 }
111  
112 2 my $res = $self->ua->post(
113 $self->post_url, $post_args
114 );
115 2 ▶ unless ( $res->is_success ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($res->is_success) 1 1 2
116 1 croak "Error posting request to Google - " . $res->status_line;
117 }
118  
119 1 return WebService::Google::Closure::Response->new(
120 format => $self->output_format,
121 content => $res->content,
122 );
123 }
124  
125  
126 3 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
127 3 __PACKAGE__->meta->make_immutable;
128 3 1;
129  
130 __END__
↑ Summary Closure/Response.pm »