line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
2063
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
52
|
|
2
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
69
|
|
3
|
|
|
|
|
|
|
package SeeAlso::Client; |
4
|
|
|
|
|
|
|
{ |
5
|
|
|
|
|
|
|
$SeeAlso::Client::VERSION = '0.71'; |
6
|
|
|
|
|
|
|
} |
7
|
|
|
|
|
|
|
#ABSTRACT: SeeAlso Linkserver Protocol Client |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
6
|
use Carp qw(croak); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
76
|
|
10
|
1
|
|
|
1
|
|
6
|
use JSON::XS '2.0' ; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
185
|
|
11
|
1
|
|
|
1
|
|
942
|
use LWP::Simple qw(get); |
|
1
|
|
|
|
|
115837
|
|
|
1
|
|
|
|
|
9
|
|
12
|
1
|
|
|
1
|
|
222
|
use URI '1.35'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
23
|
|
13
|
1
|
|
|
1
|
|
932
|
use Data::Validate::URI qw(is_web_uri); |
|
1
|
|
|
|
|
61431
|
|
|
1
|
|
|
|
|
71
|
|
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
1
|
|
633
|
use SeeAlso::Identifier; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
27
|
|
16
|
1
|
|
|
1
|
|
3793
|
use SeeAlso::Response; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
43
|
|
17
|
|
|
|
|
|
|
|
18
|
1
|
|
|
1
|
|
13
|
use base qw( SeeAlso::Source ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
812
|
|
19
|
|
|
|
|
|
|
our @EXPORT = qw( seealso_request ); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub new { |
23
|
6
|
|
|
6
|
1
|
2897
|
my $class = shift; |
24
|
6
|
|
|
|
|
8
|
my (%description, $baseurl); |
25
|
|
|
|
|
|
|
|
26
|
6
|
100
|
|
|
|
21
|
if (@_ % 2) { |
27
|
4
|
|
|
|
|
11
|
($baseurl, %description) = @_; |
28
|
|
|
|
|
|
|
} else { |
29
|
2
|
|
|
|
|
8
|
%description = @_; |
30
|
2
|
|
|
|
|
4
|
$baseurl = $description{BaseURL}; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
6
|
50
|
|
|
|
20
|
croak "Please specify a baseurl" unless defined $baseurl; |
34
|
|
|
|
|
|
|
|
35
|
6
|
|
|
|
|
19
|
my $self = bless { |
36
|
|
|
|
|
|
|
'is_simple' => 0 # unknown or no |
37
|
|
|
|
|
|
|
}, $class; |
38
|
|
|
|
|
|
|
|
39
|
6
|
|
|
|
|
27
|
$self->description( %description ); |
40
|
6
|
|
|
|
|
18
|
$self->baseURL( $baseurl ); |
41
|
|
|
|
|
|
|
|
42
|
4
|
|
|
|
|
15
|
return $self; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub query { |
47
|
0
|
|
|
0
|
1
|
0
|
my ($self, $identifier) = @_; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# TOOD: on failure catch/throw error(s) |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
0
|
my $url = $self->queryURL( $identifier ); |
52
|
0
|
|
|
|
|
0
|
my $json = get($url); |
53
|
|
|
|
|
|
|
|
54
|
0
|
0
|
|
|
|
0
|
if (defined $json) { |
55
|
0
|
|
|
|
|
0
|
return SeeAlso::Response->fromJSON( $json ); # may also croak |
56
|
|
|
|
|
|
|
} else { |
57
|
0
|
|
|
|
|
0
|
croak("Failed to query $url"); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub baseURL { |
63
|
7
|
|
|
7
|
1
|
14
|
my ($self, $url) = @_; |
64
|
7
|
100
|
|
|
|
23
|
return $self->description("BaseURL") unless defined $url; |
65
|
|
|
|
|
|
|
|
66
|
6
|
100
|
|
|
|
44
|
$url = URI->new( $url ) unless UNIVERSAL::isa( $url, "URI" ); |
67
|
6
|
100
|
66
|
|
|
9416
|
croak("The specified URL is not valid") |
68
|
|
|
|
|
|
|
unless defined $url and is_web_uri($url->as_string()); |
69
|
|
|
|
|
|
|
|
70
|
4
|
|
|
|
|
3662
|
my %query = $url->query_form(); |
71
|
4
|
50
|
33
|
|
|
102
|
croak("The specified URL must not contain id or callback parameter") |
72
|
|
|
|
|
|
|
if defined $query{'id'} or defined $query{'callback'}; |
73
|
4
|
|
|
|
|
10
|
$self->{is_simple} = defined $query{'format'}; |
74
|
4
|
|
|
|
|
9
|
$self->{baseurl} = $url; |
75
|
4
|
|
|
|
|
12
|
$url = $url->canonical()->as_string(); |
76
|
4
|
|
|
|
|
598
|
$self->description("BaseURL",$url); |
77
|
|
|
|
|
|
|
|
78
|
4
|
|
|
|
|
9
|
return $url; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub queryURL { |
83
|
2
|
|
|
2
|
1
|
437
|
my ($self, $identifier, $callback) = @_; |
84
|
2
|
50
|
|
|
|
16
|
$identifier = $identifier->normalized() |
85
|
|
|
|
|
|
|
if UNIVERSAL::isa($identifier,"SeeAlso::Identifier"); |
86
|
2
|
50
|
|
|
|
5
|
$identifier = "" unless defined $identifier; |
87
|
|
|
|
|
|
|
|
88
|
2
|
|
|
|
|
7
|
my $url = URI->new( $self->{baseurl} ); |
89
|
2
|
|
|
|
|
105
|
my %query = $url->query_form(); |
90
|
|
|
|
|
|
|
|
91
|
2
|
50
|
|
|
|
64
|
$query{'format'} = "seealso" unless $self->{is_simple}; |
92
|
2
|
|
|
|
|
4
|
$query{'id'} = $identifier; |
93
|
|
|
|
|
|
|
|
94
|
2
|
50
|
|
|
|
6
|
if (defined $callback) { |
95
|
0
|
0
|
|
|
|
0
|
$callback =~ /^[a-zA-Z0-9\._\[\]]+$/ or |
96
|
|
|
|
|
|
|
croak ( "Invalid callback name" ); |
97
|
0
|
|
|
|
|
0
|
$query{callback} = $callback; |
98
|
|
|
|
|
|
|
} |
99
|
2
|
|
|
|
|
6
|
$url->query_form( %query ); |
100
|
|
|
|
|
|
|
|
101
|
2
|
|
|
|
|
229
|
return $url->canonical(); |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub getFormats { |
106
|
0
|
|
|
0
|
1
|
0
|
my ($self) = @_; |
107
|
0
|
0
|
|
|
|
0
|
return $self->{formats} if exists $self->{formats}; |
108
|
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
0
|
my $formats = {}; |
110
|
0
|
|
|
|
|
0
|
my $url = $self->baseURL(); |
111
|
0
|
|
|
|
|
0
|
my $xml = get($url); |
112
|
0
|
0
|
|
|
|
0
|
if ($xml) { |
113
|
|
|
|
|
|
|
# dump parser (not really XML) |
114
|
0
|
|
|
|
|
0
|
my %matches = ( $xml =~ m/
|
115
|
0
|
|
|
|
|
0
|
$formats = { |
116
|
0
|
|
|
|
|
0
|
map { $_, { type => $matches{$_} } } (keys %matches) |
117
|
|
|
|
|
|
|
}; |
118
|
|
|
|
|
|
|
} |
119
|
0
|
|
|
|
|
0
|
$self->{formats} = $formats; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub seealso_request { |
124
|
1
|
|
|
1
|
1
|
928
|
my ($baseurl, $identifier) = @_; |
125
|
1
|
|
|
|
|
3
|
my $response = eval { SeeAlso::Client->new($baseurl)->query($identifier); }; |
|
1
|
|
|
|
|
5
|
|
126
|
1
|
|
|
|
|
552
|
return $response; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
__END__ |