⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 response.pm

📁 yahoo api,包括各版本的
💻 PM
📖 第 1 页 / 共 2 页
字号:
 ## WARNING:   DANGEROUS DANGEROUS DANGEROUS ## my $SearchEngine = Yahoo::Search->new(AutoContinue => 1); if (my $Response = $SearchEngine->Query(Doc => 'Britney')) {     while (my $Result = $Response->NextResult) {        printf "%d: %s\n", $Result->I, $Result->Url;     } }=item *By creating a query when Yahoo::Search had been loaded via: use Yahoo::Search AutoContinue => 1;as with this example: use Yahoo::Search AutoContinue => 1; ## ## WARNING:   DANGEROUS DANGEROUS DANGEROUS ## if (my $Response = Yahoo::Search->Query(Doc => 'Britney')) {     while (my $Result = $Response->NextResult) {         printf "%d: %s\n", $Result->I, $Result->Url;     } }=backAll these examples are dangerous because they loop through results,fetching more and more, until either all results that Yahoo! has for thequery at hand have been fetched, or the Yahoo! Search server access limitshave been reached and further access is denied. So, be sure to rate-limitthe accesses, or explicitly break out of the loop at some appropriatepoint.=cutsub NextResult{    my $Response = shift; #self;    if (@_ % 2 != 0) {        return Yahoo::Search::_carp_on_error("wrong number of args to NextResult");    }    my $AutoContinue = $Response->{_Request}->{AutoContinue};    ## isolate args we allow...    my %Args = @_;    if (exists $Args{AutoContinue}) {        $AutoContinue = delete $Args{AutoContinue};    }    ## anything left over is unexpected    if (%Args) {        my $list = join ', ', keys %Args;        return Yahoo::Search::_carp_on_error("unexpected args to NextResult: $list");    }    ##    ## Setup is done -- now the real thing.    ## If the next slot is filled, return the result sitting there.    ##    if ($Response->{_NextIterator} < @{$Response->{Result}})    {        return $Response->{Result}->[$Response->{_NextIterator}++];    }    ##    ## If we're auto-continuing and there is another response...    ##    if ($AutoContinue and my $next = $Response->NextResponse)    {        ## replace this $Response with the new one, _in_place_        ## (this destroys the old one)        %$Response = %$next;        ## and return the first result from it...        return $Response->NextResult;    }    ##    ## Oh well, reset the iterator and return nothing.    ##    $Response->{_NextIterator} = 0;    return ();}###########################################################################=item $Response->Reset()Rests the iterator so that the next C<NextResult> returns the first of theC<Response> object's C<Result> objects.=cut 'sub Reset{    my $Response = shift; #self;    $Response->{_NextIterator} = 0;}###########################################################################=item $Response->Request()Returns the C<Request> object from which this C<Response> object wasderived.=cutsub Request{    my $Response = shift; #self;    return $Response->{_Request};}###########################################################################=item $Response->NextRequest()Returns a C<Request> object which will fetch the subsequent set of results(e.g. if the current C<Response> object represents the first 10 queryresults, C<NextRequest()> returns a C<Request> object that represents aquery for the I<next> 10 results.)Returns nothing if there were no results in the current C<Response> object(thereby eliminating the possibility of there being a I<next> result set).On error, sets C<$@> and returns nothing.=cutsub NextRequest{    my $Response = shift; #self    if (not $Response->Count) {        ## No results last time, so can't expect any next time        return ();    }    if ($Response->FirstOrdinal + $Response->Count >= $Response->CountAvail)    {        ## we have them all, so no reason to get more        return ();    }    if ($Response->{_NoFurtherRequests}) {        ## no reason to get more        return ();    }    ## Make a copy of the request    my %Request = %{$Response->{_Request}};    ## want that copy to be deep    $Request{Params} = { %{$Request{Params}} };    ## update the 'start' param    $Request{Params}->{start} += $Response->Count;    return Yahoo::Search::Request->new(%Request);}###########################################################################=item $Response->NextResponse()Like C<NextRequest>, but goes ahead and calls the C<Request> object'sC<Fetch> method to return the C<Result> object for the next set of results.=cut 'sub NextResponse{    my $Response = shift; #self    if (my $Request = $Response->NextRequest) {        return $Request->Fetch();    } else {        # $@ must already be set        return ();    }}###########################################################################=item $Response->Uri()Returns the C<URI::http> object that was fetched to create this response.It is the same as:  $Response->Request->Uri()=cutsub Uri{    my $Response = shift; #self;    return $Response->{_Request}->Uri;}###########################################################################=item $Response->Url()Returns the url that was fetched to create this response.It is the same as:  $Response->Request->Url()=cutsub Url{    my $Response = shift; #self;    return $Response->Request->Url;}###########################################################################=item $Response->RawXml()Returns a string holding the raw xml returned from the Yahoo! Searchservers.=cutsub RawXml{    my $Response = shift; #self;    return $Response->{_XML};}##############################################################################=item $Response->MapUrl()Valid only for a I<Local> search, returns a url to a map showing allresults. (This is the same as each C<Result> object's C<AllMapUrl> method.)=cutsub MapUrl{    my $Response = shift; #self;    return $Response->{ResultSetMapUrl};}##############################################################################=item $Response->RelatedRequest=item $Response->RelatedResponsePerform a I<Related> request for search terms related to the query phraseof the current request, returning the new C<Request> or C<Response> object,respectively.Both return nothing if the current request is already for a I<Related>search.For example:  print "Did you mean ", join(" or ", $Response->RelatedResponse->Terms()), "?";=cutsub RelatedRequest{    my $Response = shift;    return $Response->Request->RelatedRequest;}sub RelatedResponse{    my $Response = shift;    return $Response->Request->RelatedResponse;}##############################################################################=item $Response->SpellRequest=item $Response->SpellResponsePerform a I<Spell> request for a search term that may reflect properspelling of the query phrase of the current request, returning the newC<Request> or C<Response> object, respectively.Both return nothing if the current request is already for a I<Spell>search.=cutsub SpellRequest{    my $Response = shift;    return $Response->Request->SpellRequest;}sub SpellResponse{    my $Response = shift;    return $Response->Request->SpellResponse;}##############################################################################=pod=back=head1 CopyrightCopyright Yahoo! Inc=head1 AuthorJeffrey Friedl (jfriedl@yahoo.com)=cut1;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -