line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::VIAF::API::ID; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
4
|
|
|
|
|
|
|
|
5
|
4
|
|
|
4
|
|
13
|
use strict; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
87
|
|
6
|
4
|
|
|
4
|
|
12
|
use warnings; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
108
|
|
7
|
|
|
|
|
|
|
|
8
|
4
|
|
|
4
|
|
13
|
use Catmandu::Sane; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
16
|
|
9
|
4
|
|
|
4
|
|
465
|
use Moo; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
15
|
|
10
|
|
|
|
|
|
|
|
11
|
4
|
|
|
4
|
|
2915
|
use LWP::UserAgent; |
|
4
|
|
|
|
|
119366
|
|
|
4
|
|
|
|
|
119
|
|
12
|
4
|
|
|
4
|
|
1565
|
use Catmandu::VIAF::API::Parse; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has viafid => (is => 'ro', required => 1); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
has client => (is => 'lazy'); |
17
|
|
|
|
|
|
|
has result=> (is => 'lazy'); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub _build_client { |
20
|
|
|
|
|
|
|
my $self = shift; |
21
|
|
|
|
|
|
|
my $ua = LWP::UserAgent->new( |
22
|
|
|
|
|
|
|
agent => sprintf('catmandu-store-viaf/%s', $VERSION) |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
return $ua; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub _build_result { |
28
|
|
|
|
|
|
|
my $self = shift; |
29
|
|
|
|
|
|
|
my $url = sprintf('https://www.viaf.org/viaf/%s/rdf.xml', $self->viafid); |
30
|
|
|
|
|
|
|
my $response = $self->client->get($url); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
if (!$response->is_success) { |
33
|
|
|
|
|
|
|
if ($response->code == 404) { |
34
|
|
|
|
|
|
|
return {}; |
35
|
|
|
|
|
|
|
} else { |
36
|
|
|
|
|
|
|
Catmandu::HTTPError->throw({ |
37
|
|
|
|
|
|
|
code => $response->code, |
38
|
|
|
|
|
|
|
message => $response->status_line, |
39
|
|
|
|
|
|
|
url => $response->request->uri, |
40
|
|
|
|
|
|
|
method => $response->request->method, |
41
|
|
|
|
|
|
|
request_headers => [], |
42
|
|
|
|
|
|
|
request_body => $response->request->decoded_content, |
43
|
|
|
|
|
|
|
response_headers => [], |
44
|
|
|
|
|
|
|
response_body => $response->decoded_content |
45
|
|
|
|
|
|
|
}); |
46
|
|
|
|
|
|
|
return {}; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
my $rdf = $response->decoded_content; |
50
|
|
|
|
|
|
|
my $document = sprintf('<?xml version="1.0" encoding="UTF-8"?>%s', $rdf); |
51
|
|
|
|
|
|
|
my $parser = Catmandu::VIAF::API::Parse->new(items => $document); |
52
|
|
|
|
|
|
|
return $parser->xml(); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
1; |
56
|
|
|
|
|
|
|
__END__ |