ひさしぶりに Plagger。XML::Atom::Client を使って、AtomAPI で entry を post する。既にあるかと思ったのだけど、まだないよね? (中身は Publish::HatenaBookmark ほぼそのまんま)
しかしこれ、集めてきた entry を post しまくるわけだが…… SPAM blog 作成幇(ry
package Plagger::Plugin::Publish::AtomAPI; use strict; use warnings; use base qw (Plagger::Plugin); use Encode; use Time::HiRes qw(sleep); use XML::Atom::Client; use XML::Atom::Entry; our $VERSION = 0.01; sub register { my ($self, $context) = @_; $context->register_hook( $self, 'publish.init' => \&init_client, 'publish.entry.fixup' => \&post_entry, ); } sub init_client { my $self = shift; $self->{client} = XML::Atom::Client->new(); $self->{client}->username( $self->conf->{username} ); $self->{client}->password( $self->conf->{password} ); } sub post_entry { my ($self, $context, $args) = @_; my $atom_entry = XML::Atom::Entry->new(); $atom_entry->title ( Encode::encode('utf8', $args->{entry}->title) ); $atom_entry->content( Encode::encode('utf8', $args->{entry}->body) ); my $edit_uri = $self->{client}->createEntry( $self->conf->{post_uri}, $atom_entry, ); if($edit_uri){ $context->log( info => "post ok. edit_uri: $edit_uri" ); } else { $context->log( error => "post failed. ". $self->{client}->errstr ); } sleep( $self->conf->{interval} || 3 ); } 1; __END__ =head1 Plagger::Plugin::Publish::AtomAPI - Post entry to AtomAPI =head1 SYNOPSYS - module: Publish::AtomAPI config: post_uri: http://www.example.com/path/to/post username: foo password: bar interval: 1