blib/lib/Keystone/Resolver/Result.pm untested

filter: Statementstmt 0.0% 0 / 23 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 9 totaltotal 0.0% 0 / 49 CC 4 SCAR 19.7
CC
4
Cov
0%
render
20.0
new
2.0
type
2.0
CRAP 7.1
1 # $Id: Result.pm,v 1.3 2008-04-25 17:45:52 mike Exp $
2  
3 package Keystone::Resolver::Result;
4  
5 use strict;
6 use warnings;
7  
8  
9 =head1 NAME
10  
11 Keystone::Resolver::Result - a result, with its type, resolved from an OpenURL
12  
13 =head1 SYNOPSIS
14  
15 $result = new OpenURL::Result("fulltext", "", "CQL Tutorial", 15,
16 "http://zing.z3950.org/cql/intro.html");
17 $type = $result->type();
18 $text = $result->text()
19  
20 =head1 DESCRIPTION
21  
22 A C<Keystone::Resolver::Result> object represents one of the
23 (potentially) many results found by resolving an OpenURL. It can't do
24 anything useful apart from tell you the data with which it was
25 created, and render itself. What we're looking for here is, I think,
26 what we doctors, in fact, call a C<struct>.
27  
28 =head1 METHODS
29  
30 =cut
31  
32  
33 =head2 new()
34  
35 $r1 = new OpenURL::Result("fulltext", "", "CQL web site", 10,
36 "http://zing/z3950.org/cql/");
37 $r2 = new OpenURL::Result("bookstore", "", "Amazon", 25,
38 "isbn:0253333490");
39 $r3 = new OpenURL::Result("citation", "JVP", "JVP format citation", 99,
40 "Wedel 2003. <i>Paleobiology</i>.",
41 "text/html", 1);
42  
43 Creates a new Keystone::Resolver::Result object with the specified
44 parameters. A result is represented by the following components:
45  
46 =over 4
47  
48 =item type
49  
50 A short string indicating the type of service that provided the
51 result, e.g. C<fulltext>, C<abstract>, C<websearch>, C<citation>.
52 These are intended to be recognised by XSLT stylesheets rather than
53 read by humans.
54  
55 =item tag
56  
57 A short string indicating the particular service that provided the
58 result. This, too, is intended for stylesheets to compare with rather
59 than for humans: C<service> is the human-readable equivalent. This
60 tag is useful for some types of service (e.g. C<citation>) but not
61 necessarily for others (e.g. C<fulltext>).
62  
63 =item service
64  
65 A short human-readable description of the service that provided the
66 result.
67  
68 =item priority
69  
70 An integer representing the priority of this result relative to others
71 of the same type. Lower values represent higher priorities.
72  
73 =item text
74  
75 The text of the result itself. Its form may vary depending on the
76 type of service that provided it. For example, for C<fulltext> and
77 C<abstract> services, it's a URI; but for C<citation> services, it's
78 an HTML fragment.
79  
80 =item text
81  
82 The text of the result itself. Its form may vary depending on the
83 type of service that provided it. For example, for C<fulltext> and
84 C<abstract> services, it's a URI; but for C<citation> services, it's
85 an HTML fragment.
86  
87 =item mimeType
88  
89 (Optional) An indication of the MIME-type of the text.
90  
91 =item single
92  
93 (Optional) If provided and true, then this result is the only one
94 explicitly requested by the ContextObject.
95  
96 =back
97  
98 =cut
99  
100 sub new {
101 my $class = shift();
102 my($type, $tag, $service, $priority, $text, $mimeType, $single) = @_;
103  
104 return bless {
105 type => $type,
106 tag => $tag,
107 service => $service,
108 priority => $priority,
109 text => $text,
110 mimeType => $mimeType,
111 single => $single,
112 }, $class;
113 }
114  
115  
116 =head2 type(), tag(), service(), priority(), text(), mimeType(), single()
117  
118 $type = $result->type();
119 $text = $result->text();
120 die if $type ne "fulltext" || $text ne "http://zing.z3950.org/cql/";
121  
122 C<type()> returns the type of a C<Keystone::Resolver::Result>,
123 C<tag()> returns a tag for the name of the service that provides it,
124 C<service()> returns a description of the service, C<priority()>
125 returns its priority, C<text()> returns its text, C<mimeType()>
126 returns its mime-type and C<single()> returns an indication of whether
127 the result was the only one requested. These are, respectively, the
128 first to seventh parameters with which it was created.
129  
130 =cut
131  
132 sub type { return shift()->{type} }
133 sub tag { return shift()->{tag} }
134 sub service { return shift()->{service} }
135 sub priority { return shift()->{priority} }
136 sub text { return shift()->{text} }
137 sub mimeType { return shift()->{mimeType} }
138 sub single { return shift()->{single} }
139  
140  
141 =head2 render()
142  
143 print $result->render(), "\n";
144  
145 Returns a human-readable string representing a
146 C<Keystone::Resolver::Result>.
147  
148 =cut
149  
150 sub render() {
151 my $this = shift();
152  
153 my $type = $this->type();
154 my $tag = $this->tag();
155 my $service = $this->service();
156 my $priority = $this->priority();
157 my $text = $this->text();
158  
159 return ("$type: " .
160 (defined $tag ? "$tag" : "") .
161 (defined $service ? "=$service" : "") .
162 (defined $priority ? " (priority $priority)" : "") .
163 " - $text");
164 }
165  
166  
167 1;