Changeset 2511

Show
Ignore:
Timestamp:
12/05/07 23:32:58 (5 years ago)
Author:
woremacx
Message:

lang/perl/WebService-YahooJP-TextParse?: wantarray of iterator

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/WebService-YahooJP-TextParse/trunk/lib/WebService/YahooJP/TextParse.pm

    r2497 r2511  
    4646 
    4747    $XML::Simple::PREFERRED_PARSER = 'XML::Parser'; 
    48     my $parser = XML::Simple->new; #(forcearray => 1); 
     48    my $parser = XML::Simple->new; 
    4949    $self->{result} = $parser->XMLin($res->content); 
    50     $self->{iter} = Array::Iterator::BiDirectional->new($self->{result}->{ma_result}->{word_list}->{word}); 
    51  
    52     $self->{iter}; 
     50    $self->{word} = $self->{result}->{ma_result}->{word_list}->{word}; 
     51    $self->{word} = [ $self->{word} ] if ref($self->{word}) and ref($self->{word}) eq 'HASH'; 
     52    return wantarray ? @{ $self->{word} } : Array::Iterator::BiDirectional->new($self->{word}); 
    5353} 
    5454 
     
    6464  use WebService::YahooJP::TextParse; 
    6565   
    66   my $ma = WebService::YahooJP::TextParse->new(%$config); # $config = { appid: "your-app-id" }; 
     66  my $config = { appid => "your-app-id" }; 
     67  my $ma = WebService::YahooJP::TextParse->new(%$config); 
    6768  my $text = "some japanese sentense"; 
    6869  my $iter = $ma->analysis($text);