line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::PubSubHubbub::Publisher; |
2
|
1
|
|
|
1
|
|
1080
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
48
|
|
3
|
1
|
|
|
1
|
|
1223
|
use LWP::UserAgent; |
|
1
|
|
|
|
|
70668
|
|
|
1
|
|
|
|
|
41
|
|
4
|
1
|
|
|
1
|
|
1312
|
use HTTP::Request::Common; |
|
1
|
|
|
|
|
2813
|
|
|
1
|
|
|
|
|
257
|
|
5
|
1
|
|
|
1
|
|
8
|
use Carp qw(croak); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
567
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 NAME |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
Net::PubSubHubbub::Publisher - client library to ping a PubSubHubbub hub |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 OVERVIEW |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my $pub = Net::PubSubHubbub::Publisher->new(hub => $hub); |
14
|
|
|
|
|
|
|
$pub->publish_update($atom_topic_url) or |
15
|
|
|
|
|
|
|
die "Ping failed: " . $pub->last_response->status_line; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=cut |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our $VERSION = "0.91"; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 CONSTRUCTOR |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=over 4 |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=item C(hub => $hub[, ua => $ua]) |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
Takes a required hub URL, and an optional L instance. |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=back |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=cut |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub new { |
34
|
0
|
|
|
0
|
1
|
|
my ($class, %opts) = @_; |
35
|
0
|
|
|
|
|
|
my $ua = delete $opts{ua}; |
36
|
0
|
|
|
|
|
|
my $hub = delete $opts{hub}; |
37
|
0
|
0
|
|
|
|
|
unless ($hub) { |
38
|
0
|
|
|
|
|
|
croak("Required option 'hub' not set."); |
39
|
|
|
|
|
|
|
} |
40
|
0
|
0
|
|
|
|
|
unless ($hub =~ m!^https?://!) { |
41
|
0
|
|
|
|
|
|
croak("Bogus hub URL of $hub"); |
42
|
|
|
|
|
|
|
} |
43
|
0
|
0
|
|
|
|
|
if (%opts) { |
44
|
0
|
|
|
|
|
|
die "Unknown options: " . join(", ", sort keys %opts); |
45
|
|
|
|
|
|
|
} |
46
|
0
|
0
|
|
|
|
|
unless ($ua) { |
47
|
0
|
|
|
|
|
|
$ua = LWP::UserAgent->new( |
48
|
|
|
|
|
|
|
keep_alive => 1, |
49
|
|
|
|
|
|
|
agent => "Net-PubSubHubbub-Publisher-perl/$VERSION", |
50
|
|
|
|
|
|
|
); |
51
|
|
|
|
|
|
|
} |
52
|
0
|
|
|
|
|
|
return bless { |
53
|
|
|
|
|
|
|
ua => $ua, |
54
|
|
|
|
|
|
|
hub => $hub, |
55
|
|
|
|
|
|
|
}, $class; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 METHODS |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=over 4 |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=item C($topic_url) |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=item C(@topic_urls) |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
Sends a ping that the provided Topic URL(s) has/have been updated. |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
Returns true on success. If false, see C to figure out |
69
|
|
|
|
|
|
|
why it failed. |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=cut |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub publish_update { |
74
|
0
|
|
|
0
|
1
|
|
my ($self, @urls) = @_; |
75
|
0
|
0
|
|
|
|
|
croak "No URL(s) provided" unless @urls; |
76
|
0
|
|
|
|
|
|
foreach my $url (@urls) { |
77
|
0
|
0
|
|
|
|
|
croak("Bogus URL: $url") unless $url =~ m!^https?://!; |
78
|
|
|
|
|
|
|
} |
79
|
0
|
|
|
|
|
|
my @args = ("hub.mode" => "publish"); |
80
|
0
|
|
|
|
|
|
push @args, map { ("hub.url" => $_) } @urls; |
|
0
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
my $req = POST $self->{hub}, \@args; |
82
|
0
|
|
|
|
|
|
my $res = $self->{last_res} = $self->{ua}->request($req); |
83
|
0
|
0
|
|
|
|
|
return 1 if $res->is_success; |
84
|
0
|
|
|
|
|
|
return 0; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=item C() |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Returns the last L. Use this when C |
90
|
|
|
|
|
|
|
fails to discover why it failed. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=cut |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub last_response { |
95
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
96
|
0
|
|
|
|
|
|
return $self->{last_res}; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
1; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=back |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
This module is Copyright (c) 2009 Brad Fitzpatrick. |
106
|
|
|
|
|
|
|
All rights reserved. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
You may distribute under the terms of either the GNU General Public |
109
|
|
|
|
|
|
|
License or the Artistic License, as specified in the Perl README file. |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head1 WARRANTY |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
This is free software. IT COMES WITHOUT WARRANTY OF ANY KIND. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 AUTHOR |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Brad Fitzpatrick |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head1 SEE ALSO |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
L -- PubSubHubbub home |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=cut |