Search/Result.pm

filter: Statementstmt 2.9% 9 / 310 Branchbran 0.0% 0 / 152 Conditioncond 0.0% 0 / 29 MC/DCmcdc 0.0% 0 / 19 Subroutinesub 1.6% 1 / 60 Podpod 96.4% 54 / 56 totaltotal 10.2% 64 / 626 CC 89 SCAR 58.1
CC
89
Cov
2%
as_html
1332.0
PublishWhen
72.0
_url
30.0
CRAP 334.4
↑ Summary Search/XML.pm »
1 package Yahoo::Search::Result;
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 2 our $VERSION = "20100614.1"; # just to make CPAN happy
5  
6 =head1 NAME
7  
8  
9 =head1 VERSION
10  
11 version 1.11.3
12 Yahoo::Search::Result -- class representing a single result (single web
13 page, image, video file, etc) from a Yahoo! search-engine query.
14 (This package is included in, and automatically loaded by, the Yahoo::Search package.)
15  
16 =head1 Package Use
17  
18 You never need to C<use> this package directly -- it is loaded
19 automatically by Yahoo::Search.
20  
21 =head1 Object Creation
22  
23 C<Result> objects are created automatically when a C<Response> object is
24 created (when a C<Request> object's C<Fetch> method is called, either
25 directly, or indirectly via a shortcut such as
26 C<Yahoo::Search-E<gt>Query()>.
27  
28 =head1 Methods Overview
29  
30 This table shows the methods available on a per-search-space basis:
31  
32  
33  
34 Terms
35 Related |
36 Spell | |
37 Local | | |
38 News | | | |
39 Video | | | | |
40 Image | | | | | |
41 Doc | | | | | | |
42 | | | | | | | |
43 Next [X] [X] [X] [X] [X] [X] [X] [X]
44 Prev [X] [X] [X] [X] [X] [X] [X] [X]
45 Response [X] [X] [X] [X] [X] [X] [X] [X]
46 Request [X] [X] [X] [X] [X] [X] [X] [X]
47 SearchSpace [X] [X] [X] [X] [X] [X] [X] [X]
48  
49 * I [X] [X] [X] [X] [X] [X] [X] .
50 * i [X] [X] [X] [X] [X] [X] [X] .
51 as_html [X] [X] [X] [X] [X] [X] [X] .
52 as_string [X] [X] [X] [X] [X] [X] [X] .
53 Data [X] [X] [X] [X] [X] [X] [X] .
54  
55 * Url [X] [X] [X] [X] [X] . . .
56 * ClickUrl [X] [X] [X] [X] [X] . . .
57 * Title [X] [X] [X] [X] [X] . . .
58 TitleAsHtml [X] [X] [X] [X] [X] . . .
59 Link [X] [X] [X] [X] [X] . . .
60 * Summary [X] [X] [X] [X] . . . .
61 SummaryAsHtml [X] [X] [X] [X] . . . .
62  
63 * CacheUrl [X] . . . . . . .
64 * CacheSize [X] . . . . . . .
65 * ModTimestamp [X] . . [X] . . . .
66  
67 * Width . [X] [X] . . . . .
68 * Height . [X] [X] . . . . .
69  
70 * ThumbUrl . [X] [X] [X] . . . .
71 * ThumbWidth . [X] [X] [X] . . . .
72 * ThumbHeight . [X] [X] [X] . . . .
73 ThumbImg . [X] [X] [X] . . . .
74 ThumbLink . [X] [X] [X] . . . .
75  
76 * HostUrl . [X] [X] . . . . .
77 * Copyright . [X] [X] . . . . .
78 * Publisher . [X] [X] . . . . .
79 * Restrictions . [X] [X] . . . . .
80  
81 * Type [X] [X] [X] . . . . .
82 * Bytes . [X] [X] . . . . .
83 * Channels . . [X] . . . . .
84 * Seconds . . [X] . . . . .
85 * Duration . . [X] . . . . .
86 * Streaming . . [X] . . . . .
87  
88 * SourceName . . . [X] . . . .
89 SourceNameAsHtml . . . [X] . . . .
90 * SourceUrl . . . [X] . . . .
91 * Language . . . [X] . . . .
92 * PublishTime . . . [X] . . . .
93 * PublishWhen . . . [X] . . . .
94  
95 * Address . . . . [X] . . .
96 * City . . . . [X] . . .
97 * State . . . . [X] . . .
98 * Phone . . . . [X] . . .
99 * Miles . . . . [X] . . .
100 * Kilometers . . . . [X] . . .
101 * Rating . . . . [X] . . .
102 * MapUrl . . . . [X] . . .
103 * BusinessUrl . . . . [X] . . .
104 * BusinessClickUrl . . . . [X] . . .
105 * AllMapUrl . . . . [X] . . .
106  
107 * Term . . . . . [X] [X] [X]
108 TermAsHtml . . . . . [X] [X] [X]
109  
110 | | | | | | | |
111 Doc | | | | | | |
112 Image | | | | | |
113 Video | | | | |
114 News | | | |
115 Local | | |
116 Spell | |
117 Related |
118 Terms
119  
120  
121 Those items marked with a '*' are also available via the C<Data> method
122  
123 =cut '
124  
125  
126  
127 2 my @DOW = qw[x Sun Mon Tue Wed Thu Fri Sat];
128 2 my @MON = qw[x Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec];
129  
130 ## helper function -- returns the given text cooked for html
131 sub _cook_for_html($)
132 0 ▶{
Subroutine _cook_for_html: not called CC=1 SCAR=6.9
133 0 my $text = shift;
134  
135 #die join(',', caller) if not defined $text;
136  
137 0 $text =~ s/&/&amp;/g;
138 0 $text =~ s/</&lt;/g;
139 0 $text =~ s/>/&gt;/g;
140 0 return $text;
141 }
142  
143 ##
144 ## helper function -- given a key in a result object, a result object (the
145 ## "self" from a method), and an indication of whether we want text or
146 ## html, return the appropriate text or html.
147 ##
148 sub _text_or_html($@)
149 0 ▶{
Subroutine _text_or_html: not called CC=3 SCAR=24.8
150 0 my $Key = shift;
151 0 my $Result = shift;
152 0 my $AsHtml = shift; #optional
153  
154 0 my $Text = $Result->{$Key};
155  
156 0 ▶ if (not defined $Text) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $Text) { } 0 0 0
elsif ($AsHtml) { } 0 0 0
157 0 return ();
158 } elsif ($AsHtml) {
159 0 return _cook_for_html($Text);
160 } else {
161 0 return $Text;
162 }
163 }
164  
165  
166 ##
167 ## helper function -- if passed one arg, it's a url, and simply return it.
168 ##
169 ## If passed multiple args, the 2nd is an attribute (e.g. "href", "src"),
170 ## which causes the return of a string like
171 ## href="$url"
172 ## where we're sure the quoting of the url is safe.
173 ##
174 sub _url($@)
175 0 ▶{
Subroutine _url: not called CC=5 SCAR=34.0
176 0 my $Url = shift;
177 0 my $Attrib = shift;
178  
179 0 ▶ if (not $Url)
Branch: 4 branches
BranchTrueFalseTotal
if (not $Url) { } 0 0 0
elsif (not $Attrib) { } 0 0 0
elsif (not $Url =~ /\x22/) { } 0 0 0
elsif (not $Url =~ /\x27/) { } 0 0 0
180 {
181 0 return ();
182 }
183 elsif (not $Attrib)
184 {
185 0 return $Url;
186 }
187 elsif (not $Url =~ m/\x22/) {
188 0 return qq/$Attrib="$Url"/;
189 } elsif (not $Url =~ m/\x27/) {
190 0 return qq/$Attrib='$Url'/;
191 } else {
192 0 $Url =~ s/\x22/%22/g; # double qoute
193 0 $Url =~ s/\x27/%27/g; # single quote
194 0 return qq/$Attrib="$Url"/;
195 }
196 }
197  
198  
199 ##
200 ## Want to be able to dump a hash of most data, so note which items are
201 ## available and interesting on a per-search-space basis.
202 ##
203 2 my @CommonItems = qw[Url ClickUrl Summary Title i I];
204  
205 2 my %ItemsBySpace =
206 (
207 Video => [@CommonItems, qw"Type Bytes HostUrl Copyright Publisher Restrictions Channels Seconds Duration Streaming Width Height ThumbUrl ThumbWidth ThumbHeight"],
208 Image => [@CommonItems, qw"Type Bytes HostUrl Copyright Publisher Restrictions Width Height ThumbUrl ThumbWidth ThumbHeight"],
209 Doc => [@CommonItems, qw"Type CacheUrl CacheSize ModTimestamp"],
210 Local => [@CommonItems, qw"Address City State Phone Miles Kilometers Rating MapUrl AllMapUrl"],
211 News => [@CommonItems, qw"SourceName SourceUrl Language ModTimestamp PublishTime ThumbUrl ThumbWidth ThumbHeight"],
212 Spell => [@CommonItems, "Term"],
213 Related => [@CommonItems, "Term"],
214 Terms => [@CommonItems, "Term"],
215 );
216  
217  
218  
219  
220 =head1 METHODS
221  
222 =over 4
223  
224 =cut
225  
226 ##############################################################################
227  
228 =item $Result->Next([I<boolean>])
229  
230 Returns the next C<Result> object from among the list of result objects
231 that are part of one C<Response> object.
232  
233 Returns nothing when called on the last result in a response, unless
234 auto-continuation is turned on, in which case the next set is automatically
235 fetched and the first C<Result> from that set's C<Response> is returned.
236  
237 An optional defined boolean argument turns auto-continuation on (true) or
238 off (false). If the argument is not defined, or not provided, the value for
239 the original request's C<AutoContinue> option (default off) is used.
240  
241 Note that using auto-continuation can be dangerous. See the docs for
242 C<NextResult> in Yahoo::Search::Response.
243  
244 =cut
245  
246 sub Next
247 0 ▶{
Subroutine Next: not called CC=5 SCAR=34.0
Pod documented
248 0 my $Result = shift; # self
249 0 my $AutoContinue = shift;
250  
251 0 ▶ if ($Result->{_ResponseOrdinal} < $#{ $Result->{_Response}->{Result} })
Branch: 1 branch
BranchTrueFalseTotal
if ($Result->{'_ResponseOrdinal'} < $#{$$Result{'_Response'}{'Result'};}) { } 0 0 0
252 {
253 0 return $Result->{_Response}->{Result}->[$Result->{_ResponseOrdinal} + 1];
254 }
255 else
256 {
257 0 ▶ if (not defined $AutoContinue) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $AutoContinue) 0 0 0
258 0 $AutoContinue = $Result->{_Response}->{_Request}->{AutoContinue};
259 }
260  
261 0 ▶ if ($AutoContinue
Branch: 1 branch
BranchTrueFalseTotal
if ($AutoContinue and my $NextResponse = $Result->{'_Response'}->NextSet) { } 0 0 0
Condition0%0/3
$AutoContinue and my $NextResponse = $Result->{"_Response"}->NextSet
!ll&&!rl&&r
000
MC/DC0%0/2
$AutoContinue and my $NextResponse = $Result->{"_Response"}->NextSet
$AutoContinue my $NextResponse = $Result->{"_Response"}->NextSet
Truth table0%0/3
A and B
A= $AutoContinueB= my $NextResponse = $Result->{"_Response"}->NextSet
ABresult
0X0
100
111
262 and
263 my $NextResponse = $Result->{_Response}->NextSet)
264 {
265 0 return $NextResponse->NextResult();
266 }
267 else
268 {
269 return ()
270 0 }
271 }
272 }
273  
274  
275  
276  
277 ##############################################################################
278  
279 =item $Result->Prev
280  
281 The opposite of C<Next>. No auto-continuation feature.
282  
283 =cut
284  
285 ## does not auto-fetch when fetching result[-1]
286 sub Prev
287 0 ▶{
Subroutine Prev: not called CC=2 SCAR=17.9
Pod documented
288 0 my $Result = shift; # self
289  
290 0 ▶ if ($Result->{_ResponseOrdinal} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Result->{'_ResponseOrdinal'} == 0) { } 0 0 0
291 0 return ();
292 } else {
293 0 return $Result->{_Response}->{Result}->[$Result->{_ResponseOrdinal} - 1];
294 }
295 }
296  
297  
298  
299 ##############################################################################
300  
301 =item $Result->Response
302  
303 Returns the C<Response> object of which this C<Result> object is a part.
304  
305 =cut
306  
307 sub Response
308 0 ▶{
Subroutine Response: not called CC=1 SCAR=6.9
Pod documented
309 0 my $Result = shift; # self
310 0 return $Result->{_Response};
311 }
312  
313  
314  
315 ##############################################################################
316  
317 =item $Result->Request
318  
319 Returns the original C<Request> object from which this C<Result> object's
320 C<Response> was derived.
321  
322 =cut '
323  
324 sub Request
325 0 ▶{
Subroutine Request: not called CC=1 SCAR=6.9
Pod documented
326 0 my $Result = shift; # self
327 0 return $Result->{_Response}->{_Request};
328 }
329  
330  
331  
332  
333 ##############################################################################
334  
335 =item $Result->SearchSpace
336  
337 Returns a string which indicates the search space of the original query
338 that this result was part of. (That is, it returns C<Doc>, C<Image>,
339 C<News>, C<Local>, or C<Video>.)
340  
341 It's the same as
342  
343 $Result->Request->SearchSpace;
344  
345 =cut
346  
347 sub SearchSpace
348 0 ▶{
Subroutine SearchSpace: not called CC=1 SCAR=6.9
Pod documented
349 0 my $Result = shift; # self
350 0 return $Result->{_Response}->{_Request}->{Space};
351 }
352  
353  
354  
355 ##############################################################################
356  
357  
358 =item $Result->i[ I<separator> ]
359  
360 =item $Result->I[ I<separator> ]
361  
362 The first (lower-case letter "i") returns the zero-based ordinal of the
363 result from among those in the current C<Response>.
364  
365 The latter (upper-case letter "I") returns the zero-based ordinal of the
366 result from among all search results that might be returned by Yahoo! for
367 the given query.
368  
369 For example, after
370  
371 my @Results = Yahoo::Search->Results(Image => "Briteny",
372 AppId => "my app id",
373 Start => 45,
374 Count => 15);
375  
376 the C<$Results[0]> result object has an C<I> of 45 (the 45th result of all
377 "Briteny" image results) and an C<i> of 0 (the 0th result among those
378 returned this time.)
379  
380 In either case, if an optional argument is given and is true, it is used as
381 a separator every three digits. In the US, one would use
382  
383 $Result->I(',')
384  
385 to return "1,234" where
386  
387 $Result->I()
388  
389 would return "1234".
390  
391 =cut
392  
393  
394 sub i
395 0 ▶{
Subroutine i: not called CC=1 SCAR=6.9
Pod undocumented
396 0 my $Result = shift; # self
397 0 my $Comma = shift; # optional
398 0 return Yahoo::Search::Response::_commaize($Result->{_ResponseOrdinal}, $Comma);
399 }
400  
401 sub I
402 0 ▶{
Subroutine I: not called CC=1 SCAR=6.9
Pod undocumented
403 0 my $Result = shift; # self
404 0 my $Comma = shift; # optional
405 0 return Yahoo::Search::Response::_commaize($Result->{_ResponseOrdinal} + $Result->{_Response}->{firstResultPosition} - 1, $Comma);
406 }
407  
408  
409  
410  
411 ##############################################################################
412  
413 =item $Result->as_html
414  
415 Returns a string of HTML that represents the result, as appropriate to the
416 result's query search space.
417  
418 There are many ways one may wish to display query results -- this method
419 returns one display that the author finds useful. It may come in useful for
420 quick prototyping of web applications, e.g.
421  
422 sub ShowRelated
423 {
424 print join "<hr>", map { $_->as_html } Yahoo::Search->Results(@_);
425 }
426  
427 (Also see C<Yahoo::Search-E<gt>HtmlResults>)
428  
429 The HTML returned by C<as_html> contains class references, thereby allowing
430 the look-and-feel to be easily adjusted. Here's a style sheet that makes
431 Image search results look palatable.
432  
433 <style>
434 .yResult { display: block; border: #CCF 3px solid ; padding:10px }
435 .yLink { }
436 .yTitle { display:none }
437 .yImg { border: solid 1px }
438 .yUrl { display:none }
439 .yMeta { font-size: 80% }
440 .ySrcUrl { }
441 .ySum { font-family: arial; font-size: 90% }
442 </style>
443  
444 B<Bugs>: English-centric
445  
446 =cut '
447  
448 sub as_html
449 0 ▶{
Subroutine as_html: not called CC=36 SCAR=71.9
Pod documented
450 0 my $Result = shift; # self
451 0 my $SearchSpace = $Result->SearchSpace;
452 0 my $summary = $Result->Summary(1);
453  
454 0 ▶ if ($SearchSpace eq 'Doc')
Branch: 1 branch
BranchTrueFalseTotal
if ($SearchSpace eq "Doc") 0 0 0
455 {
456 0 my $link = $Result->Link;
457 0 my $url = $Result->Url;
458  
459 0 my $html = "$link<span class=yUrl><br>$url</span>";
460 0 ▶ if ($summary) {
Branch: 1 branch
BranchTrueFalseTotal
if ($summary) 0 0 0
461 0 $html .= "<span class=ySum><br>$summary</span>";
462 }
463 0 return "<span class=yResult>$html</span>";
464 }
465  
466 0 ▶ if ($SearchSpace eq 'Video')
Branch: 1 branch
BranchTrueFalseTotal
if ($SearchSpace eq "Video") 0 0 0
467 {
468 0 my $HREF = $Result->ClickUrl('HREF');
469 0 my $title = $Result->Title(1);
470 0 my $html;
471 0 ▶ if (my $img = $Result->ThumbImg) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $img = $Result->ThumbImg) { } 0 0 0
472 0 $html = "<a class=yLink $HREF>$img<span class=yTitle> $title</span></a>";
473 } else {
474 0 $html = "<a class=yLink $HREF><span class=yTitle>$title</span></a>";
475 }
476  
477 0 $html .= "<span class=yUrl><br>" . $Result->Url . "</span>";
478  
479 0 my @extra;
480 0 ▶ if (my $duration = $Result->Duration) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $duration = $Result->Duration) 0 0 0
481 0 push @extra, "Duration: $duration";
482 }
483  
484 0 ▶ if (my $width = $Result->Width and my $height = $Result->Height) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $width = $Result->Width and my $height = $Result->Height) 0 0 0
Condition0%0/3
my $width = $Result->Width and my $height = $Result->Height
!ll&&!rl&&r
000
MC/DC0%0/2
my $width = $Result->Width and my $height = $Result->Height
my $width = $Result->Width my $height = $Result->Height
Truth table0%0/3
A and B
A= my $width = $Result->WidthB= my $height = $Result->Height
ABresult
0X0
100
111
485 0 push @extra, "Video resolution $width x $height";
486 }
487  
488 0 ▶ if (my $size = $Result->Bytes) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $size = $Result->Bytes) 0 0 0
489 0 push @extra, "File size: $size";
490 }
491  
492 0 ▶ if (my $chan = $Result->Channels) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $chan = $Result->Channels) 0 0 0
493 0 push @extra, "$chan-channel audio";
494 }
495  
496 0 ▶ if (my $HREF = $Result->HostUrl('href')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $HREF = $Result->HostUrl("href")) 0 0 0
497 0 push @extra, "<a class=ySrcUrl $HREF>Source page</a>";
498 }
499 0 ▶ if (@extra) {
Branch: 1 branch
BranchTrueFalseTotal
if (@extra) 0 0 0
500 0 $html .= "<span class=yMeta><br>" . join(" | ", @extra) . "</span>";
501 }
502  
503 0 ▶ if ($summary) {
Branch: 1 branch
BranchTrueFalseTotal
if ($summary) 0 0 0
504 0 $html .= "<span class=ySum><br>$summary</span>";
505 }
506 0 return "<span class=yResult>$html</span>";
507 }
508  
509 0 ▶ if ($SearchSpace eq 'Image')
Branch: 1 branch
BranchTrueFalseTotal
if ($SearchSpace eq "Image") 0 0 0
510 {
511 0 my $HREF = $Result->ClickUrl('href');
512 0 my $title = $Result->Title(1);
513 0 my $html;
514 0 ▶ if (my $img = $Result->ThumbImg) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $img = $Result->ThumbImg) { } 0 0 0
515 0 $html = "<a class=yLink $HREF>$img<span class=yTitle> $title</span></a>";
516 } else {
517 0 $html = "<a class=yLink $HREF><span class=yTitle>$title</span></a>";
518 }
519  
520 0 $html .= "<span class=yUrl><br>" . $Result->Url . "</span>";
521  
522 0 my @extra;
523 0 ▶ if (my $size = $Result->Bytes) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $size = $Result->Bytes) 0 0 0
524 0 push @extra, "File size: $size";
525 }
526 0 ▶ if (my $width = $Result->Width and my $height = $Result->Height) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $width = $Result->Width and my $height = $Result->Height) 0 0 0
Condition0%0/3
my $width = $Result->Width and my $height = $Result->Height
!ll&&!rl&&r
000
MC/DC0%0/2
my $width = $Result->Width and my $height = $Result->Height
my $width = $Result->Width my $height = $Result->Height
Truth table0%0/3
A and B
A= my $width = $Result->WidthB= my $height = $Result->Height
ABresult
0X0
100
111
527 0 push @extra, "Image size: $width x $height";
528 }
529 0 ▶ if (my $HREF = $Result->HostUrl('HREF')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $HREF = $Result->HostUrl("HREF")) 0 0 0
530 0 push @extra, "<a class=ySrcUrl $HREF>Source page</a>";
531 }
532 0 ▶ if (@extra) {
Branch: 1 branch
BranchTrueFalseTotal
if (@extra) 0 0 0
533 0 $html .= "<span class=yMeta><br>" . join(" | ", @extra) . "</span>";
534 }
535  
536 0 ▶ if ($summary) {
Branch: 1 branch
BranchTrueFalseTotal
if ($summary) 0 0 0
537 0 $html .= "<span class=ySum><br>$summary</span>";
538 }
539 0 return "<span class=yResult>$html</span>";
540 }
541  
542 0 ▶ if ($SearchSpace eq "News")
Branch: 1 branch
BranchTrueFalseTotal
if ($SearchSpace eq "News") 0 0 0
543 {
544 0 my $HREF = $Result->ClickUrl('HREF');
545 0 my $title = $Result->Title(1);
546 0 my $html = "<span class=yResult>";
547 0 ▶ if (my $img = $Result->ThumbImg) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $img = $Result->ThumbImg) { } 0 0 0
548 0 $html .= "<a class=yLink $HREF>$img<span class=yTitle> $title</span></a>";
549 } else {
550 0 $html .= "<a class=yLink $HREF><span class=yTitle>$title</span></a>";
551 }
552 0 my $src_name = $Result->SourceNameAsHtml;
553 0 my $src_href = $Result->SourceUrl('HREF');
554 0 ▶ if ($src_name and $src_href) {
Branch: 1 branch
BranchTrueFalseTotal
if ($src_name and $src_href) 0 0 0
Condition0%0/3
$src_name and $src_href
!ll&&!rl&&r
000
MC/DC0%0/2
$src_name and $src_href
$src_name $src_href
Truth table0%0/3
A and B
A= $src_nameB= $src_href
ABresult
0X0
100
111
555 0 $html .= "<a class=yNewsSrc $src_href><br>" . _cook_for_html($src_name) . "</a>";
556 }
557 0 ▶ if (my $when = $Result->PublishWhen) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $when = $Result->PublishWhen) 0 0 0
558 0 $html .= " <span class=yWhen>($when)</span>";
559 }
560  
561 0 ▶ if ($summary) {
Branch: 1 branch
BranchTrueFalseTotal
if ($summary) 0 0 0
562 0 $html .= "<span class=ySum><br>$summary</span>";
563 }
564 0 return "<span class=yResult>$html</span>";
565 }
566  
567 0 ▶ if ($SearchSpace eq "Local")
Branch: 1 branch
BranchTrueFalseTotal
if ($SearchSpace eq "Local") 0 0 0
568 {
569 0 my $html = $Result->Link;
570  
571 0 ▶ if (my $addr = join(', ', grep { $_ } $Result->Address, $Result->City . " " . $Result->State)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $addr = join(", ", grep({$_;} $Result->Address, $Result->City . ' ' . $Result->State))) 0 0 0
572 0 $html .= "<span class=yAddr><br>$addr</span>";
573 }
574  
575 0 my @extra;
576 0 ▶ if (my $phone = $Result->Phone) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $phone = $Result->Phone) 0 0 0
577 0 push @extra, "<span class=yPhone>$phone</span>";
578 }
579 0 ▶ if (my $HREF = $Result->MapUrl('href')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $HREF = $Result->MapUrl("href")) 0 0 0
580 0 push @extra, "<a class=yMap $HREF>Map</a>";
581 }
582 0 ▶ if (@extra) {
Branch: 1 branch
BranchTrueFalseTotal
if (@extra) 0 0 0
583 0 $html .= "<span class=yMeta><br>" . join(" | ",@extra) . "</span>";
584 }
585  
586 0 ▶ if ($summary) {
Branch: 1 branch
BranchTrueFalseTotal
if ($summary) 0 0 0
587 0 $html .= "<span class=ySum><br>$summary</span>";
588 }
589 0 return "<span class=yResult>$html</span>";
590 }
591  
592 0 ▶ if ($SearchSpace eq "Spell")
Branch: 1 branch
BranchTrueFalseTotal
if ($SearchSpace eq "Spell") 0 0 0
593 {
594 0 my $item = $Result->TermAsHtml;
595 0 return "Did you mean <i>$item</i>?";
596 }
597  
598 0 ▶ if ($SearchSpace eq "Related")
Branch: 1 branch
BranchTrueFalseTotal
if ($SearchSpace eq "Related") 0 0 0
599 {
600 0 my $item = $Result->TermAsHtml;
601 0 return "Also try: <i>$item</i>";
602 }
603  
604 0 ▶ if ($SearchSpace eq "Terms")
Branch: 1 branch
BranchTrueFalseTotal
if ($SearchSpace eq "Terms") 0 0 0
605 {
606 0 my $item = $Result->TermAsHtml;
607 0 return "Term: <i>$item</i>";
608 }
609  
610 0 return "???";
611 }
612  
613  
614 ##############################################################################
615  
616 =item $Result->as_string
617  
618 Returns a textual representation of the C<Result>, which may be useful for
619 quick prototyping or debugging.
620  
621 =cut
622  
623  
624 ## must create, for all spaces
625 sub as_string
626 0 ▶{
Subroutine as_string: not called CC=3 SCAR=24.8
Pod documented
627 0 my $Result = shift; # self
628 0 my $ref = $Result->Data;
629  
630 0 my $txt = "";
631  
632 0 for my $item (@{$ItemsBySpace{$Result->SearchSpace}})
633 {
634 0 ▶ if (defined(my $val = $Result->$item)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $val = $Result->$item)) 0 0 0
635 0 $txt .= "$item: $val\n";
636 }
637 }
638 0 return $txt;
639 }
640  
641 ##############################################################################
642  
643 =item $Result->Data
644  
645 Returns a list of key/value pairs containing the fundamental data for the
646 result (those items marked with '*' in the table at the start of this
647 document).
648  
649 my %Data = $Result->Data;
650  
651 =cut
652  
653  
654 sub Data
655 0 ▶{
Subroutine Data: not called CC=2 SCAR=17.9
Pod documented
656 0 my $Result = shift; # self
657 0 my %Data;
658  
659 0 for my $item (@{$ItemsBySpace{$Result->SearchSpace}})
660 {
661 0 $Data{$item} = $Result->$item;
662 }
663 0 return %Data;
664 }
665  
666  
667  
668 ##############################################################################
669  
670 =item $Result->Url
671  
672 =item $Result->ClickUrl
673  
674 C<Url> returns the raw url of the item (web page, image, etc.), appropriate
675 for display to the user.
676  
677 C<ClickUrl> returns a url appropriate for the href attribute of a link.
678  
679 In some cases, the two return the same url.
680  
681 As with all Result-object methods which return a url of some sort, you can
682 provide a single argument such as C<href> and receive a string such as
683 href="..."
684 appropriate to be used directly in html. For example,
685  
686 my $HREF = $Result->ClickUrl('href');
687 print "<a $HREF>click</a>";
688  
689 is preferable to
690  
691 my $url = $Result->ClickUrl;
692 print "<a href='$url'>click</a>";
693  
694 since the latter would break if C<$url> contains a singlequote.
695  
696 =cut
697  
698 sub Url
699 0 ▶{
Subroutine Url: not called CC=2 SCAR=17.9
Pod documented
700 0 my $Result = shift; # self
701 0 ▶ return _url($Result->{Url} || $Result->{ClickUrl}, @_);
Condition0%0/3
$Result->{'Url'} || $Result->{'ClickUrl'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$Result->{'Url'} || $Result->{'ClickUrl'}
$Result->{'Url'} $Result->{'ClickUrl'}
Truth table0%0/3
A || B
A= $Result->{'Url'}B= $Result->{'ClickUrl'}
ABresult
1X1
011
000
702 }
703  
704 sub ClickUrl
705 0 ▶{
Subroutine ClickUrl: not called CC=2 SCAR=17.9
Pod documented
706 0 my $Result = shift; # self
707 0 ▶ return _url($Result->{ClickUrl} || $Result->{Url}, @_);
Condition0%0/3
$Result->{'ClickUrl'} || $Result->{'Url'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$Result->{'ClickUrl'} || $Result->{'Url'}
$Result->{'ClickUrl'} $Result->{'Url'}
Truth table0%0/3
A || B
A= $Result->{'ClickUrl'}B= $Result->{'Url'}
ABresult
1X1
011
000
708 }
709  
710  
711  
712  
713  
714 ##############################################################################
715  
716 =item $Result->Title([ I<as_html> ])
717  
718 =item $Result->TitleAsHtml
719  
720 C<Title> returns the raw title text associated with the result. If an
721 optional argument is provided and is true, the title text is returned as
722 html.
723  
724 C<TitleAsHtml> is the same as
725  
726 $Result->Title(1)
727  
728 =cut
729  
730 sub Title
731 0 ▶{
Subroutine Title: not called CC=1 SCAR=6.9
Pod documented
732 0 return _text_or_html(Title => @_);
733 }
734  
735 sub TitleAsHtml
736 0 ▶{
Subroutine TitleAsHtml: not called CC=1 SCAR=6.9
Pod documented
737 0 my $Result = shift; #self
738 0 return $Result->Title(1);
739 }
740  
741  
742  
743  
744 ##############################################################################
745  
746 =item $Result->Link
747  
748 Returns a link made from the C<ClickUrl> and the C<Title>, with class
749 "yLink", e.g.
750  
751 <a class=yLink href='$URL'>$TITLE</a>
752  
753 =cut
754  
755 sub Link
756 0 ▶{
Subroutine Link: not called CC=3 SCAR=24.8
Pod documented
757 0 my $Result = shift; # self
758  
759 0 ▶ if (my $HREF = $Result->ClickUrl('href')
Branch: 1 branch
BranchTrueFalseTotal
if (my $HREF = $Result->ClickUrl('href') and my $title = $Result->Title(1)) { } 0 0 0
Condition0%0/3
my $HREF = $Result->ClickUrl("href") and my $title = $Result->Title(1)
!ll&&!rl&&r
000
MC/DC0%0/2
my $HREF = $Result->ClickUrl("href") and my $title = $Result->Title(1)
my $HREF = $Result->ClickUrl("href") my $title = $Result->Title(1)
Truth table0%0/3
A and B
A= my $HREF = $Result->ClickUrl("href")B= my $title = $Result->Title(1)
ABresult
0X0
100
111
760 and
761 my $title = $Result->Title(1))
762 {
763 0 return "<a class=yLink $HREF>$title</a>";
764 }
765 else
766 {
767 0 return ();
768 }
769 }
770  
771  
772  
773 ##############################################################################
774  
775 =item $Result->Summary([ I<as_html> ])
776  
777 =item $Result->SummaryAsHtml
778  
779 Like C<Title> and C<TitleAsHtml>, but for the summary associated with the
780 result.
781  
782 =cut
783  
784 sub Summary
785 0 ▶{
Subroutine Summary: not called CC=1 SCAR=6.9
Pod documented
786 0 return _text_or_html(Summary => @_);
787 }
788  
789 sub SummaryAsHtml
790 0 ▶{
Subroutine SummaryAsHtml: not called CC=1 SCAR=6.9
Pod documented
791 0 my $Result = shift; #self
792 0 return $Result->Summary(1);
793 }
794  
795  
796 =item $Result->CacheUrl
797  
798 =item $Result->CacheSize
799  
800 (I<Appropriate for B<Doc> search results>)
801  
802 C<CacheUrl> returns the url of the document in the Yahoo! cache.
803 See the documentation for the C<Url> method for information on the
804 one-argument version of this method.
805  
806 C<CacheSize> returns the size (as a string like "22k").
807  
808 =cut
809  
810 sub CacheUrl
811 0 ▶{
Subroutine CacheUrl: not called CC=2 SCAR=17.9
Pod documented
812 0 my $Result = shift; # self
813 0 ▶ return _url($Result->{Cache} ? $Result->{Cache}->{Url} : (), @_)
Branch: 1 branch
BranchTrueFalseTotal
$Result->{'Cache'} ? : 0 0 0
814 }
815  
816 sub CacheSize
817 0 ▶{
Subroutine CacheSize: not called CC=2 SCAR=17.9
Pod documented
818 0 my $Result = shift; # self
819 0 ▶ return $Result->{Cache} ? $Result->{Cache}->{Size} : ();
Branch: 1 branch
BranchTrueFalseTotal
$Result->{'Cache'} ? : 0 0 0
820 }
821  
822  
823  
824 ##############################################################################
825  
826 =item $Result->ModTimestamp
827  
828 (I<Appropriate for B<Doc> and B<News> search results>)
829  
830 The Unix timestamp of the Last-Modified time associated with the the url
831 when it was last checked by Yahoo!'s backend crawlers.
832  
833 =cut
834  
835 sub ModTimestamp
836 0 ▶{
Subroutine ModTimestamp: not called CC=2 SCAR=17.9
Pod documented
837 0 my $Result = shift; # self
838 0 ▶ return defined($Result->{ModificationDate}) ? $Result->{ModificationDate}: ();
Branch: 1 branch
BranchTrueFalseTotal
defined $Result->{'ModificationDate'} ? : 0 0 0
839 }
840  
841  
842 ##############################################################################
843  
844 =item $Result->Width
845  
846 =item $Result->Height
847  
848 (I<Appropriate for B<Image> and B<Video> search results>)
849  
850 The width and height (in pixels) of the image or video.
851  
852 =cut
853  
854 ## for image, video
855 sub Width
856 0 ▶{
Subroutine Width: not called CC=2 SCAR=17.9
Pod documented
857 0 my $Result = shift; # self
858 0 ▶ return defined($Result->{Width}) ? $Result->{Width} : ();
Branch: 1 branch
BranchTrueFalseTotal
defined $Result->{'Width'} ? : 0 0 0
859 }
860  
861 sub Height
862 0 ▶{
Subroutine Height: not called CC=2 SCAR=17.9
Pod documented
863 0 my $Result = shift; # self
864 0 ▶ return defined($Result->{Height}) ? $Result->{Height} : ();
Branch: 1 branch
BranchTrueFalseTotal
defined $Result->{'Height'} ? : 0 0 0
865 }
866  
867  
868  
869 ##############################################################################
870  
871 =item $Result->ThumbUrl
872  
873 =item $Result->ThumbWidth
874  
875 =item $Result->ThumbHeight
876  
877 (I<Appropriate for B<Image>, B<Video>, and B<News> search results>)
878  
879 The url of a thumbnail image, and its width and height.
880  
881 (Note: few I<News> results have a thumbnail, but some do.)
882  
883 See the documentation for the C<Url> method for information on the
884 one-argument version of C<ThumbUrl>.
885  
886 =cut
887  
888 sub ThumbUrl
889 0 ▶{
Subroutine ThumbUrl: not called CC=2 SCAR=17.9
Pod documented
890 0 my $Result = shift; # self
891 0 ▶ return _url($Result->{Thumbnail} ? $Result->{Thumbnail}->{Url} : (), @_);
Branch: 1 branch
BranchTrueFalseTotal
$Result->{'Thumbnail'} ? : 0 0 0
892 }
893  
894 sub ThumbWidth
895 0 ▶{
Subroutine ThumbWidth: not called CC=2 SCAR=17.9
Pod documented
896 0 my $Result = shift; # self
897 0 ▶ return $Result->{Thumbnail} ? $Result->{Thumbnail}->{Width} : ();
Branch: 1 branch
BranchTrueFalseTotal
$Result->{'Thumbnail'} ? : 0 0 0
898 }
899  
900 sub ThumbHeight
901 0 ▶{
Subroutine ThumbHeight: not called CC=2 SCAR=17.9
Pod documented
902 0 my $Result = shift; # self
903 0 ▶ return $Result->{Thumbnail} ? $Result->{Thumbnail}->{Height} : ();
Branch: 1 branch
BranchTrueFalseTotal
$Result->{'Thumbnail'} ? : 0 0 0
904 }
905  
906  
907 ##############################################################################
908  
909 =item $Result->ThumbImg
910  
911 (I<Appropriate for B<Image>, B<Video>, and B<News> search results>)
912  
913 Returns a C<E<lt>imgE<gt>> tag representing the thumbnail image, e.g.
914  
915 <img class=yImg src='$IMGURL' width=$WIDTH height=$HEIGHT>
916  
917 =cut
918  
919  
920 sub ThumbImg
921 0 ▶{
Subroutine ThumbImg: not called CC=2 SCAR=17.9
Pod documented
922 0 my $Result = shift; # self
923  
924 0 my $SRC = $Result->ThumbUrl('src');
925 0 my $Width = $Result->ThumbWidth;
926 0 my $Height = $Result->ThumbHeight;
927  
928 0 ▶ if ($SRC) {
Branch: 1 branch
BranchTrueFalseTotal
if ($SRC) { } 0 0 0
929 0 return "<img class=yImg $SRC width=$Width height=$Height>";
930 } else {
931 0 return ();
932 }
933 }
934  
935  
936 ##############################################################################
937  
938 =item $Result->ThumbLink
939  
940 (I<Appropriate for B<Image>, B<Video>, and B<News> search results>)
941  
942 Returns a link from the thumbnail to the C<ClickUrl> of the result,
943 e.g.
944  
945 <a class=yLink href='$CLICKURL'>
946 <img class=yImg src='$IMGURL' width=$WIDTH height=$HEIGHT>
947 </a>
948  
949 =cut
950  
951  
952 sub ThumbLink
953 0 ▶{
Subroutine ThumbLink: not called CC=3 SCAR=24.8
Pod documented
954 0 my $Result = shift; # self
955 0 my $HREF = $Result->ClickUrl('href');
956 0 my $img = $Result->ThumbImg;
957 0 ▶ if ($HREF and $img) {
Branch: 1 branch
BranchTrueFalseTotal
if ($HREF and $img) { } 0 0 0
Condition0%0/3
$HREF and $img
!ll&&!rl&&r
000
MC/DC0%0/2
$HREF and $img
$HREF $img
Truth table0%0/3
A and B
A= $HREFB= $img
ABresult
0X0
100
111
958 0 return "<a class=yLink $HREF>$img</a>";
959 } else {
960 0 return ();
961 }
962 }
963  
964  
965  
966 ##############################################################################
967  
968 =item $Result->HostUrl
969  
970 (I<Appropriate for B<Image> and B<Video> search results>)
971  
972 Returns the url of the web page containing a link to the image/video
973 item that the C<Result> represents.
974  
975 See the documentation for the C<Url> method for information on the
976 one-argument version of this method.
977  
978 =cut
979  
980 sub HostUrl
981 0 ▶{
Subroutine HostUrl: not called CC=1 SCAR=6.9
Pod documented
982 0 my $Result = shift; # self
983 0 return _url($Result->{RefererUrl}, @_);
984 }
985  
986 =cut
987  
988  
989  
990 ###########################################################################
991  
992 =item $Result->Type
993  
994 (<Appropriate for B<Doc>, B<Image>, and B<Video> search results>)
995  
996 Returns a string representing the file type of the item to which
997 C<$Result-E<gt>Url> points. For I<Doc> searches, the MIME type (e.g.
998 "text/html") is returned.
999  
1000 For other search spaces, here are the possible return values:
1001  
1002 Video: avi flash mpeg msmedia quicktime realmedia
1003 Image: bmp gif jpg png.
1004  
1005 Yahoo! Search derives these Video/Image C<Type> value by actually
1006 inspecting the file contents, and as such it is more reliable than looking
1007 at the file extension.
1008  
1009 =cut
1010  
1011 sub Type
1012 0 ▶{
Subroutine Type: not called CC=3 SCAR=24.8
Pod documented
1013 0 my $Result = shift; #self
1014 0 ▶ if (defined $Result->{MimeType}) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $Result->{'MimeType'}) { } 0 0 0
elsif (defined $Result->{'FileFormat'}) { } 0 0 0
1015 0 return $Result->{MimeType};
1016 } elsif (defined $Result->{FileFormat}) {
1017 0 return $Result->{FileFormat};
1018 } else {
1019 0 return ();
1020 }
1021 }
1022  
1023  
1024  
1025 ###########################################################################
1026  
1027 =item $Result->Copyright([ I<as_html> ])
1028  
1029 (<Appropriate for B<Image> and B<Video> search results>)
1030  
1031 Returns any copyright notice associated with the result. If an optional
1032 argument is provided and is true, the copyright text is returned as html.
1033  
1034 =cut
1035  
1036 sub Copyright
1037 0 ▶{
Subroutine Copyright: not called CC=1 SCAR=6.9
Pod documented
1038 0 return _text_or_html(Copyright => @_);
1039 }
1040  
1041  
1042  
1043 ###########################################################################
1044  
1045 =item $Result->Publisher([ I<as_html> ])
1046  
1047 (<Appropriate for B<Image>, and B<Video> search results>)
1048  
1049 Returns any publisher information (as a string) associated with the result.
1050 If an optional argument is provided and is true, the publisher information
1051 is returned as html.
1052  
1053 =cut
1054  
1055 sub Publisher
1056 0 ▶{
Subroutine Publisher: not called CC=1 SCAR=6.9
Pod documented
1057 0 return _text_or_html(Publisher => @_);
1058 }
1059  
1060  
1061  
1062 ###########################################################################
1063  
1064 =item $Result->Restrictions
1065  
1066 (<Appropriate for B<Image>, and B<Video> search results>)
1067  
1068 A (possibly zero-length) string containing zero or more of the following
1069 space-separated words:
1070  
1071 noframe
1072 noinline
1073  
1074 See Yahoo!'s web site (http://developer.yahoo.net/) for information on them.
1075  
1076 =cut
1077  
1078 sub Restrictions
1079 0 ▶{
Subroutine Restrictions: not called CC=2 SCAR=17.9
Pod documented
1080 0 my $Result = shift; #self
1081 0 ▶ if (not defined $Result->{Restrictions}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $Result->{'Restrictions'}) { } 0 0 0
1082 0 return "";
1083 } else {
1084 0 return $Result->{Restrictions};
1085 }
1086 }
1087  
1088  
1089  
1090 ##############################################################################
1091  
1092 =item $Result->Bytes
1093  
1094 (I<Appropriate for B<Image>, and B<Video> search results>)
1095  
1096 The size of the image/video item, in bytes.
1097  
1098 =cut
1099  
1100 sub Bytes
1101 0 ▶{
Subroutine Bytes: not called CC=2 SCAR=17.9
Pod documented
1102 0 my $Result = shift; #self
1103  
1104 0 ▶ if ($Result->{FileSize}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Result->{'FileSize'}) { } 0 0 0
1105 0 return $Result->{FileSize};
1106 } else {
1107 0 return ();
1108 }
1109 }
1110  
1111  
1112  
1113  
1114 ##############################################################################
1115  
1116 =item $Result->Channels
1117  
1118 (I<Appropriate for B<Video> search results>)
1119  
1120 Returns the number of channels in the audio, if known.
1121 Examples are "1", "2", "4.1", "5.1", etc....
1122  
1123 =cut
1124  
1125 sub Channels
1126 0 ▶{
Subroutine Channels: not called CC=2 SCAR=17.9
Pod documented
1127 0 my $Result = shift; # self
1128 0 ▶ if ($Result->{Channels}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Result->{'Channels'}) { } 0 0 0
1129 0 return $Result->{Channels};
1130 } else {
1131 0 return ();
1132 }
1133 }
1134  
1135  
1136  
1137 ##############################################################################
1138  
1139 =item $Result->Seconds
1140  
1141 (I<Appropriate for B<Video> search results>)
1142  
1143 Returns the duration of the video clip, if known, in (possibly fractional)
1144 seconds.
1145  
1146 =cut
1147  
1148 sub Seconds
1149 0 ▶{
Subroutine Seconds: not called CC=2 SCAR=17.9
Pod documented
1150 0 my $Result = shift; #self
1151  
1152 0 ▶ if ($Result->{Duration}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Result->{"Duration"}) 0 0 0
1153 0 return $Result->{Duration};
1154 }
1155 0 return ();
1156 }
1157  
1158  
1159  
1160 ##############################################################################
1161  
1162 =item $Result->Duration
1163  
1164 (I<Appropriate for B<Video> search results>)
1165  
1166 Returns a string representing the duration of the video clip, if known, in
1167 the form of "37 sec", "1:23", or "4:56:23", as appropriate.
1168  
1169 B<Bugs>: English-centric
1170  
1171 =cut
1172  
1173 sub Duration
1174 0 ▶{
Subroutine Duration: not called CC=4 SCAR=30.0
Pod documented
1175 0 my $Result = shift; #self
1176  
1177 0 ▶ if (my $sec = $Result->Seconds)
Branch: 1 branch
BranchTrueFalseTotal
if (my $sec = $Result->Seconds) 0 0 0
1178 {
1179 0 ▶ if ($sec < 60) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sec < 60) 0 0 0
1180 0 return sprintf "%d sec", $sec;
1181 }
1182 0 ▶ if ($sec < 3600) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sec < 3600) 0 0 0
1183 0 return sprintf "%d:%02d", int($sec/60), $sec%60;
1184 }
1185 0 my $hours = int($sec/3600);
1186 0 $sec = $sec % 3600;
1187 0 return sprintf "%d:%02d:%02d", $hours, int($sec/60), $sec%60;
1188 }
1189  
1190 0 return ();
1191 }
1192  
1193  
1194  
1195 ##############################################################################
1196  
1197 =item $Result->Streaming
1198  
1199 (I<Appropriate for B<Video> search results>)
1200  
1201 Returns "1" if the multimedia is streaming, "0" if not.
1202 If not known, an empty list is returned.
1203  
1204 =cut
1205  
1206 sub Streaming
1207 0 ▶{
Subroutine Streaming: not called CC=4 SCAR=30.0
Pod documented
1208 0 my $Result = shift; #self
1209  
1210 0 ▶ my $Stream = $Result->{Streaming} || '';
Condition0%0/2
$Result->{'Streaming'} || ''
l!l
00
MC/DC0%0/1
$Result->{'Streaming'} || ''
$Result->{'Streaming'}
Truth table0%0/2
A
A= $Result->{'Streaming'}
Aresult
11
00
1211 0 ▶ if ($Stream eq 'true') {
Branch: 2 branches
BranchTrueFalseTotal
if ($Stream eq 'true') { } 0 0 0
elsif ($Stream eq 'false') { } 0 0 0
1212 0 return 1;
1213 } elsif ($Stream eq 'false') {
1214 0 return 0;
1215 } else {
1216 0 return ();
1217 }
1218 }
1219  
1220  
1221  
1222 ##############################################################################
1223  
1224 =item $Result->SourceUrl
1225  
1226 (I<Appropriate for B<News> search results>)
1227  
1228 The main url of the news provider hosting the article that the C<Result>
1229 refers to.
1230  
1231 See the documentation for the C<Url> method for information on the
1232 one-argument version of this method.
1233  
1234 =cut
1235  
1236 sub SourceUrl
1237 0 ▶{
Subroutine SourceUrl: not called CC=1 SCAR=6.9
Pod documented
1238 0 my $Result = shift; # self
1239 0 return _url($Result->{NewsSourceUrl}, @_);
1240 }
1241  
1242  
1243  
1244  
1245 ##############################################################################
1246  
1247 =item $Result->SourceName([ I<as_html> ])
1248  
1249 =item $Result->SourceNameAsHtml
1250  
1251 (I<Appropriate for B<News> search results>)
1252  
1253 Similar to C<Title> and C<TitleAsHtml>, but the name of the organization
1254 associated with the news article (and, by extension, with C<SourceUrl>).
1255  
1256 =cut
1257  
1258 sub SourceName
1259 0 ▶{
Subroutine SourceName: not called CC=1 SCAR=6.9
Pod documented
1260 0 return _text_or_html(NewsSource => @_);
1261 }
1262  
1263 sub SourceNameAsHtml
1264 0 ▶{
Subroutine SourceNameAsHtml: not called CC=1 SCAR=6.9
Pod documented
1265 0 my $Result = shift; # self
1266 0 return $Result->SourceName(1);
1267 }
1268  
1269  
1270  
1271 ##############################################################################
1272  
1273 =item $Result->Language
1274  
1275 (I<Appropriate for B<News> search results>)
1276  
1277 A code representing the language in which the article is written (e.g. "en"
1278 for English, "ja" for Japanese, etc.). See the list of language codes at
1279 C<perldoc> Yahoo::Search.
1280  
1281 =cut
1282  
1283 sub Language
1284 0 ▶{
Subroutine Language: not called CC=1 SCAR=6.9
Pod documented
1285 0 my $Result = shift; # self
1286 0 return $Result->{Language};
1287 }
1288  
1289  
1290 ##############################################################################
1291  
1292 =item $Result->PublishTime
1293  
1294 =item $Result->PublishWhen
1295  
1296 (I<Appropriate for B<News> search results>)
1297  
1298 C<PublishTime> is the Unix time associated with the article, e.g.
1299  
1300 print "Published ", scalar(localtime $Result->PublishTime), "\n";
1301  
1302 C<PublishWhen> gives a string along the lines of
1303  
1304 3h 25m ago (if less than 12 hours ago)
1305 Tue 9:47am (if less than 5 days ago)
1306 Sat, Dec 25 (if less than 100 days ago)
1307 Sat, Dec 25, 2004 (if >= 100 days ago)
1308  
1309 B<Bug>: C<PublishWhen> is English-centric.
1310  
1311 =cut
1312  
1313 sub PublishTime
1314 0 ▶{
Subroutine PublishTime: not called CC=2 SCAR=17.9
Pod documented
1315 0 my $Result = shift; # self
1316 0 ▶ if (defined $Result->{PublishDate}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $Result->{'PublishDate'}) { } 0 0 0
1317 0 return $Result->{PublishDate};
1318 } else {
1319 0 return ();
1320 }
1321 }
1322  
1323 sub PublishWhen
1324 0 ▶{
Subroutine PublishWhen: not called CC=8 SCAR=42.8
Pod documented
1325 0 my $Result = shift; #self
1326  
1327 0 my $time = $Result->PublishTime;
1328 0 ▶ if (not $time) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($time) 0 0 0
1329 0 return ();
1330 }
1331  
1332 0 my $delta = time - $time;
1333 0 ▶ if ($delta < 3600 * 12)
Branch: 1 branch
BranchTrueFalseTotal
if ($delta < 43200) 0 0 0
1334 {
1335 0 my $h = int( $delta / 3600);
1336 0 my $m = int(($delta % 3600)/60 + 0.5);
1337 0 return "${h}h ${m}m ago";
1338 }
1339  
1340 0 ▶ if ($delta < 5 * 3600 * 24)
Branch: 1 branch
BranchTrueFalseTotal
if ($delta < 432000) 0 0 0
1341 {
1342 ## give day and time
1343 0 my ($m,$h, $DOW) = (localtime $time)[1,2,6];
1344 0 my $ampm = "am";
1345 0 ▶ if ($h == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($h == 0) { } 0 0 0
elsif ($h >= 12) { } 0 0 0
1346 0 $h = 12;
1347 } elsif ($h >= 12) {
1348 0 $ampm = "pm";
1349 0 ▶ if ($h > 12) {
Branch: 1 branch
BranchTrueFalseTotal
if ($h > 12) 0 0 0
1350 0 $h -= 12;
1351 }
1352 }
1353 0 return sprintf("%s %d:%02d%s", $DOW[$DOW], $h, $m, $ampm);
1354 }
1355  
1356 0 ▶ if ($delta < 100 * 3600 * 24)
Branch: 1 branch
BranchTrueFalseTotal
if ($delta < 8640000) { } 0 0 0
1357 {
1358 0 my ($D,$M,$Y,$DOW) = (localtime $time)[3..6];
1359 0 return sprintf("%s %s %d", $DOW[$DOW], $MON[$M], $D);
1360 }
1361 else
1362 {
1363 0 my ($D,$M,$Y,$DOW) = (localtime $time)[3..6];
1364 0 return sprintf("%s %s %d, %04d", $DOW[$DOW], $MON[$M], $D, $Y+1900);
1365 }
1366 }
1367  
1368  
1369 ##############################################################################
1370  
1371 =item $Result->Address
1372  
1373 =item $Result->City
1374  
1375 =item $Result->State
1376  
1377 =item $Result->Phone
1378  
1379 (I<Appropriate for B<Local> search results>)
1380  
1381 Location and Phone number for the business that the C<Result> refers to.
1382  
1383 =cut
1384  
1385 ## for local
1386 sub Address
1387 0 ▶{
Subroutine Address: not called CC=1 SCAR=6.9
Pod documented
1388 0 my $Result = shift; # self
1389 0 return $Result->{Address};
1390 }
1391  
1392 sub City
1393 0 ▶{
Subroutine City: not called CC=1 SCAR=6.9
Pod documented
1394 0 my $Result = shift; # self
1395 0 return $Result->{City};
1396 }
1397  
1398 sub State
1399 0 ▶{
Subroutine State: not called CC=1 SCAR=6.9
Pod documented
1400 0 my $Result = shift; # self
1401 0 return $Result->{State};
1402 }
1403  
1404 sub Phone
1405 0 ▶{
Subroutine Phone: not called CC=1 SCAR=6.9
Pod documented
1406 0 my $Result = shift; # self
1407 0 return $Result->{Phone};
1408 }
1409  
1410  
1411  
1412  
1413  
1414 ##############################################################################
1415  
1416 =item $Result->Miles
1417  
1418 =item $Result->Kilometers
1419  
1420 (I<Appropriate for B<Local> search results>)
1421  
1422 The distance (in miles and kilometers) from the location used to make the
1423 query to the location of this result.
1424  
1425 =cut
1426  
1427 sub Kilometers
1428 0 ▶{
Subroutine Kilometers: not called CC=2 SCAR=17.9
Pod documented
1429 0 my $Result = shift; # self
1430 0 ▶ return defined($Result->{Distance}) ? $Result->{Distance} * 1.609 : ();
Branch: 1 branch
BranchTrueFalseTotal
defined $Result->{'Distance'} ? : 0 0 0
1431 }
1432  
1433 sub Miles
1434 0 ▶{
Subroutine Miles: not called CC=2 SCAR=17.9
Pod documented
1435 0 my $Result = shift; # self
1436 0 ▶ return defined($Result->{Distance}) ? $Result->{Distance} : ();
Branch: 1 branch
BranchTrueFalseTotal
defined $Result->{'Distance'} ? : 0 0 0
1437 }
1438  
1439  
1440  
1441  
1442  
1443 ##############################################################################
1444  
1445 =item $Result->Rating
1446  
1447 (I<Appropriate for B<Local> search results>)
1448  
1449 Returns the rating associated with the result, if there is one. If there is
1450 a rating, it is from 1 (lowest) to 5 (highest) in 0.5-sized steps. If not,
1451 nothing is returned.
1452  
1453 =cut
1454  
1455 sub Rating
1456 0 ▶{
Subroutine Rating: not called CC=2 SCAR=17.9
Pod documented
1457 0 my $Result = shift; # self
1458 0 ▶ return defined($Result->{Rating}) ? $Result->{Rating} : ();
Branch: 1 branch
BranchTrueFalseTotal
defined $Result->{'Rating'} ? : 0 0 0
1459 }
1460  
1461  
1462  
1463 ##############################################################################
1464  
1465 =item $Result->MapUrl
1466  
1467 =item $Result->AllMapUrl
1468  
1469 (I<Appropriate for B<Local> search results>)
1470  
1471 C<MapUrl> is a url to a Yahoo! Maps map showing the business' location.
1472  
1473 C<AllMapUrl> is a url to a Yahoo! Maps map showing all the businesses
1474 found in the same result-set that the current C<Result> was part of.
1475  
1476 See the documentation for the C<Url> method for information on the
1477 one-argument versions of these methods.
1478  
1479 =cut
1480  
1481 sub MapUrl
1482 0 ▶{
Subroutine MapUrl: not called CC=1 SCAR=6.9
Pod documented
1483 0 my $Result = shift; # self
1484 0 return _url($Result->{MapUrl}, @_);
1485 }
1486  
1487 sub AllMapUrl
1488 0 ▶{
Subroutine AllMapUrl: not called CC=1 SCAR=6.9
Pod documented
1489 0 my $Result = shift; # self
1490 0 return _url($Result->Response->MapUrl, @_);
1491 }
1492  
1493  
1494  
1495 ##############################################################################
1496  
1497 =item $Result->BusinessUrl
1498  
1499 =item $Result->BusinessClickUrl
1500  
1501 (I<Appropriate for B<Local> search results>)
1502  
1503 The business' home page, if available. C<BusinessUrl> is appropriate for
1504 display, while C<BusinessClickUrl> is appropriate for the href of a link.
1505  
1506 See the documentation for the C<Url> method for information on the
1507 one-argument versions of these methods.
1508  
1509 =cut
1510  
1511 sub BusinessUrl
1512 0 ▶{
Subroutine BusinessUrl: not called CC=1 SCAR=6.9
Pod documented
1513 0 my $Result = shift; # self
1514 0 return _url($Result->{BusinessUrl}, @_);
1515 }
1516  
1517 sub BusinessClickUrl
1518 0 ▶{
Subroutine BusinessClickUrl: not called CC=2 SCAR=17.9
Pod documented
1519 0 my $Result = shift; # self
1520 0 ▶ return _url($Result->{BusinessClickUrl} || $Result->{BusinessUrl}, @_);
Condition0%0/3
$Result->{'BusinessClickUrl'} || $Result->{'BusinessUrl'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$Result->{'BusinessClickUrl'} || $Result->{'BusinessUrl'}
$Result->{'BusinessClickUrl'} $Result->{'BusinessUrl'}
Truth table0%0/3
A || B
A= $Result->{'BusinessClickUrl'}B= $Result->{'BusinessUrl'}
ABresult
1X1
011
000
1521 }
1522  
1523  
1524  
1525 ##############################################################################
1526  
1527 =item $Result->Term([ I<as_html> ])
1528  
1529 =item $Result->TermAsHtml
1530  
1531 (I<Appropriate for B<Spell>, B<Related>, and B<Terms> search results>)
1532  
1533 C<Term> returns the term associated with the result. If an optional
1534 argument is provided and is true, the term text is returned as html.
1535  
1536 C<TermAsHtml> is the same as
1537  
1538 $Result->Term(1)
1539  
1540 =cut
1541  
1542 sub Term
1543 0 ▶{
Subroutine Term: not called CC=1 SCAR=6.9
Pod documented
1544 0 _text_or_html(Term => @_);
1545 }
1546  
1547 sub TermAsHtml
1548 0 ▶{
Subroutine TermAsHtml: not called CC=1 SCAR=6.9
Pod documented
1549 0 my $Result = shift; #self
1550 0 return $Result->Term(1);
1551 }
1552  
1553  
1554 ##############################################################################
1555  
1556 =pod
1557  
1558 =back
1559  
1560 =head1 Author
1561  
1562 Jeffrey Friedl (jfriedl@yahoo.com)
1563  
1564 =cut
1565  
1566 2 1;
↑ Summary Search/XML.pm »