line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WebService::TagTheNet; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
35902
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
47
|
|
4
|
1
|
|
|
1
|
|
6
|
use Carp qw/croak/; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
80
|
|
5
|
1
|
|
|
1
|
|
1129
|
use LWP::UserAgent; |
|
1
|
|
|
|
|
66676
|
|
|
1
|
|
|
|
|
31
|
|
6
|
1
|
|
|
1
|
|
423
|
use XML::XPath; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
11
|
|
|
|
|
|
|
my ($class, %args) = @_; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my $self = bless ({}, ref ($class) || $class); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
$self->{'_opts'} = { |
16
|
|
|
|
|
|
|
uri => 'http://tagthe.net/api/', |
17
|
|
|
|
|
|
|
agent => 'WebService::TagTheNet v.'.$VERSION, |
18
|
|
|
|
|
|
|
count => 10, |
19
|
|
|
|
|
|
|
%args |
20
|
|
|
|
|
|
|
}; |
21
|
|
|
|
|
|
|
$self->{'_lwp'} = LWP::UserAgent->new(agent => $self->{'_opts'}->{'agent'}); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
return $self; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub text { |
27
|
|
|
|
|
|
|
my ($self, $text) = @_; |
28
|
|
|
|
|
|
|
croak "No text found" unless($text); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
return $self->_post('text', $text); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub url { |
34
|
|
|
|
|
|
|
my ($self, $url) = @_; |
35
|
|
|
|
|
|
|
croak "No URL found" unless($url); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
return $self->_post('url', $url); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub _post { |
41
|
|
|
|
|
|
|
my ($self, $k, $v) = @_; |
42
|
|
|
|
|
|
|
my $status = $self->{'_lwp'}->post( |
43
|
|
|
|
|
|
|
$self->{'_opts'}->{'uri'}, |
44
|
|
|
|
|
|
|
{ $k => $v, count => $self->{'_opts'}->{'count'} } |
45
|
|
|
|
|
|
|
); |
46
|
|
|
|
|
|
|
croak ("Can't connect to ", $self->{'_opts'}->{'uri'},": ", |
47
|
|
|
|
|
|
|
$status->status_line) unless($status->is_success); |
48
|
|
|
|
|
|
|
return $self->_xml2hash($status->content); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub _xml2hash { |
52
|
|
|
|
|
|
|
my ($self, $xml) = @_; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
my %result = (); |
55
|
|
|
|
|
|
|
my $xp = XML::XPath->new(xml => $xml); |
56
|
|
|
|
|
|
|
my $nodeset = $xp->find('/memes/meme/dim'); |
57
|
|
|
|
|
|
|
foreach my $node ($nodeset->get_nodelist) { |
58
|
|
|
|
|
|
|
my $type = $node->getAttribute('type'); |
59
|
|
|
|
|
|
|
foreach my $child ($node->getChildNodes) { |
60
|
|
|
|
|
|
|
next unless(ref $child eq 'XML::XPath::Node::Element'); |
61
|
|
|
|
|
|
|
push @{$result{$type}}, $child->string_value; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
return \%result; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
#################### main pod documentation begin ################### |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head1 NAME |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
WebService::TagTheNet - Retrieve tags using the tagthe.net REST API |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head1 SYNOPSIS |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
use WebService::TagTheNet; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
my $ttn = WebService::TagTheNet->new(count => 5); |
77
|
|
|
|
|
|
|
my $result = $ttn->url('http://tagthe.net/'); |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
print "Tags: ", join ", ", @{$result->{'topic'}}; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 DESCRIPTION |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
C - Retrieve tags using the tagthe.net REST API |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head2 METHODS |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
The following methods can be used |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head3 new |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
C creates a new C object. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head4 options |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=over 5 |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=item uri |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
If for some obscure reason you do not want to use the default |
100
|
|
|
|
|
|
|
L URI, you can specify your own one here. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=item agent |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
The agent string used for L. Defaults to |
105
|
|
|
|
|
|
|
C<'WebService::TagTheNet v.'.$VERSION> |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=item count |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
Define the amount of topics/tags you'd like to receive. Defaults |
110
|
|
|
|
|
|
|
to 10. |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=back |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head3 text |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Accepts a scalar and will pass that on to tagthe.net for analysis. It |
117
|
|
|
|
|
|
|
returns a hashref with the results (or croaks if something goes wrong). |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head3 url |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Accepts an URL and will pass that on to tagthe.net for analysis. It |
122
|
|
|
|
|
|
|
returns a hashref with the results (or croaks if something goes wrong). |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head2 RETURN VALUES |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
The hash with API results may contain any of these fields: |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head3 text |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=over 5 |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=item language |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=item topic |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=item location |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=item person |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=back |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head3 url |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=over 5 |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=item title |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=item size |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=item content-type |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=item author |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=back |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
Please see L for more information. |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head1 SEE ALSO |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
L, L |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head1 BUGS |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
Please report any bugs to L. |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head1 AUTHOR |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
M. Blom, |
169
|
|
|
|
|
|
|
Eblom@cpan.orgE, |
170
|
|
|
|
|
|
|
L |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head1 COPYRIGHT |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
This program is free software; you can redistribute |
175
|
|
|
|
|
|
|
it and/or modify it under the same terms as Perl itself. |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
The full text of the license can be found in the |
178
|
|
|
|
|
|
|
LICENSE file included with this module. |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=cut |
181
|
|
|
|
|
|
|
#################### main pod documentation end ################### |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
1; |