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

filter: Statementstmt 0.0% 0 / 19 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 / 30 CC 4 SCAR 25.1
CC
4
Cov
0%
data
20.0
BEGIN
2.0
BEGIN
2.0
CRAP 12.3
1 # $Id: info.pm,v 1.3 2007-06-20 13:03:40 mike Exp $
2  
3 package Keystone::Resolver::plugins::ID::info;
4  
5 use strict;
6 use warnings;
7  
8  
9 # ID plug-ins provides a single function, data(). This function is
10 # called with two arguments:
11 #
12 # $openurl The OpenURL from which the ID to be resolved is
13 # drawn. Plugins should not use this object for
14 # anything more sophisticated than invoking its die()
15 # and warn() methods and MUST NOT CHANGE IT.
16 #
17 # $id The identifier to be resolved. The leading "scheme"
18 # part of the URI is already stripped, since the plug-in
19 # is scheme-specific. For example, when the ID
20 # "info:doi/10.1006/mthe.2000.0239" is encountered, the
21 # "info" scheme plug-in is invoked with the $id argument
22 # set to "doi/10.1006/mthe.2000.0239".
23 #
24 # The data function() must return a five-element array. (This
25 # complexity is unavoidable becasue these plugins can resolve IDs in
26 # two very different senses, and there are a multitude of different
27 # error conditions):
28 #
29 # [0] A URI that the ID resolves to.
30 #
31 # [1] A "tag" to be used in labelling where the URI in
32 # element 0 came from. For example, a URI obtained by
33 # resolving a DOI expressed as an "info" URI might have
34 # the tag "info:doi". This tag is used verbatim in the
35 # XML document that is eventually generated to represent
36 # the results of the OpenURL resolution process. This
37 # is only consulted if [0] is defined.
38 #
39 # [2] A reference to hash of additional key=value metadata
40 # pairs to be added to the entity for which an ID is
41 # being resolved. The keys are those specified in the
42 # OpenURL 1.0 standard (Z39.88), _not_ including the
43 # entity-name as a prefix: so for example, using "title"
44 # rather than "rft.title".
45 #
46 # [3] An error message. This is only used if elements [0]
47 # and [2] are both undefined, and may itself be
48 # undefined to mean "nothing went wrong but the ID can't
49 # be resolved for good and adequate reasons" --
50 # e.g. "mailto" IDs simply cannot be resolved because
51 # the concept makes no sense.
52 #
53 # [4] An indication of whether the error should be treated
54 # as non-fatal (such as an unrecognised DOI). If this
55 # is absent or false, the error is treated as fatal
56 # (such as a malformed URI).
57  
58 sub data {
59 my $class = shift();
60 my($openurl, $address) = @_;
61  
62 # Info URIs are of the form
63 # info:<namespace>/<subaddress>
64 # where namespaces include "doi", "pmid", "oclcnum", etc. Each
65 # such namespace is defined by an info URI of the form
66 # info:ofi/nam:info:<namespace>
67 # and described in the OpenURL registry at
68 # http://openurl.info/registry
69 # All we do in this plugin is delegate to a sub-plugin that
70 # handles a particular namespace.
71  
72 # More OCLC WorldCat crap. Its COinS objects include referent IDs
73 # like "info:sici:", which is not even syntactically valid since
74 # info: URIs contain a slash. Spot these are make them harmlessly
75 # no-op
76 return (undef, undef, undef,
77 "syntactically invalid (OCLC?) info URI: '$address'", 1)
78 if $address =~ /^[^\/]*:$/;
79  
80 my($namespace, $subaddress) = ($address =~ /(.*?)\/(.*)/);
81 return (undef, undef, undef,
82 "info URI doesn't have a namespace: '$address'")
83 if !defined $namespace;
84  
85 eval {
86 require "Keystone/Resolver/plugins/ID/info/$namespace.pm";
87 }; if ($@) {
88 $openurl->warn("can't load ID info plugin '$namespace': $@");
89 return (undef, undef, undef,
90 "info URI namespace '$namespace' not supported ($address)");
91 }
92  
93 return "Keystone::Resolver::plugins::ID::info::$namespace"->data($openurl,
94 $subaddress);
95 }
96  
97  
98 1;