package Yahoo::Search::Result; use strict; our $VERSION = "20070320.002"; # just to make CPAN happy =head1 NAME Yahoo::Search::Result -- class representing a single result (single web page, image, video file, etc) from a Yahoo! search-engine query. (This package is included in, and automatically loaded by, the Yahoo::Search package.) =head1 Package Use You never need to C this package directly -- it is loaded automatically by Yahoo::Search. =head1 Object Creation C objects are created automatically when a C object is created (when a C object's C method is called, either directly, or indirectly via a shortcut such as CQuery()>. =head1 Methods Overview This table shows the methods available on a per-search-space basis: Terms Related | Spell | | Local | | | News | | | | Video | | | | | Image | | | | | | Doc | | | | | | | | | | | | | | | Next [X] [X] [X] [X] [X] [X] [X] [X] Prev [X] [X] [X] [X] [X] [X] [X] [X] Response [X] [X] [X] [X] [X] [X] [X] [X] Request [X] [X] [X] [X] [X] [X] [X] [X] SearchSpace [X] [X] [X] [X] [X] [X] [X] [X] * I [X] [X] [X] [X] [X] [X] [X] . * i [X] [X] [X] [X] [X] [X] [X] . as_html [X] [X] [X] [X] [X] [X] [X] . as_string [X] [X] [X] [X] [X] [X] [X] . Data [X] [X] [X] [X] [X] [X] [X] . * Url [X] [X] [X] [X] [X] . . . * ClickUrl [X] [X] [X] [X] [X] . . . * Title [X] [X] [X] [X] [X] . . . TitleAsHtml [X] [X] [X] [X] [X] . . . Link [X] [X] [X] [X] [X] . . . * Summary [X] [X] [X] [X] . . . . SummaryAsHtml [X] [X] [X] [X] . . . . * CacheUrl [X] . . . . . . . * CacheSize [X] . . . . . . . * ModTimestamp [X] . . [X] . . . . * Width . [X] [X] . . . . . * Height . [X] [X] . . . . . * ThumbUrl . [X] [X] [X] . . . . * ThumbWidth . [X] [X] [X] . . . . * ThumbHeight . [X] [X] [X] . . . . ThumbImg . [X] [X] [X] . . . . ThumbLink . [X] [X] [X] . . . . * HostUrl . [X] [X] . . . . . * Copyright . [X] [X] . . . . . * Publisher . [X] [X] . . . . . * Restrictions . [X] [X] . . . . . * Type [X] [X] [X] . . . . . * Bytes . [X] [X] . . . . . * Channels . . [X] . . . . . * Seconds . . [X] . . . . . * Duration . . [X] . . . . . * Streaming . . [X] . . . . . * SourceName . . . [X] . . . . SourceNameAsHtml . . . [X] . . . . * SourceUrl . . . [X] . . . . * Language . . . [X] . . . . * PublishTime . . . [X] . . . . * PublishWhen . . . [X] . . . . * Address . . . . [X] . . . * City . . . . [X] . . . * State . . . . [X] . . . * Phone . . . . [X] . . . * Miles . . . . [X] . . . * Kilometers . . . . [X] . . . * Rating . . . . [X] . . . * MapUrl . . . . [X] . . . * BusinessUrl . . . . [X] . . . * BusinessClickUrl . . . . [X] . . . * AllMapUrl . . . . [X] . . . * Term . . . . . [X] [X] [X] TermAsHtml . . . . . [X] [X] [X] | | | | | | | | Doc | | | | | | | Image | | | | | | Video | | | | | News | | | | Local | | | Spell | | Related | Terms Those items marked with a '*' are also available via the C method =cut ' my @DOW = qw[x Sun Mon Tue Wed Thu Fri Sat]; my @MON = qw[x Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec]; ## helper function -- returns the given text cooked for html sub _cook_for_html($) { my $text = shift; #die join(',', caller) if not defined $text; $text =~ s/&/&/g; $text =~ s//>/g; return $text; } ## ## helper function -- given a key in a result object, a result object (the ## "self" from a method), and an indication of whether we want text or ## html, return the appropriate text or html. ## sub _text_or_html($@) { my $Key = shift; my $Result = shift; my $AsHtml = shift; #optional my $Text = $Result->{$Key}; if (not defined $Text) { return (); } elsif ($AsHtml) { return _cook_for_html($Text); } else { return $Text; } } ## ## helper function -- if passed one arg, it's a url, and simply return it. ## ## If passed multiple args, the 2nd is an attribute (e.g. "href", "src"), ## which causes the return of a string like ## href="$url" ## where we're sure the quoting of the url is safe. ## sub _url($@) { my $Url = shift; my $Attrib = shift; if (not $Url) { return (); } elsif (not $Attrib) { return $Url; } elsif (not $Url =~ m/\x22/) { return qq/$Attrib="$Url"/; } elsif (not $Url =~ m/\x27/) { return qq/$Attrib='$Url'/; } else { $Url =~ s/\x22/%22/g; # double qoute $Url =~ s/\x27/%27/g; # single quote return qq/$Attrib="$Url"/; } } ## ## Want to be able to dump a hash of most data, so note which items are ## available and interesting on a per-search-space basis. ## my @CommonItems = qw[Url ClickUrl Summary Title i I]; my %ItemsBySpace = ( Video => [@CommonItems, qw"Type Bytes HostUrl Copyright Publisher Restrictions Channels Seconds Duration Streaming Width Height ThumbUrl ThumbWidth ThumbHeight"], Image => [@CommonItems, qw"Type Bytes HostUrl Copyright Publisher Restrictions Width Height ThumbUrl ThumbWidth ThumbHeight"], Doc => [@CommonItems, qw"Type CacheUrl CacheSize ModTimestamp"], Local => [@CommonItems, qw"Address City State Phone Miles Kilometers Rating MapUrl AllMapUrl"], News => [@CommonItems, qw"SourceName SourceUrl Language ModTimestamp PublishTime ThumbUrl ThumbWidth ThumbHeight"], Spell => [@CommonItems, "Term"], Related => [@CommonItems, "Term"], Terms => [@CommonItems, "Term"], ); =head1 METHODS =over 4 =cut ############################################################################## =item $Result->Next([I]) Returns the next C object from among the list of result objects that are part of one C object. Returns nothing when called on the last result in a response, unless auto-continuation is turned on, in which case the next set is automatically fetched and the first C from that set's C is returned. An optional defined boolean argument turns auto-continuation on (true) or off (false). If the argument is not defined, or not provided, the value for the original request's C option (default off) is used. Note that using auto-continuation can be dangerous. See the docs for C in Yahoo::Search::Response. =cut sub Next { my $Result = shift; # self my $AutoContinue = shift; if ($Result->{_ResponseOrdinal} < $#{ $Result->{_Response}->{Result} }) { return $Result->{_Response}->{Result}->[$Result->{_ResponseOrdinal} + 1]; } else { if (not defined $AutoContinue) { $AutoContinue = $Result->{_Response}->{_Request}->{AutoContinue}; } if ($AutoContinue and my $NextResponse = $Result->{_Response}->NextSet) { return $NextResponse->NextResult(); } else { return () } } } ############################################################################## =item $Result->Prev The opposite of C. No auto-continuation feature. =cut ## does not auto-fetch when fetching result[-1] sub Prev { my $Result = shift; # self if ($Result->{_ResponseOrdinal} == 0) { return (); } else { return $Result->{_Response}->{Result}->[$Result->{_ResponseOrdinal} - 1]; } } ############################################################################## =item $Result->Response Returns the C object of which this C object is a part. =cut sub Response { my $Result = shift; # self return $Result->{_Response}; } ############################################################################## =item $Result->Request Returns the original C object from which this C object's C was derived. =cut ' sub Request { my $Result = shift; # self return $Result->{_Response}->{_Request}; } ############################################################################## =item $Result->SearchSpace Returns a string which indicates the search space of the original query that this result was part of. (That is, it returns C, C, C, C, or C