File Coverage

blib/lib/WebService/Google/Closure/Types.pm
Criterion Covered Total %
statement 21 21 100.0
branch n/a
condition n/a
subroutine 7 7 100.0
pod n/a
total 28 28 100.0


line stmt bran cond sub pod time code
1             package WebService::Google::Closure::Types;
2              
3             use MooseX::Types
4 3         51 -declare => [
5             qw(
6             Stats
7             Warning
8             Error
9             ArrayRefOfWarnings
10             ArrayRefOfErrors
11             ArrayRefOfStrings
12             CompilationLevel
13             )
14 3     3   20 ];
  3         5  
15              
16 3     3   25813 use MooseX::Types::Moose qw( ArrayRef HashRef Str Int Undef );
  3         8  
  3         35  
17 3     3   22992 use Perl6::Junction qw( any );
  3         30552  
  3         276  
18 3     3   3635 use JSON;
  3         62163  
  3         49  
19              
20 3     3   2763 use WebService::Google::Closure::Type::Warning;
  3         16  
  3         226  
21 3     3   2614 use WebService::Google::Closure::Type::Error;
  3         13  
  3         150  
22 3     3   2411 use WebService::Google::Closure::Type::Stats;
  3         12  
  3         2490  
23              
24             subtype ArrayRefOfStrings,
25             as ArrayRef[Str];
26              
27             coerce ArrayRefOfStrings,
28             from Str,
29             via { [ $_ ] };
30              
31             my $level = {
32             NOOP => 0,
33             WHITESPACE_ONLY => 1,
34             SIMPLE_OPTIMIZATIONS => 2,
35             ADVANCED_OPTIMIZATIONS => 3,
36             };
37              
38             subtype CompilationLevel,
39             as Str,
40             where { any( keys(%$level) ) eq $_ },
41             message { "Illegal compilation level" };
42              
43             coerce CompilationLevel,
44             from Int,
45             via { my $in = $_; [ grep { $in == $level->{ $_ } } keys( %$level ) ]->[0] };
46              
47             coerce CompilationLevel,
48             from Str,
49             via { uc $_ };
50              
51             coerce CompilationLevel,
52             from Undef,
53             via { 'SIMPLE_OPTIMIZATIONS' };
54              
55             class_type Warning,
56             { class => 'WebService::Google::Closure::Type::Warning' };
57              
58             coerce Warning,
59             from HashRef,
60             via { WebService::Google::Closure::Type::Warning->new( $_ ) };
61              
62             class_type Error,
63             { class => 'WebService::Google::Closure::Type::Error' };
64              
65             coerce Error,
66             from HashRef,
67             via { WebService::Google::Closure::Type::Error->new( $_ ) };
68              
69             subtype ArrayRefOfWarnings,
70             as ArrayRef[Warning];
71              
72             coerce ArrayRefOfWarnings,
73             from ArrayRef[HashRef],
74             via { [ map { to_Warning( $_ ) } @$_ ] };
75              
76             subtype ArrayRefOfErrors,
77             as ArrayRef[Error];
78              
79             coerce ArrayRefOfErrors,
80             from ArrayRef[HashRef],
81             via { [ map { to_Error( $_ ) } @$_ ] };
82              
83             class_type Stats,
84             { class => 'WebService::Google::Closure::Type::Stats' };
85              
86             coerce Stats,
87             from HashRef,
88             via { WebService::Google::Closure::Type::Stats->new( $_ ) };
89              
90             1;