File Coverage

blib/lib/WWW/Yahoo/KeywordExtractor.pm
Criterion Covered Total %
statement 21 27 77.7
branch 2 4 50.0
condition n/a
subroutine 6 6 100.0
pod 2 2 100.0
total 31 39 79.4


line stmt bran cond sub pod time code
1             package WWW::Yahoo::KeywordExtractor;
2              
3 1     1   1138 use strict;
  1         2  
  1         48  
4 1     1   7 use warnings;
  1         1  
  1         37  
5              
6 1     1   1371 use LWP::UserAgent;
  1         64253  
  1         48  
7              
8 1     1   13 use constant KEYWORD_API_URL => 'http://api.search.yahoo.com/ContentAnalysisService/V1/termExtraction';
  1         2  
  1         277  
9              
10             our $VERSION = '0.5';
11              
12             sub new {
13 1     1 1 1178 my ($class, %args) = @_;
14 1         6 my $self = bless {%args}, $class;
15 1         4 return $self;
16             }
17              
18             sub extract {
19 1     1 1 981 my ($self, $content) = @_;
20 1 50       8 if (! $content) { die 'No content specified'; }
  0         0  
21 1         8 my $ua = LWP::UserAgent->new();
22 1         12507 my $response = $ua->post(
23             KEYWORD_API_URL,
24             { 'appid' => 'WWWYahooKeywordExtractor',
25             'query' => 'null',
26             'context' => $content, }
27             );
28 1 50       378171 if (! $response->is_success()) {
29 1         3201 die "Error getting data!\n";
30             }
31 0           my $xml = $response->content();
32 0           my @results = ();
33 0           while ($xml =~ m!([^<]*)!g) {
34 0           push @results, $1;
35             }
36 0           return \@results;
37             }
38              
39             1;
40             __END__