| 1 | package Plagger::Plugin::Publish::Slmame; |
|---|
| 2 | use strict; |
|---|
| 3 | use warnings; |
|---|
| 4 | use base qw( Plagger::Plugin ); |
|---|
| 5 | |
|---|
| 6 | use Encode; |
|---|
| 7 | use WWW::Slmame; |
|---|
| 8 | use Time::HiRes qw(sleep); |
|---|
| 9 | |
|---|
| 10 | sub register { |
|---|
| 11 | my($self,$context) = @_; |
|---|
| 12 | $context->register_hook( |
|---|
| 13 | $self, |
|---|
| 14 | 'publish.entry' => \&publish_entry, |
|---|
| 15 | 'plugin.init' => \&initialize, |
|---|
| 16 | ); |
|---|
| 17 | } |
|---|
| 18 | |
|---|
| 19 | sub initialize { |
|---|
| 20 | my($self, $context, $args) = @_; |
|---|
| 21 | my %opt = ( |
|---|
| 22 | id => $self->conf->{id}, |
|---|
| 23 | pass => $self->conf->{pass}, |
|---|
| 24 | blog => $self->conf->{blog}, |
|---|
| 25 | ); |
|---|
| 26 | $self->{slmame} = WWW::Slmame->new(%opt); |
|---|
| 27 | } |
|---|
| 28 | |
|---|
| 29 | sub publish_entry { |
|---|
| 30 | my($self, $context, $args) = @_; |
|---|
| 31 | $context->log(info => "updating slmame blog"); |
|---|
| 32 | $self->{slmame}->blog_select(); |
|---|
| 33 | my $hashref = { |
|---|
| 34 | title => $args->{entry}->title, |
|---|
| 35 | message => $args->{entry}->message |
|---|
| 36 | }; |
|---|
| 37 | $self->{slmame}->update($hashref); |
|---|
| 38 | my $sleeping_time = $self->conf->{interval} || 10; |
|---|
| 39 | $context->log(info => "sleep $sleeping_time."); |
|---|
| 40 | sleep($sleeping_time); |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | 1; |
|---|
| 44 | __END__ |
|---|
| 45 | |
|---|
| 46 | =head1 NAME |
|---|
| 47 | |
|---|
| 48 | Plagger::Plugin::Publish::Slmame - Update your slmame blog with feeds. |
|---|
| 49 | |
|---|
| 50 | =head1 SYNOPSIS |
|---|
| 51 | |
|---|
| 52 | - module: Publish::Slmame |
|---|
| 53 | config: |
|---|
| 54 | id: Slmame id |
|---|
| 55 | pass: Slmame pass |
|---|
| 56 | blog: Slmame blog index |
|---|
| 57 | |
|---|
| 58 | =head1 DESCRIPTION |
|---|
| 59 | |
|---|
| 60 | This plugin sends feed entries summary to your Slmame blog. |
|---|
| 61 | |
|---|
| 62 | =head1 CONFIG |
|---|
| 63 | |
|---|
| 64 | =over 4 |
|---|
| 65 | |
|---|
| 66 | =item id |
|---|
| 67 | |
|---|
| 68 | Slmame blog id. Required. |
|---|
| 69 | |
|---|
| 70 | =item pass |
|---|
| 71 | |
|---|
| 72 | Slmame blog pass. Required. |
|---|
| 73 | |
|---|
| 74 | =item blog |
|---|
| 75 | |
|---|
| 76 | Slmame blog index. Required. |
|---|
| 77 | |
|---|
| 78 | =item interval |
|---|
| 79 | |
|---|
| 80 | =back |
|---|
| 81 | |
|---|
| 82 | =head1 AUTHOR |
|---|
| 83 | |
|---|
| 84 | Soshi Tamura C<< <st.hao.yayoi@gmail.com> >> |
|---|
| 85 | |
|---|
| 86 | =head1 SEE ALSO |
|---|
| 87 | |
|---|
| 88 | L<Plagger>, L<WWW::Slmame> |
|---|
| 89 | |
|---|
| 90 | =cut |
|---|