From e628c5975169afa639e9c9998489739e9609aa2c Mon Sep 17 00:00:00 2001 From: Marius Gavrilescu Date: Mon, 12 Aug 2013 16:03:46 +0300 Subject: [PATCH] Initial commit --- Changes | 5 ++ MANIFEST | 6 ++ Makefile.PL | 12 ++++ README | 30 ++++++++ lib/POE/Component/IRC/Plugin/Logger/Irssi.pm | 75 ++++++++++++++++++++ t/POE-Component-IRC-Plugin-Logger-Irssi.t | 23 ++++++ 6 files changed, 151 insertions(+) create mode 100644 Changes create mode 100644 MANIFEST create mode 100644 Makefile.PL create mode 100644 README create mode 100644 lib/POE/Component/IRC/Plugin/Logger/Irssi.pm create mode 100644 t/POE-Component-IRC-Plugin-Logger-Irssi.t diff --git a/Changes b/Changes new file mode 100644 index 0000000..7aea4b4 --- /dev/null +++ b/Changes @@ -0,0 +1,5 @@ +Revision history for Perl extension POE::Component::IRC::Plugin::Logger::Irssi. + +0.001 Mon 12 Aug 15:58:49 EEST 2013 + - Initial release + diff --git a/MANIFEST b/MANIFEST new file mode 100644 index 0000000..1f5624c --- /dev/null +++ b/MANIFEST @@ -0,0 +1,6 @@ +Changes +Makefile.PL +MANIFEST +README +t/POE-Component-IRC-Plugin-Logger-Irssi.t +lib/POE/Component/IRC/Plugin/Logger/Irssi.pm diff --git a/Makefile.PL b/Makefile.PL new file mode 100644 index 0000000..ed29709 --- /dev/null +++ b/Makefile.PL @@ -0,0 +1,12 @@ +use 5.014000; +use ExtUtils::MakeMaker; +# See lib/ExtUtils/MakeMaker.pm for details of how to influence +# the contents of the Makefile that is written. +WriteMakefile( + NAME => 'POE::Component::IRC::Plugin::Logger::Irssi', + VERSION_FROM => 'lib/POE/Component/IRC/Plugin/Logger/Irssi.pm', # finds $VERSION + PREREQ_PM => {}, # e.g., Module::Name => 1.1 + ($] >= 5.005 ? ## Add these new keywords supported since 5.005 + (ABSTRACT_FROM => 'lib/POE/Component/IRC/Plugin/Logger/Irssi.pm', # retrieve abstract from module + AUTHOR => 'Marius Gavrilescu ') : ()), +); diff --git a/README b/README new file mode 100644 index 0000000..88caad4 --- /dev/null +++ b/README @@ -0,0 +1,30 @@ +POE-Component-IRC-Plugin-Logger-Irssi version 0.001 +================================================== + +POE::Component::IRC::Plugin::Logger::Irssi is an extension to the +L PoCo-IRC plugin that logs +everything in a format similar to the one used by the irssi IRC client. + +It exports one function, B, that returns a hashref usable as +a value for Cnew>'s C argument. + +INSTALLATION + +To install this module type the following: + + perl Makefile.PL + make + make test + make install + +DEPENDENCIES + +This module requires no other modules or libraries. + +COPYRIGHT AND LICENCE + +Copyright (C) 2013 by Marius Gavrilescu + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself, either Perl version 5.14.2 or, +at your option, any later version of Perl 5 you may have available. diff --git a/lib/POE/Component/IRC/Plugin/Logger/Irssi.pm b/lib/POE/Component/IRC/Plugin/Logger/Irssi.pm new file mode 100644 index 0000000..67b5dd1 --- /dev/null +++ b/lib/POE/Component/IRC/Plugin/Logger/Irssi.pm @@ -0,0 +1,75 @@ +package POE::Component::IRC::Plugin::Logger::Irssi; + +our $VERSION = 0.001; + +use 5.014000; +use strict; +use warnings; + +use parent qw/Exporter/; + +our @EXPORT_OK = qw/irssi_format/; + +################################################## + +my %irssi_format = ( + nick_change => sub { "-!- $_[0] is now known as $_[1]" }, + topic_is => sub { "-!- Topic for $_[0]: $_[1]"}, + topic_change => sub { + my ($nick, $topic) = @_; + return "-!- $nick changed the topic to: $topic" if $topic; + return "-!- Topic unset by $nick" unless $topic; + }, + privmsg => sub{ "<$_[0]> $_[1]" }, + notice => sub { "-$_[0]- $_[1]" }, + action => sub { "* $_[0] $_[1]" }, + join => sub { "-!- $_[0] [$_[1]] has joined $_[2]" }, + part => sub { "-!- $_[0] [$_[1]] has left $_[2] [$_[3]]" }, + quit => sub { "-!- $_[0] [$_[1]] has quit [$_[2]]"}, + kick => sub { "-!- $_[1] was kicked from $_[2] by $_[0] [$_[3]]"}, + topic_set_by => sub { "-!- Topic set by $_[1] [". localtime($_[2]) .']' }, +); + +for my $letter ('a' .. 'z', 'A' .. 'Z') { + $irssi_format{"+$letter"} = sub { my $nick = shift; "-!- mode [+$letter @_] by $nick" }; + $irssi_format{"-$letter"} = sub { my $nick = shift; "-!- mode [-$letter @_] by $nick" } +} + +sub irssi_format { \%irssi_format } + +1; +__END__ + +=head1 NAME + +POE::Component::IRC::Plugin::Logger::Irssi - Log IRC events like irssi + +=head1 SYNOPSIS + + use POE::Component::IRC::Plugin::Logger::Irssi qw/irssi_format/; + ... + $irc->plugin_add(Logger => POE::Component::IRC::Plugin::Logger->new( + Format => irssi_format, + ... + )); + +=head1 DESCRIPTION + +POE::Component::IRC::Plugin::Logger::Irssi is an extension to the L PoCo-IRC plugin that logs everything in a format similar to the one used by the irssi IRC client. + +It exports one function, B, that returns a hashref to be used as the value to C<< POE::Component::IRC::Plugin::Logger->new >>'s C argument. + +=head1 AUTHOR + +Marius Gavrilescu C<< >> + +=head1 COPYRIGHT AND LICENSE + +Copyright (C) 2013 by Marius Gavrilescu + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself, either Perl version 5.14.2 or, +at your option, any later version of Perl 5 you may have available. + + +=cut diff --git a/t/POE-Component-IRC-Plugin-Logger-Irssi.t b/t/POE-Component-IRC-Plugin-Logger-Irssi.t new file mode 100644 index 0000000..0c1746c --- /dev/null +++ b/t/POE-Component-IRC-Plugin-Logger-Irssi.t @@ -0,0 +1,23 @@ +use v5.14; +use strict; +use warnings; + +use Test::More tests => 14; +BEGIN { use_ok('POE::Component::IRC::Plugin::Logger::Irssi', 'irssi_format') }; + +my $fmt = irssi_format; +my $localtime0 = localtime 0; +is $fmt->{'+b'}->('mgv', '*!root@*'), '-!- mode [+b *!root@*] by mgv', 'mode +b'; +is $fmt->{nick_change}->('mgv', 'arachnidsGrip'), '-!- mgv is now known as arachnidsGrip', 'change nick'; +is $fmt->{topic_is}->('#chan', 'wasting time'), '-!- Topic for #chan: wasting time', 'see topic'; +is $fmt->{topic_change}->('mgv', 'doing nothing'), '-!- mgv changed the topic to: doing nothing', 'set topic'; +is $fmt->{topic_change}->('mgv', ''), '-!- Topic unset by mgv', 'unset topic'; +is $fmt->{privmsg}->('mgv', 'Hello, world!'), ' Hello, world!', 'privmsg'; +is $fmt->{notice}->('mgv', 'Hello, world!'), '-mgv- Hello, world!', 'notice'; +is $fmt->{action}->('mgv', 'says hello'), '* mgv says hello', 'action'; +is $fmt->{join}->('mgv', 'marius@example.org', '#chan'), '-!- mgv [marius@example.org] has joined #chan', 'join'; +is $fmt->{part}->('mgv', 'marius@example.org', '#chan', 'bye'), '-!- mgv [marius@example.org] has left #chan [bye]', 'part'; +is $fmt->{quit}->('mgv', 'marius@example.org', 'buh-bye'), '-!- mgv [marius@example.org] has quit [buh-bye]', 'quit'; +is $fmt->{kick}->('mgv', 'troll', '#chan', 'trolling'), '-!- troll was kicked from #chan by mgv [trolling]', 'kick'; +is $fmt->{topic_set_by}->('#chan', 'mgv', 0), "-!- Topic set by mgv [$localtime0]"; + -- 2.39.2