| 1 |
package Plagger::Plugin::Notify::NetSend; |
|---|
| 2 |
use strict; |
|---|
| 3 |
use warnings; |
|---|
| 4 |
use base qw(Plagger::Plugin); |
|---|
| 5 |
|
|---|
| 6 |
use Encode; |
|---|
| 7 |
use Net::NetSend; |
|---|
| 8 |
|
|---|
| 9 |
sub register { |
|---|
| 10 |
my ($self, $context) = @_; |
|---|
| 11 |
$context->register_hook( |
|---|
| 12 |
$self, |
|---|
| 13 |
'publish.feed' => \&update, |
|---|
| 14 |
); |
|---|
| 15 |
} |
|---|
| 16 |
|
|---|
| 17 |
sub update { |
|---|
| 18 |
my ($self, $context, $args) = @_; |
|---|
| 19 |
my $target_netbios_name = $self->conf->{target_netbios_name}; |
|---|
| 20 |
$target_netbios_name ||= Net::NetSend::getNbName($self->conf->{target_ip}); |
|---|
| 21 |
unless ($target_netbios_name) { |
|---|
| 22 |
$context->log(error => "No netbios name found: $@"); |
|---|
| 23 |
return; |
|---|
| 24 |
} |
|---|
| 25 |
my $body = $self->templatize($context, $args->{feed}); |
|---|
| 26 |
my $success = Net::NetSend::sendMsg( |
|---|
| 27 |
$target_netbios_name, |
|---|
| 28 |
$self->conf->{source_netbios_name}, |
|---|
| 29 |
$self->conf->{target_ip}, |
|---|
| 30 |
encode('shift-jis', $body), |
|---|
| 31 |
); |
|---|
| 32 |
$context->log(error => "Error in delivery! \n$@") unless $success; |
|---|
| 33 |
} |
|---|
| 34 |
|
|---|
| 35 |
sub templatize { |
|---|
| 36 |
my ($self, $context, $feed) = @_; |
|---|
| 37 |
my $tt = $context->template(); |
|---|
| 38 |
$tt->process('net_send_notify.tt', { |
|---|
| 39 |
feed => $feed, |
|---|
| 40 |
}, \my $out) or $context->error($tt->error); |
|---|
| 41 |
$out; |
|---|
| 42 |
} |
|---|
| 43 |
|
|---|
| 44 |
1; |
|---|
| 45 |
__END__ |
|---|
| 46 |
|
|---|
| 47 |
=head1 NAME |
|---|
| 48 |
|
|---|
| 49 |
Plagger::Plugin::Notify::NetSend - Notify feed updates to Windows Messenger Service |
|---|
| 50 |
|
|---|
| 51 |
=head1 SYNOPSIS |
|---|
| 52 |
|
|---|
| 53 |
- module: Notify::NetSend |
|---|
| 54 |
config: |
|---|
| 55 |
target_netbios_name: client |
|---|
| 56 |
source_netbios_name: plagger |
|---|
| 57 |
target_ip: 192.168.0.1 |
|---|
| 58 |
|
|---|
| 59 |
=head1 DESCRIPTION |
|---|
| 60 |
|
|---|
| 61 |
This plugin notifies feed updates to Windows Messenger Service |
|---|
| 62 |
|
|---|
| 63 |
=head1 AUTHOR |
|---|
| 64 |
|
|---|
| 65 |
Jiro Nishiguchi |
|---|
| 66 |
|
|---|
| 67 |
=head1 SEE ALSO |
|---|
| 68 |
|
|---|
| 69 |
L<Plagger>, L<Net::NetSend> |
|---|
| 70 |
|
|---|
| 71 |
=cut |
|---|