line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Business::Mondo::Utils; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Business::Mondo::Utils |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 DESCRIPTION |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
A role containing Mondo utilities. |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=cut |
12
|
|
|
|
|
|
|
|
13
|
11
|
|
|
11
|
|
192055
|
use strict; |
|
11
|
|
|
|
|
15
|
|
|
11
|
|
|
|
|
272
|
|
14
|
11
|
|
|
11
|
|
41
|
use warnings; |
|
11
|
|
|
|
|
12
|
|
|
11
|
|
|
|
|
221
|
|
15
|
|
|
|
|
|
|
|
16
|
11
|
|
|
11
|
|
423
|
use Moo::Role; |
|
11
|
|
|
|
|
9402
|
|
|
11
|
|
|
|
|
61
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 METHODS |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head2 normalize_params |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
Normalizes the passed params hash into a string for use in queries to the |
23
|
|
|
|
|
|
|
Mondo API. If a second true value is passed this will includes RFC5849 |
24
|
|
|
|
|
|
|
encoding and will convert DateTime objects into the corresponding ISO8601 |
25
|
|
|
|
|
|
|
string |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my $query_string = $self->normalize_params( \%params,$rfc_encode ); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=cut |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub normalize_params { |
32
|
5
|
|
|
5
|
1
|
7802
|
my ( $self,$params,$rfc_encode ) = @_; |
33
|
|
|
|
|
|
|
|
34
|
5
|
100
|
66
|
|
|
22
|
return '' if ( ! $params || ! keys( %{ $params } ) ); |
|
2
|
|
|
|
|
9
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
return join( '&', |
37
|
11
|
|
|
|
|
29
|
map { $_->[0] . '=' . $_->[1] } |
38
|
|
|
|
|
|
|
map { $rfc_encode |
39
|
|
|
|
|
|
|
? [ _rfc5849_encode( $_ ),_rfc5849_encode( $params->{$_} ) ] |
40
|
11
|
100
|
|
|
|
24
|
: [ $_,$params->{$_} ] |
41
|
|
|
|
|
|
|
} |
42
|
18
|
|
|
|
|
16
|
sort { $a cmp $b } |
43
|
2
|
|
|
|
|
4
|
keys( %{ $params } ) |
|
2
|
|
|
|
|
7
|
|
44
|
|
|
|
|
|
|
); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub _rfc5849_encode { |
48
|
18
|
|
|
18
|
|
12
|
my ( $str ) = @_; |
49
|
|
|
|
|
|
|
|
50
|
18
|
100
|
|
|
|
28
|
if ( ref( $str ) eq 'DateTime' ) { |
51
|
1
|
|
|
|
|
5
|
$str = $str->iso8601; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
18
|
|
|
|
|
49
|
$str =~ s#([^-.~_a-z0-9])#sprintf('%%%02X', ord($1))#gei; |
|
11
|
|
|
|
|
29
|
|
55
|
18
|
|
|
|
|
33
|
return $str; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub _params_as_array_string { |
59
|
3
|
|
|
3
|
|
6
|
my ( $self,$key,$params ) = @_; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
my %modded_params = map { |
62
|
|
|
|
|
|
|
+"$key\[$_\]" => ref( $params->{$_} ) eq 'DateTime' |
63
|
17
|
100
|
|
|
|
72
|
? $params->{$_}->iso8601 : $params->{$_} |
64
|
3
|
|
|
|
|
5
|
} keys %{ $params }; |
|
3
|
|
|
|
|
9
|
|
65
|
|
|
|
|
|
|
|
66
|
3
|
|
|
|
|
30
|
return %modded_params; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 AUTHOR |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Lee Johnson - C<leejo@cpan.org> |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify it under |
74
|
|
|
|
|
|
|
the same terms as Perl itself. If you would like to contribute documentation, |
75
|
|
|
|
|
|
|
features, bug fixes, or anything else then please raise an issue / pull request: |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
https://github.com/leejo/business-mondo |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=cut |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
1; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# vim: ts=4:sw=4:et |