| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
=head1 NAME |
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
WebService::TypePad::Util::Coerce - Utility functions used for coercing values into and out of TypePad::API::Object subclasses |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=cut |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
package WebService::TypePad::Util::Coerce; |
|
9
|
|
|
|
|
|
|
|
|
10
|
3
|
|
|
3
|
|
34618
|
use strict; |
|
|
3
|
|
|
|
|
19
|
|
|
|
3
|
|
|
|
|
128
|
|
|
11
|
3
|
|
|
3
|
|
15
|
use warnings; |
|
|
3
|
|
|
|
|
5
|
|
|
|
3
|
|
|
|
|
160
|
|
|
12
|
3
|
|
|
3
|
|
3537
|
use WebService::TypePad::Util::JSON; |
|
|
3
|
|
|
|
|
10
|
|
|
|
3
|
|
|
|
|
222
|
|
|
13
|
3
|
|
|
3
|
|
1181
|
use WebService::TypePad::Object; |
|
|
3
|
|
|
|
|
8
|
|
|
|
3
|
|
|
|
|
87
|
|
|
14
|
3
|
|
|
3
|
|
2373
|
use Set::Tiny; |
|
|
3
|
|
|
|
|
3275
|
|
|
|
3
|
|
|
|
|
742
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# Primitive Types |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub coerce_string_in { |
|
19
|
2
|
50
|
|
2
|
0
|
28
|
return defined($_[0]) ? "$_[0]" : undef; |
|
20
|
|
|
|
|
|
|
} |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub coerce_integer_in { |
|
23
|
1
|
50
|
|
1
|
0
|
411
|
return defined($_[0]) ? int($_[0]) : undef; |
|
24
|
|
|
|
|
|
|
} |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub coerce_float_in { |
|
27
|
1
|
50
|
|
1
|
0
|
9
|
return defined($_[0]) ? $_[0] + 0 : undef; |
|
28
|
|
|
|
|
|
|
} |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub coerce_boolean_in { |
|
31
|
2
|
100
|
|
2
|
0
|
888
|
return defined($_[0]) ? ($_[0] ? json_true() : json_false()) : undef; |
|
|
|
50
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
} |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub coerce_boolean_out { |
|
35
|
2
|
100
|
|
2
|
0
|
42
|
return defined($_[0]) ? ($_[0] == json_true() ? 1 : 0) : undef; |
|
|
|
50
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# Collection types |
|
39
|
|
|
|
|
|
|
# These are really just wrappers around aome inner coerce function. |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
{ |
|
42
|
|
|
|
|
|
|
my $coerce_array = sub { |
|
43
|
3
|
|
|
3
|
|
6
|
my ($array, $inner_coerce) = @_; |
|
44
|
3
|
50
|
|
|
|
12
|
return undef unless defined($array); |
|
45
|
3
|
|
|
|
|
9
|
return [ map { $inner_coerce->($_) } @$array ]; |
|
|
9
|
|
|
|
|
42
|
|
|
46
|
|
|
|
|
|
|
}; |
|
47
|
|
|
|
|
|
|
|
|
48
|
3
|
|
|
3
|
|
24
|
no strict 'refs'; |
|
|
3
|
|
|
|
|
7
|
|
|
|
3
|
|
|
|
|
428
|
|
|
49
|
|
|
|
|
|
|
*{'WebService::TypePad::Util::Coerce::coerce_array_in'} = $coerce_array; |
|
50
|
|
|
|
|
|
|
*{'WebService::TypePad::Util::Coerce::coerce_array_out'} = $coerce_array; |
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
{ |
|
54
|
|
|
|
|
|
|
my $coerce_map = sub { |
|
55
|
1
|
|
|
1
|
|
1032
|
my ($map, $inner_coerce) = @_; |
|
56
|
1
|
50
|
|
|
|
5
|
return undef unless defined($map); |
|
57
|
1
|
|
|
|
|
28
|
my $ret = {}; |
|
58
|
1
|
|
|
|
|
5
|
map { my $k = $_; $ret->{$k} = $inner_coerce->($map->{$k}) } keys %$map; |
|
|
3
|
|
|
|
|
11
|
|
|
|
3
|
|
|
|
|
9
|
|
|
59
|
1
|
|
|
|
|
30
|
return $ret; |
|
60
|
|
|
|
|
|
|
}; |
|
61
|
|
|
|
|
|
|
|
|
62
|
3
|
|
|
3
|
|
18
|
no strict 'refs'; |
|
|
3
|
|
|
|
|
3
|
|
|
|
3
|
|
|
|
|
1182
|
|
|
63
|
|
|
|
|
|
|
*{'WebService::TypePad::Util::Coerce::coerce_map_in'} = $coerce_map; |
|
64
|
|
|
|
|
|
|
*{'WebService::TypePad::Util::Coerce::coerce_map_out'} = $coerce_map; |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub coerce_set_in { |
|
68
|
1
|
|
|
1
|
0
|
19
|
my ($set, $inner_coerce) = @_; |
|
69
|
|
|
|
|
|
|
|
|
70
|
1
|
50
|
|
|
|
12
|
return undef unless defined($set); |
|
71
|
|
|
|
|
|
|
|
|
72
|
1
|
|
|
|
|
14
|
my $items = [ sort $set->members ]; |
|
73
|
1
|
|
|
|
|
23
|
return coerce_array_in($items, $inner_coerce); |
|
74
|
|
|
|
|
|
|
} |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub coerce_set_out { |
|
77
|
1
|
|
|
1
|
0
|
1520
|
my ($list, $inner_coerce) = @_; |
|
78
|
|
|
|
|
|
|
|
|
79
|
1
|
50
|
|
|
|
6
|
return undef unless defined($list); |
|
80
|
|
|
|
|
|
|
|
|
81
|
1
|
|
|
|
|
3
|
my $items = coerce_array_out($list, $inner_coerce); |
|
82
|
1
|
|
|
|
|
19
|
return Set::Tiny->new(@$items); |
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
# Object types |
|
86
|
|
|
|
|
|
|
# The implementation of these is always the same modulo |
|
87
|
|
|
|
|
|
|
# the underlying class name. |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
{ |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
# The in func is always the same |
|
92
|
|
|
|
|
|
|
my $in_func = sub { |
|
93
|
1
|
|
|
1
|
|
7
|
my ($obj) = @_; |
|
94
|
1
|
50
|
|
|
|
5
|
return undef unless defined($obj); |
|
95
|
1
|
|
|
|
|
11
|
return $obj->_as_json_dictionary; |
|
96
|
|
|
|
|
|
|
}; |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
foreach my $type (keys %WebService::TypePad::Object::Object_Types) { |
|
99
|
|
|
|
|
|
|
my $class = $WebService::TypePad::Object::Object_Types{$type}; |
|
100
|
|
|
|
|
|
|
my $in_name = 'coerce_'.$type.'_in'; |
|
101
|
|
|
|
|
|
|
my $out_name = 'coerce_'.$type.'_out'; |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
my $out_func = sub { |
|
104
|
2
|
|
|
2
|
|
2825
|
my ($dict) = @_; |
|
105
|
2
|
50
|
|
|
|
12
|
return undef unless defined($dict); |
|
106
|
2
|
|
|
1
|
|
217
|
eval "use $class;"; |
|
|
1
|
|
|
1
|
|
12
|
|
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
56
|
|
|
|
1
|
|
|
|
|
10
|
|
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
18
|
|
|
107
|
2
|
50
|
|
|
|
10
|
die "Failed to load package $class: $@" if $@; |
|
108
|
2
|
|
|
|
|
21
|
return $class->_from_json_dictionary($dict); |
|
109
|
|
|
|
|
|
|
}; |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
{ |
|
112
|
3
|
|
|
3
|
|
19
|
no strict 'refs'; |
|
|
3
|
|
|
|
|
5
|
|
|
|
3
|
|
|
|
|
247
|
|
|
113
|
|
|
|
|
|
|
*{__PACKAGE__.'::'.$in_name} = $in_func; |
|
114
|
|
|
|
|
|
|
*{__PACKAGE__.'::'.$out_name} = $out_func; |
|
115
|
|
|
|
|
|
|
} |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
} |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
} |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
1; |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
|