line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Azure::CognitiveServices::Face::Base; |
2
|
29
|
|
|
29
|
|
193
|
use strict; |
|
29
|
|
|
|
|
67
|
|
|
29
|
|
|
|
|
691
|
|
3
|
29
|
|
|
29
|
|
137
|
use warnings; |
|
29
|
|
|
|
|
63
|
|
|
29
|
|
|
|
|
949
|
|
4
|
|
|
|
|
|
|
use Class::Accessor::Lite ( |
5
|
29
|
|
|
|
|
428
|
new => 1, |
6
|
|
|
|
|
|
|
ro => [qw[access_key endpoint]], |
7
|
29
|
|
|
29
|
|
11804
|
); |
|
29
|
|
|
|
|
26196
|
|
8
|
29
|
|
|
29
|
|
17679
|
use LWP::UserAgent; |
|
29
|
|
|
|
|
1099522
|
|
|
29
|
|
|
|
|
968
|
|
9
|
29
|
|
|
29
|
|
15515
|
use JSON; |
|
29
|
|
|
|
|
220694
|
|
|
29
|
|
|
|
|
168
|
|
10
|
29
|
|
|
29
|
|
3677
|
use Carp; |
|
29
|
|
|
|
|
73
|
|
|
29
|
|
|
|
|
1497
|
|
11
|
29
|
|
|
29
|
|
197
|
use URI; |
|
29
|
|
|
|
|
74
|
|
|
29
|
|
|
|
|
657
|
|
12
|
29
|
|
|
29
|
|
147
|
use HTTP::Request; |
|
29
|
|
|
|
|
68
|
|
|
29
|
|
|
|
|
11131
|
|
13
|
|
|
|
|
|
|
|
14
|
0
|
|
|
0
|
1
|
0
|
sub path {''}; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub uri { |
17
|
28
|
|
|
28
|
1
|
114
|
my ($self, $path, %query) = @_; |
18
|
28
|
|
|
|
|
195
|
my $uri = URI->new($self->endpoint); |
19
|
28
|
100
|
|
|
|
197357
|
$uri->path($path ? join('/', $self->path, $path) : $self->path); |
20
|
28
|
100
|
|
|
|
3226
|
if (keys %query) { |
21
|
4
|
|
|
|
|
43
|
$uri->query_form(%query); |
22
|
|
|
|
|
|
|
} |
23
|
28
|
|
|
|
|
691
|
$uri; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub json { |
27
|
15
|
|
|
15
|
1
|
46
|
my $self = shift; |
28
|
15
|
|
33
|
|
|
570
|
$self->{json} ||= JSON->new->utf8(1); |
29
|
15
|
|
|
|
|
414
|
$self->{json}; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub agent { |
33
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
34
|
0
|
|
0
|
|
|
0
|
$self->{agent} ||= LWP::UserAgent->new(agent => __PACKAGE__, timeout => 60); |
35
|
0
|
|
|
|
|
0
|
$self->{agent}; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub request { |
39
|
0
|
|
|
0
|
1
|
0
|
my ($self, $req) = @_; |
40
|
0
|
|
|
|
|
0
|
my $res; |
41
|
0
|
|
|
|
|
0
|
my $try = 0; |
42
|
0
|
|
|
|
|
0
|
while (1) { |
43
|
0
|
|
|
|
|
0
|
$res = $self->agent->request($req); |
44
|
0
|
|
|
|
|
0
|
$try++; |
45
|
0
|
0
|
0
|
|
|
0
|
if ($try > 10 || $res->code != 429) { |
46
|
0
|
|
|
|
|
0
|
last; |
47
|
|
|
|
|
|
|
} |
48
|
0
|
|
|
|
|
0
|
carp sprintf('Retry. Because API said %s', $res->content); |
49
|
|
|
|
|
|
|
} |
50
|
0
|
|
|
|
|
0
|
my $body; |
51
|
0
|
0
|
|
|
|
0
|
if ($res->content) { |
52
|
0
|
0
|
|
|
|
0
|
if ($res->content_type !~ /application\/json/) { |
53
|
0
|
|
|
|
|
0
|
croak($res->content); |
54
|
|
|
|
|
|
|
} |
55
|
0
|
|
|
|
|
0
|
$body = $self->json->decode($res->content); |
56
|
|
|
|
|
|
|
} |
57
|
0
|
0
|
|
|
|
0
|
if (!$res->is_success) { |
58
|
0
|
|
|
|
|
0
|
croak($body->{error}{message}); |
59
|
|
|
|
|
|
|
} |
60
|
0
|
|
|
|
|
0
|
$body; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub build_headers { |
64
|
28
|
|
|
28
|
1
|
112
|
my ($self, @headers) = @_; |
65
|
|
|
|
|
|
|
( |
66
|
28
|
|
|
|
|
224
|
"Content-Type" => "application/json", |
67
|
|
|
|
|
|
|
"Ocp-Apim-Subscription-Key" => $self->access_key, |
68
|
|
|
|
|
|
|
@headers, |
69
|
|
|
|
|
|
|
); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub build_request { |
73
|
28
|
|
|
28
|
1
|
117
|
my ($self, $method, $uri_param, $header, $hash) = @_; |
74
|
28
|
|
|
|
|
213
|
my $uri = $self->uri(@$uri_param); |
75
|
28
|
100
|
|
|
|
266
|
my $body = $hash ? $self->json->encode($hash) : undef; |
76
|
28
|
50
|
|
|
|
302
|
my @headers = $self->build_headers(defined $header ? @$header : ()); |
77
|
28
|
|
|
|
|
548
|
HTTP::Request->new($method => $uri, [@headers], $body); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
1; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
__END__ |