line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WWW::NHKProgram::API::Provider::Common; |
2
|
1
|
|
|
1
|
|
945
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
29
|
|
3
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
21
|
|
4
|
1
|
|
|
1
|
|
4
|
use utf8; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
4
|
|
5
|
1
|
|
|
1
|
|
17
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
320
|
|
6
|
1
|
|
|
1
|
|
20
|
use JSON (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
7
|
1
|
|
|
1
|
|
1706
|
use Text::Sprintf::Named qw/named_sprintf/; |
|
1
|
|
|
|
|
8776
|
|
|
1
|
|
|
|
|
114
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
12
|
use constant API_ENDPOINT => "http://api.nhk.or.jp/v1/pg/"; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
637
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub call { |
12
|
0
|
|
|
0
|
0
|
|
my ($class, $sub_uri, $arg, $raw) = @_; |
13
|
|
|
|
|
|
|
|
14
|
0
|
|
|
|
|
|
my $res = $class->furl->get(named_sprintf( |
15
|
|
|
|
|
|
|
API_ENDPOINT . "$sub_uri?key=" . $class->api_key, $arg |
16
|
|
|
|
|
|
|
)); |
17
|
0
|
|
|
|
|
|
_catch_error($res, $raw); |
18
|
0
|
|
|
|
|
|
return $res->{content}; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub _catch_error { |
22
|
0
|
|
|
0
|
|
|
my ($res, $raw) = @_; |
23
|
|
|
|
|
|
|
|
24
|
0
|
0
|
|
|
|
|
unless ($res->is_success) { |
25
|
0
|
0
|
|
|
|
|
if ($raw) { |
26
|
0
|
|
|
|
|
|
croak $res->{content}; |
27
|
|
|
|
|
|
|
} |
28
|
0
|
|
|
|
|
|
my $fault = JSON::decode_json($res->{content})->{fault}; |
29
|
0
|
|
|
|
|
|
my $fault_str = $fault->{faultstring}; |
30
|
0
|
|
|
|
|
|
my $fault_detail = $fault->{detail}->{errorcode}; |
31
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
my $error_str = "[Error] " . $res->status_line; |
33
|
0
|
0
|
|
|
|
|
if ($fault_str) { |
34
|
0
|
|
|
|
|
|
$error_str .= ": $fault_str"; |
35
|
|
|
|
|
|
|
} |
36
|
0
|
0
|
|
|
|
|
if ($fault_detail) { |
37
|
0
|
|
|
|
|
|
$error_str .= " ($fault_detail)"; |
38
|
|
|
|
|
|
|
} |
39
|
0
|
|
|
|
|
|
croak $error_str; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
1; |
44
|
|
|
|
|
|
|
|