diff options
| author | 2015-12-26 20:23:48 -0700 | |
|---|---|---|
| committer | 2015-12-26 20:23:48 -0700 | |
| commit | 2a85bdefca654241cc16939890236300516cfb0b (patch) | |
| tree | 2f036fd7eb5eec42633b73a14f0b0af629b86ea4 /lib | |
| parent | 786e5f91e16bc3a709ef06d0ffa1808bd92a6451 (diff) | |
Create a fifo, relay it into masterchan (awesome for git web hook, and for making dwfreed wonder how the bot is talking)
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/ASM/Fifo.pm | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/ASM/Fifo.pm b/lib/ASM/Fifo.pm new file mode 100644 index 0000000..1a480f8 --- /dev/null +++ b/lib/ASM/Fifo.pm @@ -0,0 +1,33 @@ +package ASM::Fifo; + +use warnings; +use strict; +use POSIX qw(mkfifo); +use Fcntl; + +sub new +{ + my $module = shift; + my @args = @_; + my $self = { + "irc" => $args[0], + "conn" => $args[1] + }; + mkfifo("fifo", 0777); + sysopen( my $fifo, "fifo", O_NONBLOCK ); + $self->{fifo} = $fifo; + bless($self); + $self->{irc}->addfh( $self->{fifo}, sub { $self->process(@_); }, 'r' ); + return $self; +} + +sub process +{ + my ($self, $fifo) = @_; + my $line = readline($fifo); + return unless defined($line); + chomp $line; + $self->{conn}->privmsg($::settings->{masterchan}, $line); +} + +1; |
