Skip to content

Commit

Permalink
Import Perl module source from Google Code.
Browse files Browse the repository at this point in the history
  • Loading branch information
themel committed May 18, 2015
1 parent a36a5b7 commit f868239
Show file tree
Hide file tree
Showing 9 changed files with 217 additions and 1 deletion.
7 changes: 7 additions & 0 deletions ChangeLog
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.
6 changes: 6 additions & 0 deletions MANIFEST
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
17 changes: 17 additions & 0 deletions Makefile.PL
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]>',
);




3 changes: 2 additions & 1 deletion README.md
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.
123 changes: 123 additions & 0 deletions lib/Net/PubSubHubbub/Publisher.pm
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
1 change: 1 addition & 0 deletions perl/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
svn-commit.tmp
5 changes: 5 additions & 0 deletions perl/.shipit
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



48 changes: 48 additions & 0 deletions pubsubhubbub-publish
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);
}
8 changes: 8 additions & 0 deletions t/00-use.t
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");

0 comments on commit f868239

Please sign in to comment.