blib/lib/Keystone/Resolver/plugins/Service/Infotrac.pm untested

filter: Statementstmt 0.0% 0 / 23 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 4 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 32 CC 3 SCAR 19.5
CC
3
Cov
0%
uri
12.0
BEGIN
2.0
BEGIN
2.0
CRAP 7.0
1 # $Id: Infotrac.pm,v 1.5 2007-05-25 08:31:34 mike Exp $
2  
3 package Keystone::Resolver::plugins::Service::Infotrac;
4  
5 use strict;
6 use warnings;
7 use URI::Escape qw(uri_escape_utf8);
8  
9  
10 # See ../../doc/providers/Infomarks Dynamic Creation for OpenURL.doc
11 # The example InfoMarc (that is, Gale URL) in that document is:
12 # http://www.infotrac.galegroup.com/itw/infomark/1/1/1/purl=rc3%5FEAIM%5F0%5F%5Fsu+%22ace+inhibitors%22?sw_aep=gale
13 #
14 # However, the documentation seems to be wrong in several respects.
15 # The following InfoTrac URLs are known empirically to work. The
16 # first URL in this list is a working example sent by Deryck Velasquez
17 # at Gale <Deryck.Velasquez@thomson.com>. I made the others by
18 # changing one aspect at a time to bring it as close as possible to
19 # what the specification suggests without breaking it.
20 #
21 # Original as supplied by Deryck Velasquez:
22 # http://infotrac.galegroup.com/itw/infomark/0/1/1/purl=rc11_ITOF_0_sn_0034-4125_AND_vo_39_AND_sp_373_&dyn=sig!49?sw_aep=cusqa_ingenta
23 # Change the "sw_aep" from "cusqa_ingenta" to our own "indexdata":
24 # http://infotrac.galegroup.com/itw/infomark/0/1/1/purl=rc11_ITOF_0_sn_0034-4125_AND_vo_39_AND_sp_373_&dyn=sig!49?sw_aep=indexdata
25 # Remove the "&dyn=sig!49" component, which is not documented:
26 # http://infotrac.galegroup.com/itw/infomark/0/1/1/purl=rc11_ITOF_0_sn_0034-4125_AND_vo_39_AND_sp_373_?sw_aep=indexdata
27 # Change the "_0_" after the resource name into "__" as documented:
28 # http://infotrac.galegroup.com/itw/infomark/0/1/1/purl=rc11_ITOF__sn_0034-4125_AND_vo_39_AND_sp_373_?sw_aep=indexdata
29 # Change "0/1/1" to "1/1/1" as specified:
30 # http://infotrac.galegroup.com/itw/infomark/1/1/1/purl=rc11_ITOF__sn_0034-4125_AND_vo_39_AND_sp_373_?sw_aep=indexdata
31 # Use hostname "www..." as documented:
32 # http://www.infotrac.galegroup.com/itw/infomark/1/1/1/purl=rc11_ITOF__sn_0034-4125_AND_vo_39_AND_sp_373_?sw_aep=indexdata
33 # Replace some "_" occurrences by "%5F" as documented:
34 # http://www.infotrac.galegroup.com/itw/infomark/1/1/1/purl=rc11%5FITOF%5F%5Fsn_0034-4125_AND_vo_39_AND_sp_373_?sw_aep=indexdata
35 # Remove extraneous underscore from the end of the query:
36 # http://www.infotrac.galegroup.com/itw/infomark/1/1/1/purl=rc11%5FITOF%5F%5Fsn_0034-4125_AND_vo_39_AND_sp_373?sw_aep=indexdata
37 # Provide parameters for the usual Bergelson _Science_ article:
38 # http://www.infotrac.galegroup.com/itw/infomark/1/1/1/purl=rc11%5FITOF%5F%5Fjn_Science_AND_vo_275_AND_sp_1320?sw_aep=indexdata
39 # Re-order query terms alphabetically by fieldname:
40 # http://www.infotrac.galegroup.com/itw/infomark/1/1/1/purl=rc11%5FITOF%5F%5Fjn_Science_AND_sp_1320_AND_vo_275?sw_aep=indexdata
41 # And the last of these is what we actually generate.
42  
43 my %fields = (
44 # au => "aulast", ### au is really of the form "Taylor, Mike"
45 # ti => "atitle",
46 # No OpenURL field for "su" (subject)
47 # No OpenURL field for "ab" (abstract)
48 # No OpenURL field for "ke" (keyword)
49 # we prefer JN to IS since Gale doesn't seem to know the ISSN of
50 # _Science_ magazine, where the usual test-case article lives.
51 # Astonishingly, if both are provided, InfoTrac says, "The search
52 # expression is missing a search term". By experimentation, this
53 # seems to be InfoTrac's response whenver it's given a search in which
54 # one of the ANDed terms has no hits.
55 jn => "jtitle",
56 # is => "issn",
57 vo => "volume",
58 iu => "issue",
59 sp => "spage",
60 # da => "date", # da may be more complex, e.g. "May 3 2001"
61 # No OpenURL fields for "cn" (critic name)
62 );
63  
64 sub uri {
65 my $class = shift();
66 my($openurl) = @_;
67  
68 my($issn, $volume, $issue, $spage)
69 = map { $openurl->rft($_) } qw(issn volume issue spage);
70  
71 my $resource = "ITOF"; # This is what we are subscribed to
72 my $location = "indexdata"; # As specified in email from Gale
73 my $query = "";
74 foreach my $key (sort keys %fields) {
75 my $val = $openurl->rft($fields{$key});
76 if (defined $val) {
77 ### For some reason, "_" as a separator works but the
78 # documented "+" doesn't.
79 ### Does the InfoTrac gateway expect us to encode UTF8 or Latin1?
80 $query .= "_AND_" if $query ne "";
81 $query .= "${key}_" . uri_escape_utf8($val) . "";
82 }
83 }
84  
85 ### For some reason, "rc11" works but the documented "rc3" doesn't
86 return "http://www.infotrac.galegroup.com/itw/infomark/1/1/1/" .
87 "purl=rc11%5F$resource%5F%5F$query?sw_aep=$location";
88 }
89  
90  
91 1;