blib/lib/Keystone/Resolver/plugins/ID/urn.pm untested

filter: Statementstmt 0.0% 0 / 20 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 4 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 31 CC 4 SCAR 25.1
CC
4
Cov
0%
data
20.0
BEGIN
2.0
BEGIN
2.0
CRAP 12.3
1 # $Id: urn.pm,v 1.3 2007-06-20 12:55:32 mike Exp $
2  
3 package Keystone::Resolver::plugins::ID::urn;
4  
5 use strict;
6 use warnings;
7  
8  
9 # See "info.pm" for comments. Like that ID namespace, this one merely
10 # delegates to sub-namespaces.
11  
12 sub data {
13 my $class = shift();
14 my($openurl, $address) = @_;
15  
16 # Urn URIs are of the form
17 # urn:<namespace>:<subaddress>
18 # where namespaces include "isbn", etc.
19  
20 my($namespace, $subaddress) = ($address =~ /(.*?):(.*)/);
21 return (undef, undef, undef,
22 "URN doesn't have a namespace: '$address'")
23 if !defined $namespace;
24  
25 # OCLC's WorldCat COinS provides URN identifiers of the form
26 # "urn:ISBN:9780394588162", with an upper-case "ISBN". I'm not
27 # sure whether that's allowed, but in any case we canonicalise it
28 # down into lowercase.
29 $namespace = lc($namespace);
30  
31 # Another oddity of WorldCat OpenURLs: they provide IDs with empty
32 # values, such as "urn:ISSN:". We protect the individual plugins
33 # from such nonsense.
34 return (undef, undef, undef, "empty URN '$address'", 1)
35 if $subaddress eq "";
36  
37 eval {
38 require "Keystone/Resolver/plugins/ID/urn/$namespace.pm";
39 }; if ($@) {
40 $openurl->warn("can't load ID URN plugin '$namespace': $@");
41 return (undef, undef, undef,
42 "URN namespace '$namespace' not supported ($address)");
43 }
44  
45 return "Keystone::Resolver::plugins::ID::urn::$namespace"->data($openurl,
46 $subaddress);
47 }
48  
49  
50 1;