blib/lib/URI/OpenURL.pm

filter: Statementstmt 63.6% 142 / 223 Branchbran 39.3% 37 / 94 Conditioncond 22.8% 8 / 35 MC/DCmcdc 4.5% 1 / 22 Subroutinesub 71.7% 33 / 46 Podpod 100% 14 / 14 totaltotal 54.1% 235 / 434 CC 62 SCAR 34.6
CC
62
Cov
53%
new_from_hybrid
182.0
as_hybrid
72.0
descriptors
30.0
CRAP 31.9
↑ Summary
1 package URI::OpenURL;
2  
3 =pod
4  
5 =head1 NAME
6  
7 URI::OpenURL - Parse and construct OpenURL's (NISO Z39.88-2004)
8  
9 =head1 DESCRIPTION
10  
11 This module provides an implementation of OpenURLs encoded as URIs (Key/Encoded-Value (KEV) Format), this forms only a part of the OpenURL spec. It does not check that OpenURLs constructed are sane according to the OpenURL specification (to a large extent sanity will depend on the community of use).
12  
13 From the implementation guidelines:
14  
15 The description of a referenced resource, and the descriptions of the associated resources that comprise the context of the reference, bundled together are called a ContextObject. It is a ContextObject that is transported when a user makes a request by clicking a link. A KEV OpenURL may contain only one ContextObject.
16  
17 The ContextObject may contain up to six Entities. One of these, the Referent, conveys information about the referenced item. It must always be included in a ContextObject. The other five entities - ReferringEntity, Requester, Resolver, ServiceType and Referrer - hold information about the context of the reference and are optional.
18  
19 =head1 OpenURL
20  
21 http://library.caltech.edu/openurl/
22  
23 From the implementation guidelines:
24  
25 The OpenURL Framework for Context-Sensitive Services Standard provides a means of describing a referenced resource along with a description of the context of the reference. Additionally it defines methods of transporting these descriptions between networked systems. It is anticipated that it will be used to request services pertaining to the referenced resource and appropriate for the requester.
26  
27 The OpenURL Framework is very general and has the potential to be used in many application domains and by many communities. Concrete instantiations of the various core components within the framework are defined within the OpenURL Registry. The OpenURL Framework is currently a .draft standard for ballot.. During the ballot and public review period, the content of the Registry will be static and has been pre-defined by the NISO AX Committee. There is also an experimental registry where components under development are held. In the future it will be possible to register further items.
28  
29 There are currently two formats for ContextObjects defined in the OpenURL Framework, Key/Encoded-Value and XML. This document provides implementation guidelines for the Key/Encoded-Value Format, concentrating mainly, but not exclusively, on components from the San Antonio Level 1 Community Profile (SAP1).
30  
31 =head1 SYNOPSIS
32  
33 use URI::OpenURL;
34  
35 # Construct an OpenURL
36 # This is the first example from the implementation specs,
37 # with additional resolver and serviceType entities.
38 print URI::OpenURL->new('http://other.service/cgi/openURL'
39 )->referrer(
40 id => 'info:sid/my.service',
41 )->requester(
42 id => 'mailto:john@invalid.domain',
43 )->resolver(
44 id => 'info:sid/other.service',
45 )->serviceType()->scholarlyService(
46 fulltext => 'yes',
47 )->referringEntity(id => 'info:doi/10.1045/march2001-vandesompel')->journal(
48 genre => 'article',
49 aulast => 'Van de Sompel',
50 aufirst => 'Herbert',
51 issn => '1082-9873',
52 volume => '7',
53 issue => '3',
54 date => '2001',
55 atitle => 'Open Linking in the Scholarly Information Environment using the OpenURL Framework',
56 )->referent(id => 'info:doi/10.1045/july99-caplan')->journal(
57 genre => 'article',
58 aulast => 'Caplan',
59 aufirst => 'Priscilla',
60 issn => '1082-9873',
61 volume => '5',
62 issue => '7/8',
63 date => '1999',
64 atitle => 'Reference Linking for Journal Articles',
65 )->as_string();
66  
67 # Parsing (wrappers for $uri->query_form())
68 my $uri = URI::OpenURL->new('http://a.OpenURL/?url_ver=Z39.88-2004&...');
69 my @referent = $uri->referent->metadata();
70 print join(',',@referent), "\n";
71 # This could lose data if there is more than one id
72 my %ds = $uri->referent->descriptors();
73 if( !exists($ds{val_fmt}) ) {
74 warn "No by-value metadata for referent in OpenURL";
75 } elsif($ds{val_fmt} eq 'info:ofi/fmt:kev:mtx:journal') {
76 my %md = $uri->referent->metadata();
77 print ($md{genre} || 'Unknown journal article genre'), "\n";
78 }
79
80 if( $uri->referent->val_fmt() eq 'info:ofi/fmt:kev:mtx:journal' ) {
81 print "The referent is a journal article.\n";
82 }
83  
84 =head1 METHODS
85  
86 =over 4
87  
88 =cut
89  
90 5 ▶use vars qw( $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
91  
92 5 $VERSION = '0.4.6';
93  
94 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
95 5 ▶use URI::Escape;
Subroutine BEGIN: called CC=1 SCAR=0.0
96 5 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
97 5 ▶use POSIX qw/ strftime /;
Subroutine BEGIN: called CC=1 SCAR=0.0
98  
99 5 require URI;
100 5 require URI::_server;
101 5 ▶use vars qw( @ISA );
Subroutine BEGIN: called CC=1 SCAR=0.0
102 5 @ISA = qw( URI::_server );
103  
104 =pod
105  
106 =item $uri = URI::OpenURL->new([$url])
107  
108 Create a new URI::OpenURL object and optionally initialize with $url. If $url does not contain a query component (...?key=value) the object will be initialized to a valid contextobject, but without any entities.
109  
110 If you don't want the context object version and encoding specify url_ver e.g.
111  
112 use URI::OpenURL;
113 my $uri = URI::OpenURL->new(
114 'http://myresolver.com/openURL?url_ver=Z39.88-2004'
115 );
116  
117 =cut
118  
119 5 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
120 5 _init(@_);
121 }
122  
123 5 ▶sub _init {
Subroutine _init: called CC=2 SCAR=6.9
124 5 my $self = shift->SUPER::_init(@_);
125 5 ▶ $self->query_form(
Branch: 1 branch
BranchTrueFalseTotal
unless $self->query 4 1 5
126 url_ver => 'Z39.88-2004',
127 ) unless $self->query();
128 5 $self;
129 }
130  
131 =pod
132  
133 =item $uri = URI::OpenURL->new_from_hybrid($uri)
134  
135 Create a new URI::OpenURL object from a hybrid OpenURL (version 0.1 and/or 1.0 KEVS). Use this to parse a version 0.1 (SFX) style OpenURL.
136  
137 =cut
138  
139 sub new_from_hybrid
140 0 ▶{
Subroutine new_from_hybrid: not called CC=13 SCAR=52.0
Pod documented
141 0 my ($class,$uri) = @_;
142 0 ▶ $class = ref($class) || $class;
Condition0%0/3
ref $class || $class
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table0%0/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
143 0 my $self = $class->new($uri);
144 # If we already have a 1.0 OpenURL just return a canonical 1.0
145 0 my @KEVS = $self->query_form;
146 0 my %kevs = @KEVS;
147 0 ▶ my $genre = $kevs{'genre'} || 'article';
Condition0%0/2
$kevs{'genre'} || 'article'
l!l
00
MC/DC0%0/1
$kevs{'genre'} || 'article'
$kevs{'genre'}
Truth table0%0/2
A
A= $kevs{'genre'}
Aresult
11
00
148 0 ▶ if( $kevs{url_ver} && $kevs{url_ver} eq 'Z39.88-2004' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($kevs{"url_ver"} and $kevs{"url_ver"} eq "Z39.88-2004") 0 0 0
Condition0%0/3
$kevs{"url_ver"} and $kevs{"url_ver"} eq "Z39.88-2004"
!ll&&!rl&&r
000
MC/DC0%0/2
$kevs{"url_ver"} and $kevs{"url_ver"} eq "Z39.88-2004"
$kevs{"url_ver"} $kevs{"url_ver"} eq "Z39.88-2004"
Truth table0%0/3
A and B
A= $kevs{"url_ver"}B= $kevs{"url_ver"} eq "Z39.88-2004"
ABresult
0X0
100
111
149 0 return $self->canonical();
150 }
151 # Initialize the OpenURL (url_ver etc.)
152 0 $self->query('');
153 0 $self = $class->new($self);
154 # Tidy up the 0.1 keys
155 0 ▶ for(my $i = 0; $i < @KEVS;) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @KEVS) 0 0 0
156 0 ▶ if( $KEVS[$i] eq 'sid' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($KEVS[$i] eq 'sid') { } 0 0 0
elsif ($KEVS[$i] eq 'id') { } 0 0 0
elsif ($KEVS[$i] eq 'pid') { } 0 0 0
157 0 $self->referrer->id('info:sid/'.$KEVS[$i+1]);
158 0 splice(@KEVS,$i,2);
159 } elsif( $KEVS[$i] eq 'id' ) {
160 0 ▶ if( $KEVS[$i+1] =~ s/(^doi|pmid|bibcode):// ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($KEVS[$i + 1] =~ s/(^doi|pmid|bibcode)://) { } 0 0 0
161 0 $self->referent->id("info:$1/".$KEVS[$i+1]);
162 } else {
163 0 $self->referent->id($KEVS[$i+1]);
164 }
165 0 splice(@KEVS,$i,2);
166 } elsif( $KEVS[$i] eq 'pid' ) {
167 0 $self->referent->dat($KEVS[$i+1]);
168 0 splice(@KEVS,$i,2);
169 } else {
170 0 ▶ $KEVS[$i] = 'jtitle' if $KEVS[$i] eq 'title';
Branch: 1 branch
BranchTrueFalseTotal
if $KEVS[$i] eq "title" 0 0 0
171 0 $i += 2;
172 }
173 }
174 # Map genre onto a ctx format and add the metadata
175 0 ▶ if( $genre =~ '^article|preprint|proceeding$' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($genre =~ /^article|preprint|proceeding$/) { } 0 0 0
elsif ($genre eq 'bookitem') { } 0 0 0
176 0 $self->referent->journal(@KEVS);
177 } elsif( $genre eq 'bookitem' ) {
178 0 $self->referent->book(@KEVS);
179 } else {
180 0 die "Unable to handle version 0.1 genre: $genre";
181 }
182 0 $self;
183 }
184  
185 =pod
186  
187 =item @qry = $uri->query_form([key, value, [key, value]])
188  
189 Equivalent to URI::query_form, but with support for UTF-8 encoding.
190  
191 =cut
192  
193 sub query_form
194 46 ▶{
Subroutine query_form: called CC=5 SCAR=20.9
Pod documented
195 46 my $self = shift;
196 46 my @new = @_;
197 46 ▶ if( 1 == @new ) {
Branch: 1 branch
BranchTrueFalseTotal
if (1 == @new) 0 46 46
198 0 my $n = $new[0];
199 0 ▶ if( ref($n) eq "ARRAY" ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $n eq 'ARRAY') { } 0 0 0
elsif (ref $n eq 'HASH') { } 0 0 0
200 0 @new = @$n;
201 } elsif( ref($n) eq "HASH" ) {
202 0 @new = %$n;
203 }
204 }
205 46 for (@new) {
206 362 utf8::encode($_);
207 }
208 46 map { utf8::decode($_); $_ } $self->SUPER::query_form(@new);
209 }
210  
211 =pod
212  
213 =item $uri->init_ctxobj_version()
214  
215 Add ContextObject versioning.
216  
217 =cut
218  
219 sub init_ctxobj_version
220 1 ▶{
Subroutine init_ctxobj_version: called CC=3 SCAR=12.0
Pod documented
221 1 my $self = shift;
222 1 my %query = $self->query_form;
223 return if
224 defined($query{'ctx_ver'}) &&
225 1 ▶ $query{'ctx_ver'} eq 'Z39.88-2004';
Branch: 1 branch
BranchTrueFalseTotal
if defined $query{"ctx_ver"} and $query{"ctx_ver"} eq "Z39.88-2004" 0 1 1
Condition33%1/3
defined $query{"ctx_ver"} and $query{"ctx_ver"} eq "Z39.88-2004"
!ll&&!rl&&r
100
MC/DC0%0/2
defined $query{"ctx_ver"} and $query{"ctx_ver"} eq "Z39.88-2004"
defined $query{"ctx_ver"} $query{"ctx_ver"} eq "Z39.88-2004"
Truth table33%1/3
A and B
A= defined $query{"ctx_ver"}B= $query{"ctx_ver"} eq "Z39.88-2004"
ABresult
0X0
100
111
226 1 $self->query_form(
227 $self->query_form,
228 ctx_ver => 'Z39.88-2004',
229 ctx_enc => 'info:ofi/enc:UTF-8',
230 url_ctx_fmt => 'info:ofi/fmt:kev:mtx:ctx',
231 );
232 }
233  
234 =pod
235  
236 =item $ts = $uri->init_timestamps([ctx_timestamp, [url_timestamp]])
237  
238 Add ContextObject and URL timestamps, returns the old timestamp(s) or undef on none.
239  
240 =cut
241  
242 3 ▶sub init_timestamps {
Subroutine init_timestamps: called CC=8 SCAR=21.2
Pod documented
243 3 my $self = shift;
244 3 ▶ my $ctx_timestamp = shift ||
Condition66%2/3
shift() || strftime('%Y-%m-%dT%H:%M:%STZD', gmtime time)
l!l&&r!l&&!r
120
MC/DC0%0/2
shift() || strftime('%Y-%m-%dT%H:%M:%STZD', gmtime time)
shift() strftime('%Y-%m-%dT%H:%M:%STZD', gmtime time)
Truth table66%2/3
A || B
A= shift()B= strftime('%Y-%m-%dT%H:%M:%STZD', gmtime time)
ABresult
1X1
011
000
245 strftime("%Y-%m-%dT%H:%M:%STZD",gmtime(time));
246 3 ▶ my $url_timestamp = shift || $ctx_timestamp;
Condition33%1/3
shift() || $ctx_timestamp
l!l&&r!l&&!r
030
MC/DC0%0/2
shift() || $ctx_timestamp
shift() $ctx_timestamp
Truth table33%1/3
A || B
A= shift()B= $ctx_timestamp
ABresult
1X1
011
000
247 3 my @query = $self->query_form;
248 3 my @old;
249 3 ▶ for(my $i = 0; $i < @query;) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @query) 13 3 16
250 13 ▶ if( $query[$i] eq 'ctx_tim' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($query[$i] eq 'ctx_tim') { } 2 11 13
elsif ($query[$i] eq 'url_tim') { } 2 9 11
251 2 ($_,$old[0]) = splice(@query,$i,2);
252 } elsif( $query[$i] eq 'url_tim' ) {
253 2 ($_,$old[1]) = splice(@query,$i,2);
254 } else {
255 9 $i+=2;
256 }
257 }
258 3 $self->query_form(
259 @query,
260 'ctx_tim', $ctx_timestamp,
261 'url_tim', $url_timestamp,
262 );
263 3 ▶ wantarray ? @old : ($old[0]||$old[1]);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 3 3
Condition66%2/3
$old[0] or $old[1]
l!l&&r!l&&!r
201
MC/DC50%1/2
$old[0] or $old[1]
$old[0] $old[1]
Truth table66%2/3
A or B
A= $old[0]B= $old[1]
ABresult
1X1
011
000
264 }
265  
266 =pod
267  
268 =item $uri = $uri->as_hybrid()
269  
270 Return the OpenURL as a hybrid 0.1/1.0 OpenURL (contains KEVs for both versions). Returns a new URI::OpenURL object.
271  
272 =cut
273  
274 sub as_hybrid
275 0 ▶{
Subroutine as_hybrid: not called CC=8 SCAR=42.8
Pod documented
276 0 my $self = shift;
277 0 my @KEVS = $self->query_form;
278 # Add the referent
279 0 my @md = $self->referent->metadata();
280 # 'title' has been changed to 'jtitle' in 1.0
281 0 ▶ for(my $i = 0; $i < @md; $i+=2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @md) 0 0 0
282 0 ▶ $md[$i] = 'title' if($md[$i] eq 'jtitle');
Branch: 1 branch
BranchTrueFalseTotal
if $md[$i] eq "jtitle" 0 0 0
283 }
284 0 push @KEVS, @md;
285 # Add the referrer's id
286 0 my $rfr_id = $self->referrer->id;
287 0 ▶ if( defined($rfr_id) && $rfr_id =~ s/^info:sid\/// ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $rfr_id and $rfr_id =~ s[^info:sid/][]) 0 0 0
Condition0%0/3
defined $rfr_id and $rfr_id =~ s[^info:sid/][]
!ll&&!rl&&r
000
MC/DC0%0/2
defined $rfr_id and $rfr_id =~ s[^info:sid/][]
defined $rfr_id $rfr_id =~ s[^info:sid/][]
Truth table0%0/3
A and B
A= defined $rfr_idB= $rfr_id =~ s[^info:sid/][]
ABresult
0X0
100
111
288 0 push @KEVS, sid => $rfr_id;
289 }
290 # Add the referent's id (if its compatible with 0.1)
291 0 my $rft_id = $self->referent->id;
292 0 ▶ if( defined($rft_id) &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $rft_id and $rft_id =~ s[^info:(doi|pmid|bibcode)/][$1:] || $rft_id =~ /^oai:/) 0 0 0
Condition0%0/6
defined $rft_id and $rft_id =~ s[^info:(doi|pmid|bibcode)/][$1:] || $rft_id =~ /^oai:/
!ll&&!rl&&r
000
$rft_id =~ s[^info:(doi|pmid|bibcode)/][$1:] or $rft_id =~ /^oai:/
l!l&&r!l&&!r
000
MC/DC0%0/3
defined $rft_id and $rft_id =~ s[^info:(doi|pmid|bibcode)/][$1:] || $rft_id =~ /^oai:/
defined $rft_id $rft_id =~ s[^info:(doi|pmid|bibcode)/][$1:] $rft_id =~ /^oai:/
Truth table0%0/4
A and B or C
A= defined $rft_idB= $rft_id =~ s[^info:(doi|pmid|bibcode)/][$1:]C= $rft_id =~ /^oai:/
ABCresult
0XX0
1000
11X1
1011
293 ($rft_id =~ s/^info:(doi|pmid|bibcode)\//$1:/ ||
294 $rft_id =~ /^oai:/)
295 ) {
296 0 push @KEVS, id => $rft_id;
297 }
298 # Return a new URI (otherwise we pollute ourselves)
299 0 my $hybrid = new URI::OpenURL($self);
300 0 $hybrid->query_form(@KEVS);
301 0 $hybrid;
302 }
303  
304 =item $uri = $uri->canonical()
305  
306 Return a canonical OpenURL by removing anything that isn't part of the version 1.0 specification.
307  
308 =cut
309  
310 sub canonical
311 0 ▶{
Subroutine canonical: not called CC=3 SCAR=24.8
Pod documented
312 0 my $uri = shift->SUPER::canonical();
313 0 $uri = bless $uri, "URI::OpenURL";
314 0 my @KEVS = $uri->query_form();
315 0 ▶ for(my $i = 0; $i < @KEVS; ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @KEVS) 0 0 0
316 0 ▶ if( $KEVS[$i] !~ /^ctx_ver|ctx_enc|ctx_id|ctx_tim|url_ver|url_tim|url_ctx_fmt|(?:(?:rft|rfe|svc|req|res|rfr)[_\.].+)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $KEVS[$i] =~ /^ctx_ver|ctx_enc|ctx_id|ctx_tim|url_ver|url_tim|url_ctx_fmt|(?:(?:rft|rfe|svc|req|res|rfr)[_\.].+)$/) { } 0 0 0
317 0 splice(@KEVS,$i,2);
318 } else {
319 0 $i += 2;
320 }
321 }
322 0 $uri->query_form(@KEVS);
323 0 $uri;
324 }
325  
326 =pod
327  
328 =item $str = $uri->dump()
329  
330 Return the OpenURL as a human-readable string (useful for debugging).
331  
332 =cut
333  
334 sub dump
335 0 ▶{
Subroutine dump: not called CC=2 SCAR=17.9
Pod documented
336 0 my $self = shift;
337 0 my $str = URI->new($self);
338 0 $str->query('');
339 0 $str .= "\n";
340 0 my @kevs = $self->query_form;
341 0 ▶ for(my $i = 0; $i < @kevs; $i+=2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @kevs) 0 0 0
342 0 $str .= $kevs[$i] . "=" . $kevs[$i+1] . "\n";
343 }
344 0 $str;
345 }
346  
347 =pod
348  
349 =item $uri = $uri->referent()
350  
351 Every ContextObject must have a Referent, the referenced resource for which the ContextObject is created. Within the scholarly information community the Referent will probably be a document-like object, for instance: a book or part of a book; a journal publication or part of a journal; a report; etc.
352  
353 =cut
354  
355 5 ▶sub referent {
Subroutine referent: called CC=2 SCAR=7.1
Pod documented
356 5 my $self = bless shift, 'URI::OpenURL::referent';
357 5 ▶ return $self->descriptors() if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 0 5 5
358 5 $self->_addattr(@_);
359 }
360  
361 =pod
362  
363 =item $uri->referringEntity()
364  
365 The ReferringEntity is the Entity that references the Referent. It is optional in the ContextObject. Within the scholarly information community the ReferringEntity could be a journal article that cites the Referent. Or it could be a record within an abstracting and indexing database.
366  
367 =cut
368  
369 1 ▶sub referringEntity {
Subroutine referringEntity: called CC=2 SCAR=7.1
Pod documented
370 1 my $self = bless shift, 'URI::OpenURL::referringEntity';
371 1 ▶ return $self->descriptors() if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 0 1 1
372 1 $self->_addattr(@_);
373 }
374  
375 =pod
376  
377 =item $uri = $uri->requester()
378  
379 The Requester is the Entity that requests services pertaining to the Referent. It is optional in the ContextObject. Within the scholarly information community the Requester is generally a human end-user who clicks a link within a digital library application.
380  
381 =cut
382  
383 1 ▶sub requester {
Subroutine requester: called CC=2 SCAR=7.1
Pod documented
384 1 my $self = bless shift, 'URI::OpenURL::requester';
385 1 ▶ return $self->descriptors() if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 0 1 1
386 1 $self->_addattr(@_);
387 }
388  
389 =item $uri = $uri->serviceType()
390  
391 The ServiceType is the Entity that defines the type of service requested. It is optional in the ContextObject. Within the scholarly information community the ServiceType could be a request for; the full text of an article; the abstract of an article; an inter-library loan request, etc.
392  
393 =cut
394  
395 1 ▶sub serviceType {
Subroutine serviceType: called CC=2 SCAR=7.1
Pod documented
396 1 my $self = bless shift, 'URI::OpenURL::serviceType';
397 1 ▶ return $self->descriptors() if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 0 1 1
398 1 $self->_addattr(@_);
399 }
400  
401 =pod
402  
403 =item $uri = $uri->resolver()
404  
405 The Resolver is the Entity at which a request for services is targeted. It is optional in the ContextObject. This need not be the same Resolver as that specified as the base URL for an OpenURL Transport and does not replace that base URL.
406  
407 =cut
408  
409 1 ▶sub resolver {
Subroutine resolver: called CC=2 SCAR=7.1
Pod documented
410 1 my $self = bless shift, 'URI::OpenURL::resolver';
411 1 ▶ return $self->descriptors() if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 0 1 1
412 1 $self->_addattr(@_);
413 }
414  
415 =pod
416  
417 =item $uri = $uri->referrer()
418  
419 The Referrer is the Entity that generated the ContextObject. It is optional in the ContextObject, but its inclusion is strongly encouraged. Within the scholarly information community the Referrer will be an information provider such as an electronic journal application or an 'abstracting and indexing' service.
420  
421 =cut
422  
423 1 ▶sub referrer {
Subroutine referrer: called CC=2 SCAR=7.1
Pod documented
424 1 my $self = bless shift, 'URI::OpenURL::referrer';
425 1 ▶ return $self->descriptors() if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 0 1 1
426 1 $self->_addattr(@_);
427 }
428  
429 =pod
430  
431 =item $uri = $uri->referent->dublinCore(key => value)
432  
433 =item $uri = $uri->referent->book(key => value)
434  
435 =item $uri = $uri->referent->dissertation(key => value)
436  
437 =item $uri = $uri->referent->journal(key => value)
438  
439 =item $uri = $uri->referent->patent(key => value)
440  
441 =item $uri = $uri->serviceType->scholarlyService(key => value)
442  
443 Add metadata to the current entity (referent is given only as an example). Dublin Core is an experimental format.
444  
445 =item @descs = $uri->referent->descriptors([$key=>$value[, $key=>$value]])
446  
447 Return the descriptors as a list of key-value pairs for the current entity (referent is given as an example).
448  
449 Optionally add descriptors (functionally equivalent to $uri->referent($key=>$value)).
450  
451 =item @metadata = $uri->referent->metadata([$schema_url, $key=>$value[, $key=>$value]])
452  
453 Returns by-value metadata as a list of key-value pairs for the current entity (referent is given as an example).
454  
455 Optionally, if you wish to add metadata that does not use one of the standard schemas (journal, book etc.) then you can add them using metadata.
456  
457 =item @vals = $uri->referent->descriptor('id')
458  
459 Return a list of values given for an entity descriptor (id, ref, dat, val_fmt, ref_fmt).
460  
461 =item $dat = $uri->referent->dat()
462  
463 =item @ids = $uri->referent->id()
464  
465 =item $ref = $uri->referent->ref()
466  
467 =item $val_fmt = $uri->referent->val_fmt()
468  
469 =item $ref_fmt = $uri->referent->ref_fmt()
470  
471 Return the respective descriptor using a method interface. An entity may contain 0 or more ids, and optionally a by-reference URI, private data, by-value format and by-reference format.
472  
473 =head1 CHANGES
474  
475 0.4.6
476 - Removed ContextObject versioning from default
477 constructor
478 0.4.5
479 - Support for URL utf-8 encoding
480 0.4.2
481 - Added methods for parsing/writing hybrid OpenURLs
482 0.4.1
483 - Timestamps no longer included in default initialization
484 - Added method "init_timestamps" to add timestamps
485 0.4
486 - Initial release
487  
488 =head1 COPYRIGHT
489  
490 Quotes from the OpenURL implementation guidelines are from: http://library.caltech.edu/openurl/
491  
492 Copyright 2004 Tim Brody.
493  
494 This module is released under the same terms as the main Perl distribution.
495  
496 =head1 AUTHOR
497  
498 Tim Brody <tdb01r@ecs.soton.ac.uk>
499 Intelligence, Agents, Multimedia Group
500 University of Southampton, UK
501  
502 =back
503  
504 =cut
505  
506 package URI::OpenURL::entity;
507  
508 5 ▶use vars qw(@ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
509 5 @ISA = qw(URI::OpenURL);
510  
511 5 ▶use vars qw( %ENTITIES );
Subroutine BEGIN: called CC=1 SCAR=0.0
512  
513 5 %ENTITIES = (
514 referent => 'rft',
515 referringEntity => 'rfe',
516 serviceType => 'svc',
517 requester => 'req',
518 resolver => 'res',
519 referrer => 'rfr',
520 );
521  
522 17 ▶sub _entity {
Subroutine _entity: called CC=1 SCAR=0.0
523 17 my $entity = ref(shift());
524 17 $entity =~ s/.*:://;
525 17 $ENTITIES{$entity};
526 }
527  
528 10 ▶sub _addattr {
Subroutine _addattr: called CC=4 SCAR=14.2
529 10 my ($self,@pairs) = @_;
530 10 my @KEVS = $self->query_form();
531 10 my $entity = _entity($self);
532 10 ▶ for( my $i = 0; $i < @pairs; $i+=2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @pairs) 7 10 17
533 7 ▶ next unless defined($pairs[$i+1]) && length($pairs[$i+1]);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pairs[$i + 1] and length $pairs[$i + 1] 0 7 7
Condition33%1/3
defined $pairs[$i + 1] and length $pairs[$i + 1]
!ll&&!rl&&r
007
MC/DC0%0/2
defined $pairs[$i + 1] and length $pairs[$i + 1]
defined $pairs[$i + 1] length $pairs[$i + 1]
Truth table33%1/3
A and B
A= defined $pairs[$i + 1]B= length $pairs[$i + 1]
ABresult
0X0
100
111
534 7 push @KEVS, $entity.'_'.$pairs[$i], $pairs[$i+1];
535 }
536 10 $self->query_form(@KEVS);
537 10 $self;
538 }
539  
540 5 ▶sub _addkevs {
Subroutine _addkevs: called CC=5 SCAR=16.6
541 5 my ($self,$val_fmt,@pairs) = @_;
542 5 my @KEVS = $self->query_form();
543 5 my $entity = _entity($self);
544 5 ▶ push @KEVS, $entity.'_val_fmt', $val_fmt if $val_fmt;
Branch: 1 branch
BranchTrueFalseTotal
if $val_fmt 5 0 5
545 5 ▶ for( my $i = 0; $i < @pairs; $i+=2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @pairs) 20 5 25
546 20 ▶ next unless defined($pairs[$i+1]) && length($pairs[$i+1]);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pairs[$i + 1] and length $pairs[$i + 1] 0 20 20
Condition33%1/3
defined $pairs[$i + 1] and length $pairs[$i + 1]
!ll&&!rl&&r
0020
MC/DC0%0/2
defined $pairs[$i + 1] and length $pairs[$i + 1]
defined $pairs[$i + 1] length $pairs[$i + 1]
Truth table33%1/3
A and B
A= defined $pairs[$i + 1]B= length $pairs[$i + 1]
ABresult
0X0
100
111
547 20 push @KEVS, $entity.'.'.$pairs[$i], $pairs[$i+1];
548 }
549 5 $self->query_form(@KEVS);
550 5 bless $self, 'URI::OpenURL'; # Should catch some broken user code
551 }
552  
553 0 ▶sub dublinCore {
Subroutine dublinCore: not called CC=1 SCAR=6.9
554 0 shift->_addkevs('info:ofi/fmt:kev:mtx:dc',@_);
555 }
556  
557 0 ▶sub book {
Subroutine book: not called CC=1 SCAR=6.9
558 0 shift->_addkevs('info:ofi/fmt:kev:mtx:book',@_);
559 }
560  
561 0 ▶sub dissertation {
Subroutine dissertation: not called CC=1 SCAR=6.9
562 0 shift->_addkevs('info:ofi/fmt:kev:mtx:dissertation',@_);
563 }
564  
565 3 ▶sub journal {
Subroutine journal: called CC=1 SCAR=0.0
566 3 shift->_addkevs('info:ofi/fmt:kev:mtx:journal',@_);
567 }
568  
569 0 ▶sub patent {
Subroutine patent: not called CC=1 SCAR=6.9
570 0 shift->_addkevs('info:ofi/fmt:kev:mtx:patent',@_);
571 }
572  
573 1 ▶sub scholarlyService {
Subroutine scholarlyService: called CC=1 SCAR=0.0
574 1 shift->_addkevs('info:ofi/fmt:kev:mtx:sch_svc',@_);
575 }
576  
577 # Descriptors (things with '_' in)
578 0 ▶sub descriptors {
Subroutine descriptors: not called CC=5 SCAR=34.0
579 0 my $self = shift;
580 0 ▶ $self->_addattr(@_) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
581 0 ▶ return () unless wantarray;
Branch: 1 branch
BranchTrueFalseTotal
unless wantarray 0 0 0
582 0 my $entity = $self->_entity();
583 0 my @pairs = $self->query_form();
584 0 my @md;
585 0 ▶ for(my $i = 0; $i < @pairs; $i+=2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @pairs) 0 0 0
586 0 ▶ if( $pairs[$i] =~ s/^$entity\_// ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pairs[$i] =~ s/^$entity\_//) 0 0 0
587 0 push @md, $pairs[$i], $pairs[$i+1];
588 }
589 }
590 0 return @md;
591 }
592  
593 1 ▶sub descriptor {
Subroutine descriptor: called CC=5 SCAR=16.1
594 1 my ($self,$key) = splice(@_,0,2);
595 1 $self->_addattr($key => $_) for @_;
596 1 my @KEVS = $self->query_form();
597 1 my @VALS;
598 1 my $entity = $self->_entity();
599 1 ▶ for(my $i = 0; $i < @KEVS; $i+=2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @KEVS) 29 1 30
600 29 ▶ push @VALS, $KEVS[$i+1] if( $KEVS[$i] eq "${entity}_${key}" );
Branch: 1 branch
BranchTrueFalseTotal
if $KEVS[$i] eq "${entity}_$key" 2 27 29
601 }
602 1 ▶ wantarray ? @VALS : $VALS[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 0 1
603 }
604  
605 0 ▶sub dat { shift->descriptor('dat',@_) }
Subroutine dat: not called CC=1 SCAR=6.9
606 1 ▶sub id { shift->descriptor('id',@_) }
Subroutine id: called CC=1 SCAR=0.0
607 0 ▶sub ref { shift->descriptor('ref',@_) }
Subroutine ref: not called CC=1 SCAR=6.9
608 0 ▶sub ref_fmt { shift->descriptor('ref_fmt',@_) }
Subroutine ref_fmt: not called CC=1 SCAR=6.9
609 0 ▶sub val_fmt { shift->descriptor('val_fmt',@_) }
Subroutine val_fmt: not called CC=1 SCAR=6.9
610  
611 # By-value metadata (things with '.' in)
612 2 ▶sub metadata {
Subroutine metadata: called CC=5 SCAR=16.1
613 2 my $self = shift;
614 2 ▶ $self->_addkevs(@_) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 1 1 2
615 2 ▶ return () unless wantarray;
Branch: 1 branch
BranchTrueFalseTotal
unless wantarray 1 1 2
616 1 my $entity = $self->_entity();
617 1 my @pairs = $self->query_form();
618 1 my @md;
619 1 ▶ for(my $i = 0; $i < @pairs; $i+=2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @pairs) 29 1 30
620 29 ▶ if( $pairs[$i] =~ s/^$entity\.// ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pairs[$i] =~ s/^$entity\.//) 8 21 29
621 8 push @md, $pairs[$i], $pairs[$i+1];
622 }
623 }
624 1 return @md;
625 }
626  
627 package URI::OpenURL::referent;
628  
629 5 ▶use vars qw(@ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
630 5 @ISA = qw(URI::OpenURL::entity);
631  
632 package URI::OpenURL::referringEntity;
633  
634 5 ▶use vars qw(@ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
635 5 @ISA = qw(URI::OpenURL::entity);
636  
637 package URI::OpenURL::requester;
638  
639 5 ▶use vars qw(@ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
640 5 @ISA = qw(URI::OpenURL::entity);
641  
642 package URI::OpenURL::serviceType;
643  
644 5 ▶use vars qw(@ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
645 5 @ISA = qw(URI::OpenURL::entity);
646  
647 package URI::OpenURL::resolver;
648  
649 5 ▶use vars qw(@ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
650 5 @ISA = qw(URI::OpenURL::entity);
651  
652 package URI::OpenURL::referrer;
653  
654 5 ▶use vars qw(@ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
655 5 @ISA = qw(URI::OpenURL::entity);
656  
657 5 1;
658  
↑ Summary