« blib/lib/Keystone/Resolver/plugins/ID/info.pm
↑ Summary
blib/lib/Keystone/Resolver/plugins/Service/APP.pm »
| 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; |