| blib/lib/Yahoo/Search/Result.pm | |||
|---|---|---|---|
| Criterion | Covered | Total | % |
| statement | 3 | 304 | 0.9 |
| branch | 0 | 152 | 0.0 |
| condition | 0 | 29 | 0.0 |
| subroutine | 1 | 60 | 1.6 |
| pod | 54 | 56 | 96.4 |
| total | 58 | 601 | 9.6 |
| line | stmt | bran | cond | sub | pod | time | code |
|---|---|---|---|---|---|---|---|
| 1 | package Yahoo::Search::Result; | ||||||
| 2 | 2 | 2 | 12 | use strict; | |||
| 2 | 6 | ||||||
| 2 | 10379 | ||||||
| 3 | |||||||
| 4 | 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 | ||||||
| 19 | automatically by Yahoo::Search. | ||||||
| 20 | |||||||
| 21 | =head1 Object Creation | ||||||
| 22 | |||||||
| 23 | C |
||||||
| 24 | created (when a C |
||||||
| 25 | directly, or indirectly via a shortcut such as | ||||||
| 26 | C |
||||||
| 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 method | ||||||
| 122 | |||||||
| 123 | =cut ' | ||||||
| 124 | |||||||
| 125 | |||||||
| 126 | |||||||
| 127 | my @DOW = qw[x Sun Mon Tue Wed Thu Fri Sat]; | ||||||
| 128 | 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 | { | ||||||
| 133 | 0 | 0 | my $text = shift; | ||||
| 134 | |||||||
| 135 | #die join(',', caller) if not defined $text; | ||||||
| 136 | |||||||
| 137 | 0 | $text =~ s/&/&/g; | |||||
| 138 | 0 | $text =~ s/</g; | |||||
| 139 | 0 | $text =~ s/>/>/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 | { | ||||||
| 150 | 0 | 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 | 0 | if (not defined $Text) { | ||||
| 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 | { | ||||||
| 176 | 0 | 0 | my $Url = shift; | ||||
| 177 | 0 | my $Attrib = shift; | |||||
| 178 | |||||||
| 179 | 0 | 0 | if (not $Url) | ||||
| 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 | my @CommonItems = qw[Url ClickUrl Summary Title i I]; | ||||||
| 204 | |||||||
| 205 | 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 |
||||||
| 229 | |||||||
| 230 | Returns the next C |
||||||
| 231 | that are part of one C |
||||||
| 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 |
||||||
| 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 |
||||||
| 240 | |||||||
| 241 | Note that using auto-continuation can be dangerous. See the docs for | ||||||
| 242 | C |
||||||
| 243 | |||||||
| 244 | =cut | ||||||
| 245 | |||||||
| 246 | sub Next | ||||||
| 247 | { | ||||||
| 248 | 0 | 0 | 1 | my $Result = shift; # self | |||
| 249 | 0 | my $AutoContinue = shift; | |||||
| 250 | |||||||
| 251 | 0 | 0 | if ($Result->{_ResponseOrdinal} < $#{ $Result->{_Response}->{Result} }) | ||||
| 0 | |||||||
| 252 | { | ||||||
| 253 | 0 | return $Result->{_Response}->{Result}->[$Result->{_ResponseOrdinal} + 1]; | |||||
| 254 | } | ||||||
| 255 | else | ||||||
| 256 | { | ||||||
| 257 | 0 | 0 | if (not defined $AutoContinue) { | ||||
| 258 | 0 | $AutoContinue = $Result->{_Response}->{_Request}->{AutoContinue}; | |||||
| 259 | } | ||||||
| 260 | |||||||
| 261 | 0 | 0 | 0 | if ($AutoContinue | |||
| 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 |
||||||
| 282 | |||||||
| 283 | =cut | ||||||
| 284 | |||||||
| 285 | ## does not auto-fetch when fetching result[-1] | ||||||
| 286 | sub Prev | ||||||
| 287 | { | ||||||
| 288 | 0 | 0 | 1 | my $Result = shift; # self | |||
| 289 | |||||||
| 290 | 0 | 0 | if ($Result->{_ResponseOrdinal} == 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 |
||||||
| 304 | |||||||
| 305 | =cut | ||||||
| 306 | |||||||
| 307 | sub Response | ||||||
| 308 | { | ||||||
| 309 | 0 | 0 | 1 | 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 |
||||||
| 320 | C |
||||||
| 321 | |||||||
| 322 | =cut ' | ||||||
| 323 | |||||||
| 324 | sub Request | ||||||
| 325 | { | ||||||
| 326 | 0 | 0 | 1 | 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 |
||||||
| 339 | C |
||||||
| 340 | |||||||
| 341 | It's the same as | ||||||
| 342 | |||||||
| 343 | $Result->Request->SearchSpace; | ||||||
| 344 | |||||||
| 345 | =cut | ||||||
| 346 | |||||||
| 347 | sub SearchSpace | ||||||
| 348 | { | ||||||
| 349 | 0 | 0 | 1 | my $Result = shift; # self | |||
| 350 | 0 | return $Result->{_Response}->{_Request}->{Space}; | |||||
| 351 | } | ||||||
| 352 | |||||||
| 353 | |||||||
| 354 | |||||||
| 355 | ############################################################################## | ||||||
| 356 | |||||||
| 357 | |||||||
| 358 | =item $Result->i[ I |
||||||
| 359 | |||||||
| 360 | =item $Result->I[ I |
||||||
| 361 | |||||||
| 362 | The first (lower-case letter "i") returns the zero-based ordinal of the | ||||||
| 363 | result from among those in the current C |
||||||
| 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 of 45 (the 45th result of all | ||||||
| 377 | "Briteny" image results) and an C 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 | { | ||||||
| 396 | 0 | 0 | 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 | { | ||||||
| 403 | 0 | 0 | 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 " ", map { $_->as_html } Yahoo::Search->Results(@_); |
||||||
| 425 | } | ||||||
| 426 | |||||||
| 427 | (Also see C |
||||||
| 428 | |||||||
| 429 | The HTML returned by C |
||||||
| 430 | the look-and-feel to be easily adjusted. Here's a style sheet that makes | ||||||
| 431 | Image search results look palatable. | ||||||
| 432 | |||||||
| 433 | |||||||
| 443 | |||||||
| 444 | B |
||||||
| 445 | |||||||
| 446 | =cut ' | ||||||
| 447 | |||||||
| 448 | sub as_html | ||||||
| 449 | { | ||||||
| 450 | 0 | 0 | 1 | my $Result = shift; # self | |||
| 451 | 0 | my $SearchSpace = $Result->SearchSpace; | |||||
| 452 | 0 | my $summary = $Result->Summary(1); | |||||
| 453 | |||||||
| 454 | 0 | 0 | if ($SearchSpace eq 'Doc') | ||||
| 455 | { | ||||||
| 456 | 0 | my $link = $Result->Link; | |||||
| 457 | 0 | my $url = $Result->Url; | |||||
| 458 | |||||||
| 459 | 0 | my $html = "$link $url"; |
|||||
| 460 | 0 | 0 | if ($summary) { | ||||
| 461 | 0 | $html .= " $summary"; |
|||||
| 462 | } | ||||||
| 463 | 0 | return "$html"; | |||||
| 464 | } | ||||||
| 465 | |||||||
| 466 | 0 | 0 | if ($SearchSpace eq 'Video') | ||||
| 467 | { | ||||||
| 468 | 0 | my $HREF = $Result->ClickUrl('HREF'); | |||||
| 469 | 0 | my $title = $Result->Title(1); | |||||
| 470 | 0 | my $html; | |||||
| 471 | 0 | 0 | if (my $img = $Result->ThumbImg) { | ||||
| 472 | 0 | $html = "$img $title"; | |||||
| 473 | } else { | ||||||
| 474 | 0 | $html = "$title"; | |||||
| 475 | } | ||||||
| 476 | |||||||
| 477 | 0 | $html .= " " . $Result->Url . ""; |
|||||
| 478 | |||||||
| 479 | 0 | my @extra; | |||||
| 480 | 0 | 0 | if (my $duration = $Result->Duration) { | ||||
| 481 | 0 | push @extra, "Duration: $duration"; | |||||
| 482 | } | ||||||
| 483 | |||||||
| 484 | 0 | 0 | 0 | if (my $width = $Result->Width and my $height = $Result->Height) { | |||
| 485 | 0 | push @extra, "Video resolution $width x $height"; | |||||
| 486 | } | ||||||
| 487 | |||||||
| 488 | 0 | 0 | if (my $size = $Result->Bytes) { | ||||
| 489 | 0 | push @extra, "File size: $size"; | |||||
| 490 | } | ||||||
| 491 | |||||||
| 492 | 0 | 0 | if (my $chan = $Result->Channels) { | ||||
| 493 | 0 | push @extra, "$chan-channel audio"; | |||||
| 494 | } | ||||||
| 495 | |||||||
| 496 | 0 | 0 | if (my $HREF = $Result->HostUrl('href')) { | ||||
| 497 | 0 | push @extra, "Source page"; | |||||
| 498 | } | ||||||
| 499 | 0 | 0 | if (@extra) { | ||||
| 500 | 0 | $html .= " " . join(" | ", @extra) . ""; |
|||||
| 501 | } | ||||||
| 502 | |||||||
| 503 | 0 | 0 | if ($summary) { | ||||
| 504 | 0 | $html .= " $summary"; |
|||||
| 505 | } | ||||||
| 506 | 0 | return "$html"; | |||||
| 507 | } | ||||||
| 508 | |||||||
| 509 | 0 | 0 | if ($SearchSpace eq 'Image') | ||||
| 510 | { | ||||||
| 511 | 0 | my $HREF = $Result->ClickUrl('href'); | |||||
| 512 | 0 | my $title = $Result->Title(1); | |||||
| 513 | 0 | my $html; | |||||
| 514 | 0 | 0 | if (my $img = $Result->ThumbImg) { | ||||
| 515 | 0 | $html = "$img $title"; | |||||
| 516 | } else { | ||||||
| 517 | 0 | $html = "$title"; | |||||
| 518 | } | ||||||
| 519 | |||||||
| 520 | 0 | $html .= " " . $Result->Url . ""; |
|||||
| 521 | |||||||
| 522 | 0 | my @extra; | |||||
| 523 | 0 | 0 | if (my $size = $Result->Bytes) { | ||||
| 524 | 0 | push @extra, "File size: $size"; | |||||
| 525 | } | ||||||
| 526 | 0 | 0 | 0 | if (my $width = $Result->Width and my $height = $Result->Height) { | |||
| 527 | 0 | push @extra, "Image size: $width x $height"; | |||||
| 528 | } | ||||||
| 529 | 0 | 0 | if (my $HREF = $Result->HostUrl('HREF')) { | ||||
| 530 | 0 | push @extra, "Source page"; | |||||
| 531 | } | ||||||
| 532 | 0 | 0 | if (@extra) { | ||||
| 533 | 0 | $html .= " " . join(" | ", @extra) . ""; |
|||||
| 534 | } | ||||||
| 535 | |||||||
| 536 | 0 | 0 | if ($summary) { | ||||
| 537 | 0 | $html .= " $summary"; |
|||||
| 538 | } | ||||||
| 539 | 0 | return "$html"; | |||||
| 540 | } | ||||||
| 541 | |||||||
| 542 | 0 | 0 | if ($SearchSpace eq "News") | ||||
| 543 | { | ||||||
| 544 | 0 | my $HREF = $Result->ClickUrl('HREF'); | |||||
| 545 | 0 | my $title = $Result->Title(1); | |||||
| 546 | 0 | my $html = ""; | |||||
| 547 | 0 | 0 | if (my $img = $Result->ThumbImg) { | ||||
| 548 | 0 | $html .= "$img $title"; | |||||
| 549 | } else { | ||||||
| 550 | 0 | $html .= "$title"; | |||||
| 551 | } | ||||||
| 552 | 0 | my $src_name = $Result->SourceNameAsHtml; | |||||
| 553 | 0 | my $src_href = $Result->SourceUrl('HREF'); | |||||
| 554 | 0 | 0 | 0 | if ($src_name and $src_href) { | |||
| 555 | 0 | $html .= " " . _cook_for_html($src_name) . ""; |
|||||
| 556 | } | ||||||
| 557 | 0 | 0 | if (my $when = $Result->PublishWhen) { | ||||
| 558 | 0 | $html .= " ($when)"; | |||||
| 559 | } | ||||||
| 560 | |||||||
| 561 | 0 | 0 | if ($summary) { | ||||
| 562 | 0 | $html .= " $summary"; |
|||||
| 563 | } | ||||||
| 564 | 0 | return "$html"; | |||||
| 565 | } | ||||||
| 566 | |||||||
| 567 | 0 | 0 | if ($SearchSpace eq "Local") | ||||
| 568 | { | ||||||
| 569 | 0 | my $html = $Result->Link; | |||||
| 570 | |||||||
| 571 | 0 | 0 | if (my $addr = join(', ', grep { $_ } $Result->Address, $Result->City . " " . $Result->State)) { | ||||
| 0 | |||||||
| 572 | 0 | $html .= " $addr"; |
|||||
| 573 | } | ||||||
| 574 | |||||||
| 575 | 0 | my @extra; | |||||
| 576 | 0 | 0 | if (my $phone = $Result->Phone) { | ||||
| 577 | 0 | push @extra, "$phone"; | |||||
| 578 | } | ||||||
| 579 | 0 | 0 | if (my $HREF = $Result->MapUrl('href')) { | ||||
| 580 | 0 | push @extra, "Map"; | |||||
| 581 | } | ||||||
| 582 | 0 | 0 | if (@extra) { | ||||
| 583 | 0 | $html .= " " . join(" | ",@extra) . ""; |
|||||
| 584 | } | ||||||
| 585 | |||||||
| 586 | 0 | 0 | if ($summary) { | ||||
| 587 | 0 | $html .= " $summary"; |
|||||
| 588 | } | ||||||
| 589 | 0 | return "$html"; | |||||
| 590 | } | ||||||
| 591 | |||||||
| 592 | 0 | 0 | if ($SearchSpace eq "Spell") | ||||
| 593 | { | ||||||
| 594 | 0 | my $item = $Result->TermAsHtml; | |||||
| 595 | 0 | return "Did you mean $item?"; | |||||
| 596 | } | ||||||
| 597 | |||||||
| 598 | 0 | 0 | if ($SearchSpace eq "Related") | ||||
| 599 | { | ||||||
| 600 | 0 | my $item = $Result->TermAsHtml; | |||||
| 601 | 0 | return "Also try: $item"; | |||||
| 602 | } | ||||||
| 603 | |||||||
| 604 | 0 | 0 | if ($SearchSpace eq "Terms") | ||||
| 605 | { | ||||||
| 606 | 0 | my $item = $Result->TermAsHtml; | |||||
| 607 | 0 | return "Term: $item"; | |||||
| 608 | } | ||||||
| 609 | |||||||
| 610 | 0 | return "???"; | |||||
| 611 | } | ||||||
| 612 | |||||||
| 613 | |||||||
| 614 | ############################################################################## | ||||||
| 615 | |||||||
| 616 | =item $Result->as_string | ||||||
| 617 | |||||||
| 618 | Returns a textual representation of the C |
||||||
| 619 | quick prototyping or debugging. | ||||||
| 620 | |||||||
| 621 | =cut | ||||||
| 622 | |||||||
| 623 | |||||||
| 624 | ## must create, for all spaces | ||||||
| 625 | sub as_string | ||||||
| 626 | { | ||||||
| 627 | 0 | 0 | 1 | my $Result = shift; # self | |||
| 628 | 0 | my $ref = $Result->Data; | |||||
| 629 | |||||||
| 630 | 0 | my $txt = ""; | |||||
| 631 | |||||||
| 632 | 0 | for my $item (@{$ItemsBySpace{$Result->SearchSpace}}) | |||||
| 0 | |||||||
| 633 | { | ||||||
| 634 | 0 | 0 | if (defined(my $val = $Result->$item)) { | ||||
| 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 | { | ||||||
| 656 | 0 | 0 | 1 | my $Result = shift; # self | |||
| 657 | 0 | my %Data; | |||||
| 658 | |||||||
| 659 | 0 | for my $item (@{$ItemsBySpace{$Result->SearchSpace}}) | |||||
| 0 | |||||||
| 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 |
||||||
| 675 | for display to the user. | ||||||
| 676 | |||||||
| 677 | C |
||||||
| 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 |
||||||
| 683 | href="..." | ||||||
| 684 | appropriate to be used directly in html. For example, | ||||||
| 685 | |||||||
| 686 | my $HREF = $Result->ClickUrl('href'); | ||||||
| 687 | print "click"; | ||||||
| 688 | |||||||
| 689 | is preferable to | ||||||
| 690 | |||||||
| 691 | my $url = $Result->ClickUrl; | ||||||
| 692 | print "click"; | ||||||
| 693 | |||||||
| 694 | since the latter would break if C<$url> contains a singlequote. | ||||||
| 695 | |||||||
| 696 | =cut | ||||||
| 697 | |||||||
| 698 | sub Url | ||||||
| 699 | { | ||||||
| 700 | 0 | 0 | 1 | my $Result = shift; # self | |||
| 701 | 0 | 0 | return _url($Result->{Url} || $Result->{ClickUrl}, @_); | ||||
| 702 | } | ||||||
| 703 | |||||||
| 704 | sub ClickUrl | ||||||
| 705 | { | ||||||
| 706 | 0 | 0 | 1 | my $Result = shift; # self | |||
| 707 | 0 | 0 | return _url($Result->{ClickUrl} || $Result->{Url}, @_); | ||||
| 708 | } | ||||||
| 709 | |||||||
| 710 | |||||||
| 711 | |||||||
| 712 | |||||||
| 713 | |||||||
| 714 | ############################################################################## | ||||||
| 715 | |||||||
| 716 | =item $Result->Title([ I |
||||||
| 717 | |||||||
| 718 | =item $Result->TitleAsHtml | ||||||
| 719 | |||||||
| 720 | C |
||||||
| 721 | optional argument is provided and is true, the title text is returned as | ||||||
| 722 | html. | ||||||
| 723 | |||||||
| 724 | C |
||||||
| 725 | |||||||
| 726 | $Result->Title(1) | ||||||
| 727 | |||||||
| 728 | =cut | ||||||
| 729 | |||||||
| 730 | sub Title | ||||||
| 731 | { | ||||||
| 732 | 0 | 0 | 1 | return _text_or_html(Title => @_); | |||
| 733 | } | ||||||
| 734 | |||||||
| 735 | sub TitleAsHtml | ||||||
| 736 | { | ||||||
| 737 | 0 | 0 | 1 | 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 |
||||||
| 749 | "yLink", e.g. | ||||||
| 750 | |||||||
| 751 | $TITLE | ||||||
| 752 | |||||||
| 753 | =cut | ||||||
| 754 | |||||||
| 755 | sub Link | ||||||
| 756 | { | ||||||
| 757 | 0 | 0 | 1 | my $Result = shift; # self | |||
| 758 | |||||||
| 759 | 0 | 0 | 0 | if (my $HREF = $Result->ClickUrl('href') | |||
| 760 | and | ||||||
| 761 | my $title = $Result->Title(1)) | ||||||
| 762 | { | ||||||
| 763 | 0 | return "$title"; | |||||
| 764 | } | ||||||
| 765 | else | ||||||
| 766 | { | ||||||
| 767 | 0 | return (); | |||||
| 768 | } | ||||||
| 769 | } | ||||||
| 770 | |||||||
| 771 | |||||||
| 772 | |||||||
| 773 | ############################################################################## | ||||||
| 774 | |||||||
| 775 | =item $Result->Summary([ I |
||||||
| 776 | |||||||
| 777 | =item $Result->SummaryAsHtml | ||||||
| 778 | |||||||
| 779 | Like C |
||||||
| 780 | result. | ||||||
| 781 | |||||||
| 782 | =cut | ||||||
| 783 | |||||||
| 784 | sub Summary | ||||||
| 785 | { | ||||||
| 786 | 0 | 0 | 1 | return _text_or_html(Summary => @_); | |||
| 787 | } | ||||||
| 788 | |||||||
| 789 | sub SummaryAsHtml | ||||||
| 790 | { | ||||||
| 791 | 0 | 0 | 1 | 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 |
||||||
| 801 | |||||||
| 802 | C |
||||||
| 803 | See the documentation for the C |
||||||
| 804 | one-argument version of this method. | ||||||
| 805 | |||||||
| 806 | C |
||||||
| 807 | |||||||
| 808 | =cut | ||||||
| 809 | |||||||
| 810 | sub CacheUrl | ||||||
| 811 | { | ||||||
| 812 | 0 | 0 | 1 | my $Result = shift; # self | |||
| 813 | 0 | 0 | return _url($Result->{Cache} ? $Result->{Cache}->{Url} : (), @_) | ||||
| 814 | } | ||||||
| 815 | |||||||
| 816 | sub CacheSize | ||||||
| 817 | { | ||||||
| 818 | 0 | 0 | 1 | my $Result = shift; # self | |||
| 819 | 0 | 0 | return $Result->{Cache} ? $Result->{Cache}->{Size} : (); | ||||
| 820 | } | ||||||
| 821 | |||||||
| 822 | |||||||
| 823 | |||||||
| 824 | ############################################################################## | ||||||
| 825 | |||||||
| 826 | =item $Result->ModTimestamp | ||||||
| 827 | |||||||
| 828 | (I |
||||||
| 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 | { | ||||||
| 837 | 0 | 0 | 1 | my $Result = shift; # self | |||
| 838 | 0 | 0 | return defined($Result->{ModificationDate}) ? $Result->{ModificationDate}: (); | ||||
| 839 | } | ||||||
| 840 | |||||||
| 841 | |||||||
| 842 | ############################################################################## | ||||||
| 843 | |||||||
| 844 | =item $Result->Width | ||||||
| 845 | |||||||
| 846 | =item $Result->Height | ||||||
| 847 | |||||||
| 848 | (I |
||||||
| 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 | { | ||||||
| 857 | 0 | 0 | 1 | my $Result = shift; # self | |||
| 858 | 0 | 0 | return defined($Result->{Width}) ? $Result->{Width} : (); | ||||
| 859 | } | ||||||
| 860 | |||||||
| 861 | sub Height | ||||||
| 862 | { | ||||||
| 863 | 0 | 0 | 1 | my $Result = shift; # self | |||
| 864 | 0 | 0 | return defined($Result->{Height}) ? $Result->{Height} : (); | ||||
| 865 | } | ||||||
| 866 | |||||||
| 867 | |||||||
| 868 | |||||||
| 869 | ############################################################################## | ||||||
| 870 | |||||||
| 871 | =item $Result->ThumbUrl | ||||||
| 872 | |||||||
| 873 | =item $Result->ThumbWidth | ||||||
| 874 | |||||||
| 875 | =item $Result->ThumbHeight | ||||||
| 876 | |||||||
| 877 | (I |
||||||
| 878 | |||||||
| 879 | The url of a thumbnail image, and its width and height. | ||||||
| 880 | |||||||
| 881 | (Note: few I |
||||||
| 882 | |||||||
| 883 | See the documentation for the C |
||||||
| 884 | one-argument version of C |
||||||
| 885 | |||||||
| 886 | =cut | ||||||
| 887 | |||||||
| 888 | sub ThumbUrl | ||||||
| 889 | { | ||||||
| 890 | 0 | 0 | 1 | my $Result = shift; # self | |||
| 891 | 0 | 0 | return _url($Result->{Thumbnail} ? $Result->{Thumbnail}->{Url} : (), @_); | ||||
| 892 | } | ||||||
| 893 | |||||||
| 894 | sub ThumbWidth | ||||||
| 895 | { | ||||||
| 896 | 0 | 0 | 1 | my $Result = shift; # self | |||
| 897 | 0 | 0 | return $Result->{Thumbnail} ? $Result->{Thumbnail}->{Width} : (); | ||||
| 898 | } | ||||||
| 899 | |||||||
| 900 | sub ThumbHeight | ||||||
| 901 | { | ||||||
| 902 | 0 | 0 | 1 | my $Result = shift; # self | |||
| 903 | 0 | 0 | return $Result->{Thumbnail} ? $Result->{Thumbnail}->{Height} : (); | ||||
| 904 | } | ||||||
| 905 | |||||||
| 906 | |||||||
| 907 | ############################################################################## | ||||||
| 908 | |||||||
| 909 | =item $Result->ThumbImg | ||||||
| 910 | |||||||
| 911 | (I |
||||||
| 912 | |||||||
| 913 | Returns a C |
||||||
| 914 | |||||||
| 915 | |
||||||
| 916 | |||||||
| 917 | =cut | ||||||
| 918 | |||||||
| 919 | |||||||
| 920 | sub ThumbImg | ||||||
| 921 | { | ||||||
| 922 | 0 | 0 | 1 | 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 | 0 | if ($SRC) { | ||||
| 929 | 0 | return " |
|||||
| 930 | } else { | ||||||
| 931 | 0 | return (); | |||||
| 932 | } | ||||||
| 933 | } | ||||||
| 934 | |||||||
| 935 | |||||||
| 936 | ############################################################################## | ||||||
| 937 | |||||||
| 938 | =item $Result->ThumbLink | ||||||
| 939 | |||||||
| 940 | (I |
||||||
| 941 | |||||||
| 942 | Returns a link from the thumbnail to the C |
||||||
| 943 | e.g. | ||||||
| 944 | |||||||
| 945 | |||||||
| 946 | |
||||||
| 947 | |||||||
| 948 | |||||||
| 949 | =cut | ||||||
| 950 | |||||||
| 951 | |||||||
| 952 | sub ThumbLink | ||||||
| 953 | { | ||||||
| 954 | 0 | 0 | 1 | my $Result = shift; # self | |||
| 955 | 0 | my $HREF = $Result->ClickUrl('href'); | |||||
| 956 | 0 | my $img = $Result->ThumbImg; | |||||
| 957 | 0 | 0 | 0 | if ($HREF and $img) { | |||
| 958 | 0 | return "$img"; | |||||
| 959 | } else { | ||||||
| 960 | 0 | return (); | |||||
| 961 | } | ||||||
| 962 | } | ||||||
| 963 | |||||||
| 964 | |||||||
| 965 | |||||||
| 966 | ############################################################################## | ||||||
| 967 | |||||||
| 968 | =item $Result->HostUrl | ||||||
| 969 | |||||||
| 970 | (I |
||||||
| 971 | |||||||
| 972 | Returns the url of the web page containing a link to the image/video | ||||||
| 973 | item that the C |
||||||
| 974 | |||||||
| 975 | See the documentation for the C |
||||||
| 976 | one-argument version of this method. | ||||||
| 977 | |||||||
| 978 | =cut | ||||||
| 979 | |||||||
| 980 | sub HostUrl | ||||||
| 981 | { | ||||||
| 982 | 0 | 0 | 1 | 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 | ( |
||||||
| 995 | |||||||
| 996 | Returns a string representing the file type of the item to which | ||||||
| 997 | C<$Result-E |
||||||
| 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 |
||||||
| 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 | { | ||||||
| 1013 | 0 | 0 | 1 | my $Result = shift; #self | |||
| 1014 | 0 | 0 | if (defined $Result->{MimeType}) { | ||||
| 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 |
||||||
| 1028 | |||||||
| 1029 | ( |
||||||
| 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 | { | ||||||
| 1038 | 0 | 0 | 1 | return _text_or_html(Copyright => @_); | |||
| 1039 | } | ||||||
| 1040 | |||||||
| 1041 | |||||||
| 1042 | |||||||
| 1043 | ########################################################################### | ||||||
| 1044 | |||||||
| 1045 | =item $Result->Publisher([ I |
||||||
| 1046 | |||||||
| 1047 | ( |
||||||
| 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 | { | ||||||
| 1057 | 0 | 0 | 1 | return _text_or_html(Publisher => @_); | |||
| 1058 | } | ||||||
| 1059 | |||||||
| 1060 | |||||||
| 1061 | |||||||
| 1062 | ########################################################################### | ||||||
| 1063 | |||||||
| 1064 | =item $Result->Restrictions | ||||||
| 1065 | |||||||
| 1066 | ( |
||||||
| 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 | { | ||||||
| 1080 | 0 | 0 | 1 | my $Result = shift; #self | |||
| 1081 | 0 | 0 | if (not defined $Result->{Restrictions}) { | ||||
| 1082 | 0 | return ""; | |||||
| 1083 | } else { | ||||||
| 1084 | 0 | return $Result->{Restrictions}; | |||||
| 1085 | } | ||||||
| 1086 | } | ||||||
| 1087 | |||||||
| 1088 | |||||||
| 1089 | |||||||
| 1090 | ############################################################################## | ||||||
| 1091 | |||||||
| 1092 | =item $Result->Bytes | ||||||
| 1093 | |||||||
| 1094 | (I |
||||||
| 1095 | |||||||
| 1096 | The size of the image/video item, in bytes. | ||||||
| 1097 | |||||||
| 1098 | =cut | ||||||
| 1099 | |||||||
| 1100 | sub Bytes | ||||||
| 1101 | { | ||||||
| 1102 | 0 | 0 | 1 | my $Result = shift; #self | |||
| 1103 | |||||||
| 1104 | 0 | 0 | if ($Result->{FileSize}) { | ||||
| 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 |
||||||
| 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 | { | ||||||
| 1127 | 0 | 0 | 1 | my $Result = shift; # self | |||
| 1128 | 0 | 0 | if ($Result->{Channels}) { | ||||
| 1129 | 0 | return $Result->{Channels}; | |||||
| 1130 | } else { | ||||||
| 1131 | 0 | return (); | |||||
| 1132 | } | ||||||
| 1133 | } | ||||||
| 1134 | |||||||
| 1135 | |||||||
| 1136 | |||||||
| 1137 | ############################################################################## | ||||||
| 1138 | |||||||
| 1139 | =item $Result->Seconds | ||||||
| 1140 | |||||||
| 1141 | (I |
||||||
| 1142 | |||||||
| 1143 | Returns the duration of the video clip, if known, in (possibly fractional) | ||||||
| 1144 | seconds. | ||||||
| 1145 | |||||||
| 1146 | =cut | ||||||
| 1147 | |||||||
| 1148 | sub Seconds | ||||||
| 1149 | { | ||||||
| 1150 | 0 | 0 | 1 | my $Result = shift; #self | |||
| 1151 | |||||||
| 1152 | 0 | 0 | if ($Result->{Duration}) { | ||||
| 1153 | 0 | return $Result->{Duration}; | |||||
| 1154 | } | ||||||
| 1155 | 0 | return (); | |||||
| 1156 | } | ||||||
| 1157 | |||||||
| 1158 | |||||||
| 1159 | |||||||
| 1160 | ############################################################################## | ||||||
| 1161 | |||||||
| 1162 | =item $Result->Duration | ||||||
| 1163 | |||||||
| 1164 | (I |
||||||
| 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 |
||||||
| 1170 | |||||||
| 1171 | =cut | ||||||
| 1172 | |||||||
| 1173 | sub Duration | ||||||
| 1174 | { | ||||||
| 1175 | 0 | 0 | 1 | my $Result = shift; #self | |||
| 1176 | |||||||
| 1177 | 0 | 0 | if (my $sec = $Result->Seconds) | ||||
| 1178 | { | ||||||
| 1179 | 0 | 0 | if ($sec < 60) { | ||||
| 1180 | 0 | return sprintf "%d sec", $sec; | |||||
| 1181 | } | ||||||
| 1182 | 0 | 0 | if ($sec < 3600) { | ||||
| 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 |
||||||
| 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 | { | ||||||
| 1208 | 0 | 0 | 1 | my $Result = shift; #self | |||
| 1209 | |||||||
| 1210 | 0 | 0 | my $Stream = $Result->{Streaming} || ''; | ||||
| 1211 | 0 | 0 | if ($Stream eq 'true') { | ||||
| 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 |
||||||
| 1227 | |||||||
| 1228 | The main url of the news provider hosting the article that the C |
||||||
| 1229 | refers to. | ||||||
| 1230 | |||||||
| 1231 | See the documentation for the C |
||||||
| 1232 | one-argument version of this method. | ||||||
| 1233 | |||||||
| 1234 | =cut | ||||||
| 1235 | |||||||
| 1236 | sub SourceUrl | ||||||
| 1237 | { | ||||||
| 1238 | 0 | 0 | 1 | my $Result = shift; # self | |||
| 1239 | 0 | return _url($Result->{NewsSourceUrl}, @_); | |||||
| 1240 | } | ||||||
| 1241 | |||||||
| 1242 | |||||||
| 1243 | |||||||
| 1244 | |||||||
| 1245 | ############################################################################## | ||||||
| 1246 | |||||||
| 1247 | =item $Result->SourceName([ I |
||||||
| 1248 | |||||||
| 1249 | =item $Result->SourceNameAsHtml | ||||||
| 1250 | |||||||
| 1251 | (I |
||||||
| 1252 | |||||||
| 1253 | Similar to C |
||||||
| 1254 | associated with the news article (and, by extension, with C |
||||||
| 1255 | |||||||
| 1256 | =cut | ||||||
| 1257 | |||||||
| 1258 | sub SourceName | ||||||
| 1259 | { | ||||||
| 1260 | 0 | 0 | 1 | return _text_or_html(NewsSource => @_); | |||
| 1261 | } | ||||||
| 1262 | |||||||
| 1263 | sub SourceNameAsHtml | ||||||
| 1264 | { | ||||||
| 1265 | 0 | 0 | 1 | my $Result = shift; # self | |||
| 1266 | 0 | return $Result->SourceName(1); | |||||
| 1267 | } | ||||||
| 1268 | |||||||
| 1269 | |||||||
| 1270 | |||||||
| 1271 | ############################################################################## | ||||||
| 1272 | |||||||
| 1273 | =item $Result->Language | ||||||
| 1274 | |||||||
| 1275 | (I |
||||||
| 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 |
||||||
| 1280 | |||||||
| 1281 | =cut | ||||||
| 1282 | |||||||
| 1283 | sub Language | ||||||
| 1284 | { | ||||||
| 1285 | 0 | 0 | 1 | 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 |
||||||
| 1297 | |||||||
| 1298 | C |
||||||
| 1299 | |||||||
| 1300 | print "Published ", scalar(localtime $Result->PublishTime), "\n"; | ||||||
| 1301 | |||||||
| 1302 | C |
||||||
| 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 |
||||||
| 1310 | |||||||
| 1311 | =cut | ||||||
| 1312 | |||||||
| 1313 | sub PublishTime | ||||||
| 1314 | { | ||||||
| 1315 | 0 | 0 | 1 | my $Result = shift; # self | |||
| 1316 | 0 | 0 | if (defined $Result->{PublishDate}) { | ||||
| 1317 | 0 | return $Result->{PublishDate}; | |||||
| 1318 | } else { | ||||||
| 1319 | 0 | return (); | |||||
| 1320 | } | ||||||
| 1321 | } | ||||||
| 1322 | |||||||
| 1323 | sub PublishWhen | ||||||
| 1324 | { | ||||||
| 1325 | 0 | 0 | 1 | my $Result = shift; #self | |||
| 1326 | |||||||
| 1327 | 0 | my $time = $Result->PublishTime; | |||||
| 1328 | 0 | 0 | if (not $time) { | ||||
| 1329 | 0 | return (); | |||||
| 1330 | } | ||||||
| 1331 | |||||||
| 1332 | 0 | my $delta = time - $time; | |||||
| 1333 | 0 | 0 | if ($delta < 3600 * 12) | ||||
| 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 | 0 | if ($delta < 5 * 3600 * 24) | ||||
| 1341 | { | ||||||
| 1342 | ## give day and time | ||||||
| 1343 | 0 | my ($m,$h, $DOW) = (localtime $time)[1,2,6]; | |||||
| 1344 | 0 | my $ampm = "am"; | |||||
| 1345 | 0 | 0 | if ($h == 0) { | ||||
| 0 | |||||||
| 1346 | 0 | $h = 12; | |||||
| 1347 | } elsif ($h >= 12) { | ||||||
| 1348 | 0 | $ampm = "pm"; | |||||
| 1349 | 0 | 0 | if ($h > 12) { | ||||
| 1350 | 0 | $h -= 12; | |||||
| 1351 | } | ||||||
| 1352 | } | ||||||
| 1353 | 0 | return sprintf("%s %d:%02d%s", $DOW[$DOW], $h, $m, $ampm); | |||||
| 1354 | } | ||||||
| 1355 | |||||||
| 1356 | 0 | 0 | if ($delta < 100 * 3600 * 24) | ||||
| 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 |
||||||
| 1380 | |||||||
| 1381 | Location and Phone number for the business that the C |
||||||
| 1382 | |||||||
| 1383 | =cut | ||||||
| 1384 | |||||||
| 1385 | ## for local | ||||||
| 1386 | sub Address | ||||||
| 1387 | { | ||||||
| 1388 | 0 | 0 | 1 | my $Result = shift; # self | |||
| 1389 | 0 | return $Result->{Address}; | |||||
| 1390 | } | ||||||
| 1391 | |||||||
| 1392 | sub City | ||||||
| 1393 | { | ||||||
| 1394 | 0 | 0 | 1 | my $Result = shift; # self | |||
| 1395 | 0 | return $Result->{City}; | |||||
| 1396 | } | ||||||
| 1397 | |||||||
| 1398 | sub State | ||||||
| 1399 | { | ||||||
| 1400 | 0 | 0 | 1 | my $Result = shift; # self | |||
| 1401 | 0 | return $Result->{State}; | |||||
| 1402 | } | ||||||
| 1403 | |||||||
| 1404 | sub Phone | ||||||
| 1405 | { | ||||||
| 1406 | 0 | 0 | 1 | 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 |
||||||
| 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 | { | ||||||
| 1429 | 0 | 0 | 1 | my $Result = shift; # self | |||
| 1430 | 0 | 0 | return defined($Result->{Distance}) ? $Result->{Distance} * 1.609 : (); | ||||
| 1431 | } | ||||||
| 1432 | |||||||
| 1433 | sub Miles | ||||||
| 1434 | { | ||||||
| 1435 | 0 | 0 | 1 | my $Result = shift; # self | |||
| 1436 | 0 | 0 | return defined($Result->{Distance}) ? $Result->{Distance} : (); | ||||
| 1437 | } | ||||||
| 1438 | |||||||
| 1439 | |||||||
| 1440 | |||||||
| 1441 | |||||||
| 1442 | |||||||
| 1443 | ############################################################################## | ||||||
| 1444 | |||||||
| 1445 | =item $Result->Rating | ||||||
| 1446 | |||||||
| 1447 | (I |
||||||
| 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 | { | ||||||
| 1457 | 0 | 0 | 1 | my $Result = shift; # self | |||
| 1458 | 0 | 0 | return defined($Result->{Rating}) ? $Result->{Rating} : (); | ||||
| 1459 | } | ||||||
| 1460 | |||||||
| 1461 | |||||||
| 1462 | |||||||
| 1463 | ############################################################################## | ||||||
| 1464 | |||||||
| 1465 | =item $Result->MapUrl | ||||||
| 1466 | |||||||
| 1467 | =item $Result->AllMapUrl | ||||||
| 1468 | |||||||
| 1469 | (I |
||||||
| 1470 | |||||||
| 1471 | C |
||||||
| 1472 | |||||||
| 1473 | C |
||||||
| 1474 | found in the same result-set that the current C |
||||||
| 1475 | |||||||
| 1476 | See the documentation for the C |
||||||
| 1477 | one-argument versions of these methods. | ||||||
| 1478 | |||||||
| 1479 | =cut | ||||||
| 1480 | |||||||
| 1481 | sub MapUrl | ||||||
| 1482 | { | ||||||
| 1483 | 0 | 0 | 1 | my $Result = shift; # self | |||
| 1484 | 0 | return _url($Result->{MapUrl}, @_); | |||||
| 1485 | } | ||||||
| 1486 | |||||||
| 1487 | sub AllMapUrl | ||||||
| 1488 | { | ||||||
| 1489 | 0 | 0 | 1 | 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 |
||||||
| 1502 | |||||||
| 1503 | The business' home page, if available. C |
||||||
| 1504 | display, while C |
||||||
| 1505 | |||||||
| 1506 | See the documentation for the C |
||||||
| 1507 | one-argument versions of these methods. | ||||||
| 1508 | |||||||
| 1509 | =cut | ||||||
| 1510 | |||||||
| 1511 | sub BusinessUrl | ||||||
| 1512 | { | ||||||
| 1513 | 0 | 0 | 1 | my $Result = shift; # self | |||
| 1514 | 0 | return _url($Result->{BusinessUrl}, @_); | |||||
| 1515 | } | ||||||
| 1516 | |||||||
| 1517 | sub BusinessClickUrl | ||||||
| 1518 | { | ||||||
| 1519 | 0 | 0 | 1 | my $Result = shift; # self | |||
| 1520 | 0 | 0 | return _url($Result->{BusinessClickUrl} || $Result->{BusinessUrl}, @_); | ||||
| 1521 | } | ||||||
| 1522 | |||||||
| 1523 | |||||||
| 1524 | |||||||
| 1525 | ############################################################################## | ||||||
| 1526 | |||||||
| 1527 | =item $Result->Term([ I |
||||||
| 1528 | |||||||
| 1529 | =item $Result->TermAsHtml | ||||||
| 1530 | |||||||
| 1531 | (I |
||||||
| 1532 | |||||||
| 1533 | C |
||||||
| 1534 | argument is provided and is true, the term text is returned as html. | ||||||
| 1535 | |||||||
| 1536 | C |
||||||
| 1537 | |||||||
| 1538 | $Result->Term(1) | ||||||
| 1539 | |||||||
| 1540 | =cut | ||||||
| 1541 | |||||||
| 1542 | sub Term | ||||||
| 1543 | { | ||||||
| 1544 | 0 | 0 | 1 | _text_or_html(Term => @_); | |||
| 1545 | } | ||||||
| 1546 | |||||||
| 1547 | sub TermAsHtml | ||||||
| 1548 | { | ||||||
| 1549 | 0 | 0 | 1 | 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 | 1; |