-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Import Perl module source from Google Code.
- Loading branch information
Showing
9 changed files
with
217 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
0.91: 2009-04-26 | ||
|
||
* Multi-topic support; better docs. | ||
|
||
0.90: 2009-04-26 | ||
|
||
* Initial release. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
ChangeLog | ||
pubsubhubbub-publish | ||
lib/Net/PubSubHubbub/Publisher.pm | ||
Makefile.PL | ||
MANIFEST This list of files | ||
t/00-use.t |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/usr/bin/perl | ||
use strict; | ||
use ExtUtils::MakeMaker; | ||
|
||
WriteMakefile( NAME => 'Net::PubSubHubbub::Publisher', | ||
VERSION_FROM => 'lib/Net/PubSubHubbub/Publisher.pm', | ||
EXE_FILES => [ 'pubsubhubbub-publish' ], | ||
PREREQ_PM => { | ||
'LWP::UserAgent' => 0, | ||
}, | ||
ABSTRACT_FROM => 'lib/Net/PubSubHubbub/Publisher.pm', | ||
AUTHOR => 'Brad Fitzpatrick <[email protected]>', | ||
); | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
# perl-publisher | ||
A perl module that implements the publishing ("pinging") part of the | ||
PubSubHubbub protocol. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
package Net::PubSubHubbub::Publisher; | ||
use strict; | ||
use LWP::UserAgent; | ||
use HTTP::Request::Common; | ||
use Carp qw(croak); | ||
|
||
=head1 NAME | ||
Net::PubSubHubbub::Publisher - client library to ping a PubSubHubbub hub | ||
=head1 OVERVIEW | ||
my $pub = Net::PubSubHubbub::Publisher->new(hub => $hub); | ||
$pub->publish_update($atom_topic_url) or | ||
die "Ping failed: " . $pub->last_response->status_line; | ||
=cut | ||
|
||
our $VERSION = "0.91"; | ||
|
||
=head1 CONSTRUCTOR | ||
=over 4 | ||
=item C<new>(hub => $hub[, ua => $ua]) | ||
Takes a required hub URL, and an optional L<LWP::UserAgent> instance. | ||
=back | ||
=cut | ||
|
||
sub new { | ||
my ($class, %opts) = @_; | ||
my $ua = delete $opts{ua}; | ||
my $hub = delete $opts{hub}; | ||
unless ($hub) { | ||
croak("Required option 'hub' not set."); | ||
} | ||
unless ($hub =~ m!^https?://!) { | ||
croak("Bogus hub URL of $hub"); | ||
} | ||
if (%opts) { | ||
die "Unknown options: " . join(", ", sort keys %opts); | ||
} | ||
unless ($ua) { | ||
$ua = LWP::UserAgent->new( | ||
keep_alive => 1, | ||
agent => "Net-PubSubHubbub-Publisher-perl/$VERSION", | ||
); | ||
} | ||
return bless { | ||
ua => $ua, | ||
hub => $hub, | ||
}, $class; | ||
} | ||
|
||
=head1 METHODS | ||
=over 4 | ||
=item C<publish_update>($topic_url) | ||
=item C<publish_update>(@topic_urls) | ||
Sends a ping that the provided Topic URL(s) has/have been updated. | ||
Returns true on success. If false, see C<last_response> to figure out | ||
why it failed. | ||
=cut | ||
|
||
sub publish_update { | ||
my ($self, @urls) = @_; | ||
croak "No URL(s) provided" unless @urls; | ||
foreach my $url (@urls) { | ||
croak("Bogus URL: $url") unless $url =~ m!^https?://!; | ||
} | ||
my @args = ("hub.mode" => "publish"); | ||
push @args, map { ("hub.url" => $_) } @urls; | ||
my $req = POST $self->{hub}, \@args; | ||
my $res = $self->{last_res} = $self->{ua}->request($req); | ||
return 1 if $res->is_success; | ||
return 0; | ||
} | ||
|
||
=item C<last_response>() | ||
Returns the last L<HTTP::Response>. Use this when C<publish_update> | ||
fails to discover why it failed. | ||
=cut | ||
|
||
sub last_response { | ||
my $self = shift; | ||
return $self->{last_res}; | ||
} | ||
|
||
1; | ||
|
||
=back | ||
=head1 COPYRIGHT & LICENSE | ||
This module is Copyright (c) 2009 Brad Fitzpatrick. | ||
All rights reserved. | ||
You may distribute under the terms of either the GNU General Public | ||
License or the Artistic License, as specified in the Perl README file. | ||
=head1 WARRANTY | ||
This is free software. IT COMES WITHOUT WARRANTY OF ANY KIND. | ||
=head1 AUTHOR | ||
Brad Fitzpatrick <[email protected]> | ||
=head1 SEE ALSO | ||
L<http://code.google.com/p/pubsubhubbub/> -- PubSubHubbub home | ||
=cut |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
svn-commit.tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
steps = FindVersion, ChangeVersion, CheckChangeLog, DistTest, Commit, Tag, MakeDist, UploadCPAN | ||
svn.tagpattern = Net-PubSubHubbub-Publisher-perl-%v | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/usr/bin/perl | ||
# -*-perl-*- | ||
|
||
use strict; | ||
use lib 'lib'; | ||
use Net::PubSubHubbub::Publisher; | ||
use Getopt::Long; | ||
use LWP::Simple (); | ||
|
||
sub usage { | ||
my $err = shift; | ||
if ($err) { | ||
warn "ERROR: $err\n\n"; | ||
} | ||
print STDERR <<END; | ||
Usage: pubsubhubbub-publish [OPTS] <topic_url> [<topic_url2> ...] | ||
Pings the hub, notifying the hub that the provided 'topic_url' has | ||
been updated. | ||
Options: | ||
--hub=<hub_publish_endpoint> Which hub endpoint to ping. Defaults | ||
to the open, reference hub, but you need to use whatever hub | ||
that your Topic URL references. | ||
END | ||
|
||
exit(1); | ||
} | ||
|
||
my $hub = "http://pubsubhubbub.appspot.com/"; | ||
GetOptions("hub=s" => \$hub) | ||
or usage(); | ||
|
||
my @topic_urls = @ARGV or usage("topic_url required."); | ||
foreach my $url (@topic_urls) { | ||
usage("Bogus topic URL: $url") | ||
unless $url =~ m!^https?://\S+$!; | ||
} | ||
|
||
usage("No hub provided.") | ||
unless $hub && $hub =~ m!^https?://\S+$!; | ||
|
||
my $publisher = Net::PubSubHubbub::Publisher->new(hub => $hub); | ||
unless ($publisher->publish_update(@topic_urls)) { | ||
warn "Error pinging hub: " . $publisher->last_response->status_line; | ||
exit(1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/usr/bin/perl | ||
# -*-perl -*- | ||
|
||
use strict; | ||
use Test::More tests => 1; | ||
|
||
use_ok("Net::PubSubHubbub::Publisher"); | ||
|