Technorati/OutboundApiQuery.pm untested

filter: Statementstmt 0.0% 0 / 70 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 16 Podpod 0.0% 0 / 7 totaltotal 0.0% 0 / 110 CC 7 SCAR 15.7
CC
7
Cov
0%
new
12.0
url
6.0
execute
6.0
CRAP 4.8
1 package WebService::Technorati::OutboundApiQuery;
2 use strict;
3 use utf8;
4  
5 use WebService::Technorati::ApiQuery;
6 use WebService::Technorati::LinkQuerySubject;
7 use WebService::Technorati::BlogLink;
8 use WebService::Technorati::Exception;
9 use base 'WebService::Technorati::ApiQuery';
10  
11 BEGIN {
12 use vars qw ($VERSION $DEBUG);
13 $VERSION = 0.04;
14 $DEBUG = 0;
15 }
16  
17 use constant API_URI => '/cosmos';
18  
19 sub new {
20 my ($class, %params) = @_;
21 if (! exists $params{'key'}) {
22 WebService::Technorati::InstantiationException->throw(
23 "WebService::Technorati::OutboundApiQuery must be " .
24 "instantiated with at least 'key => theverylongkeystring'");
25 }
26 my $data = {};
27 if (! exists $params{'url'}) {
28 $data->{'needs_url'}++;
29 }
30 for my $k (keys %params) {
31 $data->{'args'}{$k} = $params{$k};
32 }
33 my $self = bless ($data, ref ($class) || $class);
34 return $self;
35 }
36  
37 sub url {
38 my $self = shift;
39 my $url = shift;
40 if ($url) {
41 $self->{'url'} = $url;
42 delete($self->{'needs_url'});
43 }
44 return $self->{'url'};
45 }
46  
47 sub execute {
48 my $self = shift;
49 my $apiUrl = $self->apiHostUrl() . API_URI;
50 if (exists $self->{'needs_url'}) {
51 WebService::Technorati::StateValidationException->throw(
52 "WebService::Technorati::AuthorinfoApiQuery must have a " .
53 "'url' attribute set prior to query execution");
54 }
55 $self->SUPER::execute($apiUrl,$self->{'args'});
56 }
57  
58 sub readResults {
59 my $self = shift;
60 my $result_xp = shift;
61 my $error = $result_xp->find('/tapi/document/result/error');
62 if ($error) {
63 WebService::Technorati::DataException->throw($error);
64 }
65 my $nodeset = $result_xp->find("/tapi/document/result");
66 my $node = $nodeset->shift;
67 my $blogSubject = WebService::Technorati::LinkQuerySubject->new_from_node($node);
68 $nodeset = $result_xp->find('/tapi/document/item');
69 my @links = ();
70 for my $node ($nodeset->get_nodelist) {
71 my $blogLink = WebService::Technorati::BlogLink->new_from_node($node);
72 push(@links, $blogLink);
73 }
74 $self->{'subject'} = $blogSubject;
75 $self->{'links'} = \@links;
76  
77 }
78  
79  
80 =head2 getLinkQuerySubject
81  
82 Usage : getLinkQuerySubject();
83 Purpose :
84 Returns : a scalar WebService::Technorati::LinkQuerySubject instance
85 Argument : none
86 Throws : none
87 Comments : the URL subject (blog or not) is returned with what
88 Technorati knows about it
89 See Also : WebService::Technorati
90  
91 =cut
92  
93 sub getLinkQuerySubject {
94 my $self = shift;
95 return $self->{'subject'};
96 }
97  
98  
99 =head2 getOutboundLinks
100  
101 Usage : getOutboundLinks();
102 Purpose :
103 Returns : an array of WebService::Technorati::BlogLink instances
104 Argument : none
105 Throws : none
106 Comments : the list of outbound links are returned with what Technorati knows
107 about them
108 See Also : WebService::Technorati
109  
110 =cut
111  
112  
113 sub getOutboundLinks {
114 my $self = shift;
115 return (wantarray) ? @{$self->{'links'}} : $self->{'links'};
116 }
117  
118 1;