line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::VIAF::API::ID; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
4
|
|
|
|
|
|
|
|
5
|
4
|
|
|
4
|
|
13
|
use strict; |
|
4
|
|
|
|
|
3
|
|
|
4
|
|
|
|
|
84
|
|
6
|
4
|
|
|
4
|
|
12
|
use warnings; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
105
|
|
7
|
|
|
|
|
|
|
|
8
|
4
|
|
|
4
|
|
14
|
use Catmandu::Sane; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
18
|
|
9
|
4
|
|
|
4
|
|
464
|
use Moo; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
19
|
|
10
|
|
|
|
|
|
|
|
11
|
4
|
|
|
4
|
|
2909
|
use LWP::UserAgent; |
|
4
|
|
|
|
|
117186
|
|
|
4
|
|
|
|
|
120
|
|
12
|
4
|
|
|
4
|
|
1682
|
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
|
|
|
|
|
|
|
Catmandu::HTTPError->throw({ |
34
|
|
|
|
|
|
|
code => $response->code, |
35
|
|
|
|
|
|
|
message => $response->status_line, |
36
|
|
|
|
|
|
|
url => $response->request->uri, |
37
|
|
|
|
|
|
|
method => $response->request->method, |
38
|
|
|
|
|
|
|
request_headers => [], |
39
|
|
|
|
|
|
|
request_body => $response->request->decoded_content, |
40
|
|
|
|
|
|
|
response_headers => [], |
41
|
|
|
|
|
|
|
response_body => $response->decoded_content |
42
|
|
|
|
|
|
|
}); |
43
|
|
|
|
|
|
|
return []; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
my $rdf = $response->decoded_content; |
46
|
|
|
|
|
|
|
my $document = sprintf('<?xml version="1.0" encoding="UTF-8"?>%s', $rdf); |
47
|
|
|
|
|
|
|
my $parser = Catmandu::VIAF::API::Parse->new(items => $document); |
48
|
|
|
|
|
|
|
return $parser->xml(); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
1; |
52
|
|
|
|
|
|
|
__END__ |