line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Amazon::MWS::TypeMap; |
2
|
|
|
|
|
|
|
|
3
|
8
|
|
|
8
|
|
57
|
use warnings; |
|
8
|
|
|
|
|
21
|
|
|
8
|
|
|
|
|
261
|
|
4
|
8
|
|
|
8
|
|
51
|
use strict; |
|
8
|
|
|
|
|
20
|
|
|
8
|
|
|
|
|
176
|
|
5
|
|
|
|
|
|
|
|
6
|
8
|
|
|
8
|
|
1465
|
use DateTime; |
|
8
|
|
|
|
|
1179868
|
|
|
8
|
|
|
|
|
280
|
|
7
|
8
|
|
|
8
|
|
1353
|
use DateTime::Format::ISO8601; |
|
8
|
|
|
|
|
259466
|
|
|
8
|
|
|
|
|
402
|
|
8
|
|
|
|
|
|
|
|
9
|
8
|
|
|
8
|
|
68
|
use Exporter qw(import); |
|
8
|
|
|
|
|
22
|
|
|
8
|
|
|
|
|
3260
|
|
10
|
|
|
|
|
|
|
our @EXPORT_OK = qw(from_amazon to_amazon); |
11
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( all => \@EXPORT_OK ); |
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
0
|
4
|
sub identity { shift } |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my %from_map = ( |
16
|
|
|
|
|
|
|
'string' => \&identity, |
17
|
|
|
|
|
|
|
'boolean' => sub { lc(shift) eq 'true' }, |
18
|
|
|
|
|
|
|
'nonNegativeInteger' => \&identity, |
19
|
|
|
|
|
|
|
'datetime' => sub { |
20
|
|
|
|
|
|
|
return DateTime::Format::ISO8601->parse_datetime(shift); |
21
|
|
|
|
|
|
|
}, |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub from_amazon { |
25
|
1
|
|
|
1
|
1
|
4
|
my ($type, $value) = @_; |
26
|
1
|
|
|
|
|
8
|
return $from_map{$type}->($value); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
my %to_map = ( |
30
|
|
|
|
|
|
|
'string' => \&identity, |
31
|
|
|
|
|
|
|
'boolean' => sub { $_[0] ? 'true' : 'false' }, |
32
|
|
|
|
|
|
|
'nonNegativeInteger' => sub { |
33
|
|
|
|
|
|
|
my $int = int(shift); |
34
|
|
|
|
|
|
|
$int = 1 unless $int > 0; |
35
|
|
|
|
|
|
|
return $int; |
36
|
|
|
|
|
|
|
}, |
37
|
|
|
|
|
|
|
'datetime' => sub { |
38
|
|
|
|
|
|
|
return DateTime::Format::ISO8601->parse_datetime(shift); |
39
|
|
|
|
|
|
|
}, |
40
|
|
|
|
|
|
|
); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub to_amazon { |
43
|
4
|
|
|
4
|
1
|
997
|
my ($type, $value) = @_; |
44
|
4
|
|
|
|
|
22
|
return $to_map{$type}->($value); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
1; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
__END__ |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 NAME |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
Amazon::MWS::TypeMap |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 DESCRIPTION |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
Functions for mapping between types specified in the MWS API documentation and |
58
|
|
|
|
|
|
|
perl datatypes. |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head1 EXPORTED FUNCTIONS |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head2 to_amazon ( type, value ) |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
Converts from a perl datatype to a string for use as an MWS param. |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head2 from_amazon ( type, value ) |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
Converts from a string supplied by MWS to a perl datatype. |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head1 TYPES |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head2 string |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
A plain perl string. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head2 boolean |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
When sent by amazon, true is converted to 1 and false to the empty string. |
79
|
|
|
|
|
|
|
When sent to amazon, any true value or false value will be properly converted. |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head2 datetime |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Converted to and from DateTime objects. |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 AUTHOR |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Paul Driver C<< frodwith@cpan.org >> |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 LICENCE AND COPYRIGHT |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Copyright (c) 2009, Plain Black Corporation L<http://plainblack.com>. |
92
|
|
|
|
|
|
|
All rights reserved |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
This module is free software; you can redistribute it and/or modify it under |
95
|
|
|
|
|
|
|
the same terms as Perl itself. See L<perlartistic>. |