📄 result.pm
字号:
} if (my $HREF = $Result->HostUrl('HREF')) { push @extra, "<a class=ySrcUrl $HREF>Source page</a>"; } if (@extra) { $html .= "<span class=yMeta><br>" . join(" | ", @extra) . "</span>"; } if ($summary) { $html .= "<span class=ySum><br>$summary</span>"; } return "<span class=yResult>$html</span>"; } if ($SearchSpace eq "News") { my $HREF = $Result->ClickUrl('HREF'); my $title = $Result->Title(1); my $html = "<span class=yResult>"; if (my $img = $Result->ThumbImg) { $html .= "<a class=yLink $HREF>$img<span class=yTitle> $title</span></a>"; } else { $html .= "<a class=yLink $HREF><span class=yTitle>$title</span></a>"; } my $src_name = $Result->SourceNameAsHtml; my $src_href = $Result->SourceUrl('HREF'); if ($src_name and $src_href) { $html .= "<a class=yNewsSrc $src_href><br>" . _cook_for_html($src_name) . "</a>"; } if (my $when = $Result->PublishWhen) { $html .= " <span class=yWhen>($when)</span>"; } if ($summary) { $html .= "<span class=ySum><br>$summary</span>"; } return "<span class=yResult>$html</span>"; } if ($SearchSpace eq "Local") { my $html = $Result->Link; if (my $addr = join(', ', grep { $_ } $Result->Address, $Result->City . " " . $Result->State)) { $html .= "<span class=yAddr><br>$addr</span>"; } my @extra; if (my $phone = $Result->Phone) { push @extra, "<span class=yPhone>$phone</span>"; } if (my $HREF = $Result->MapUrl('href')) { push @extra, "<a class=yMap $HREF>Map</a>"; } if (@extra) { $html .= "<span class=yMeta><br>" . join(" | ",@extra) . "</span>"; } if ($summary) { $html .= "<span class=ySum><br>$summary</span>"; } return "<span class=yResult>$html</span>"; } if ($SearchSpace eq "Spell") { my $item = $Result->TermAsHtml; return "Did you mean <i>$item</i>?"; } if ($SearchSpace eq "Related") { my $item = $Result->TermAsHtml; return "Also try: <i>$item</i>"; } if ($SearchSpace eq "Terms") { my $item = $Result->TermAsHtml; return "Term: <i>$item</i>"; } return "???";}##############################################################################=item $Result->as_stringReturns a textual representation of the C<Result>, which may be useful forquick prototyping or debugging.=cut## must create, for all spacessub as_string{ my $Result = shift; # self my $ref = $Result->Data; my $txt = ""; for my $item (@{$ItemsBySpace{$Result->SearchSpace}}) { if (defined(my $val = $Result->$item)) { $txt .= "$item: $val\n"; } } return $txt;}##############################################################################=item $Result->DataReturns a list of key/value pairs containing the fundamental data for theresult (those items marked with '*' in the table at the start of thisdocument). my %Data = $Result->Data;=cutsub Data{ my $Result = shift; # self my %Data; for my $item (@{$ItemsBySpace{$Result->SearchSpace}}) { $Data{$item} = $Result->$item; } return %Data;}##############################################################################=item $Result->Url=item $Result->ClickUrlC<Url> returns the raw url of the item (web page, image, etc.), appropriatefor display to the user.C<ClickUrl> returns a url appropriate for the href attribute of a link.In some cases, the two return the same url.As with all Result-object methods which return a url of some sort, you canprovide a single argument such as C<href> and receive a string such as href="..."appropriate to be used directly in html. For example, my $HREF = $Result->ClickUrl('href'); print "<a $HREF>click</a>";is preferable to my $url = $Result->ClickUrl; print "<a href='$url'>click</a>";since the latter would break if C<$url> contains a singlequote.=cutsub Url{ my $Result = shift; # self return _url($Result->{Url} || $Result->{ClickUrl}, @_);}sub ClickUrl{ my $Result = shift; # self return _url($Result->{ClickUrl} || $Result->{Url}, @_);}##############################################################################=item $Result->Title([ I<as_html> ])=item $Result->TitleAsHtmlC<Title> returns the raw title text associated with the result. If anoptional argument is provided and is true, the title text is returned ashtml.C<TitleAsHtml> is the same as $Result->Title(1)=cutsub Title{ return _text_or_html(Title => @_);}sub TitleAsHtml{ my $Result = shift; #self return $Result->Title(1);}##############################################################################=item $Result->LinkReturns a link made from the C<ClickUrl> and the C<Title>, with class"yLink", e.g. <a class=yLink href='$URL'>$TITLE</a>=cutsub Link{ my $Result = shift; # self if (my $HREF = $Result->ClickUrl('href') and my $title = $Result->Title(1)) { return "<a class=yLink $HREF>$title</a>"; } else { return (); }}##############################################################################=item $Result->Summary([ I<as_html> ])=item $Result->SummaryAsHtmlLike C<Title> and C<TitleAsHtml>, but for the summary associated with theresult.=cutsub Summary{ return _text_or_html(Summary => @_);}sub SummaryAsHtml{ my $Result = shift; #self return $Result->Summary(1);}=item $Result->CacheUrl=item $Result->CacheSize(I<Appropriate for B<Doc> search results>)C<CacheUrl> returns the url of the document in the Yahoo! cache.See the documentation for the C<Url> method for information on theone-argument version of this method.C<CacheSize> returns the size (as a string like "22k").=cutsub CacheUrl{ my $Result = shift; # self return _url($Result->{Cache} ? $Result->{Cache}->{Url} : (), @_)}sub CacheSize{ my $Result = shift; # self return $Result->{Cache} ? $Result->{Cache}->{Size} : ();}##############################################################################=item $Result->ModTimestamp(I<Appropriate for B<Doc> and B<News> search results>)The Unix timestamp of the Last-Modified time associated with the the urlwhen it was last checked by Yahoo!'s backend crawlers.=cutsub ModTimestamp{ my $Result = shift; # self return defined($Result->{ModificationDate}) ? $Result->{ModificationDate}: ();}##############################################################################=item $Result->Width=item $Result->Height(I<Appropriate for B<Image> and B<Video> search results>)The width and height (in pixels) of the image or video.=cut## for image, videosub Width{ my $Result = shift; # self return defined($Result->{Width}) ? $Result->{Width} : ();}sub Height{ my $Result = shift; # self return defined($Result->{Height}) ? $Result->{Height} : ();}##############################################################################=item $Result->ThumbUrl=item $Result->ThumbWidth=item $Result->ThumbHeight(I<Appropriate for B<Image>, B<Video>, and B<News> search results>)The url of a thumbnail image, and its width and height.(Note: few I<News> results have a thumbnail, but some do.)See the documentation for the C<Url> method for information on theone-argument version of C<ThumbUrl>.=cutsub ThumbUrl{ my $Result = shift; # self return _url($Result->{Thumbnail} ? $Result->{Thumbnail}->{Url} : (), @_);}sub ThumbWidth{ my $Result = shift; # self return $Result->{Thumbnail} ? $Result->{Thumbnail}->{Width} : ();}sub ThumbHeight{ my $Result = shift; # self return $Result->{Thumbnail} ? $Result->{Thumbnail}->{Height} : ();}##############################################################################=item $Result->ThumbImg(I<Appropriate for B<Image>, B<Video>, and B<News> search results>)Returns a C<E<lt>imgE<gt>> tag representing the thumbnail image, e.g. <img class=yImg src='$IMGURL' width=$WIDTH height=$HEIGHT>=cutsub ThumbImg{ my $Result = shift; # self my $SRC = $Result->ThumbUrl('src'); my $Width = $Result->ThumbWidth; my $Height = $Result->ThumbHeight; if ($SRC) { return "<img class=yImg $SRC width=$Width height=$Height>"; } else { return (); }}##############################################################################=item $Result->ThumbLink(I<Appropriate for B<Image>, B<Video>, and B<News> search results>)Returns a link from the thumbnail to the C<ClickUrl> of the result,e.g. <a class=yLink href='$CLICKURL'> <img class=yImg src='$IMGURL' width=$WIDTH height=$HEIGHT> </a>=cutsub ThumbLink{ my $Result = shift; # self my $HREF = $Result->ClickUrl('href'); my $img = $Result->ThumbImg; if ($HREF and $img) { return "<a class=yLink $HREF>$img</a>"; } else { return (); }}##############################################################################=item $Result->HostUrl(I<Appropriate for B<Image> and B<Video> search results>)Returns the url of the web page containing a link to the image/videoitem that the C<Result> represents.See the documentation for the C<Url> method for information on theone-argument version of this method.=cutsub HostUrl{ my $Result = shift; # self return _url($Result->{RefererUrl}, @_);}=cut###########################################################################=item $Result->Type(<Appropriate for B<Doc>, B<Image>, and B<Video> search results>)Returns a string representing the file type of the item to whichC<$Result-E<gt>Url> points. For I<Doc> searches, the MIME type (e.g."text/html") is returned.For other search spaces, here are the possible return values: Video: avi flash mpeg msmedia quicktime realmedia Image: bmp gif jpg png.Yahoo! Search derives these Video/Image C<Type> value by actuallyinspecting the file contents, and as such it is more reliable than lookingat the file extension.=cutsub Type{ my $Result = shift; #self if (defined $Result->{MimeType}) { return $Result->{MimeType}; } elsif (defined $Result->{FileFormat}) { return $Result->{FileFormat}; } else { return (); }}###########################################################################=item $Result->Copyright([ I<as_html> ])(<Appropriate for B<Image> and B<Video> search results>)Returns any copyright notice associated with the result. If an optionalargument is provided and is true, the copyright text is returned as html.=cutsub Copyright{ return _text_or_html(Copyright => @_);}###########################################################################=item $Result->Publisher([ I<as_html> ])(<Appropriate for B<Image>, and B<Video> search results>)Returns any publisher information (as a string) associated with the result.If an optional argument is provided and is true, the publisher information
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -