butting with fortunes!

This commit is contained in:
shabble 2009-11-11 15:11:53 +00:00
parent 24ecdb163d
commit f11a159bce
1 changed files with 38 additions and 0 deletions

38
butt-fortune.pl Executable file
View File

@ -0,0 +1,38 @@
#!/usr/bin/env perl
use strict;
use warnings;
use POE;
use POE::Component::Server::TCP;
use Butts;
# search $PATH by default.
my $fortune = 'fortune';
# Start a TCP server. Client input will be logged to the console and
# echoed back to the client, one line at a time.
my $butter = Butts->new();
POE::Component::Server::TCP->new
(
Alias => "echo_server",
Port => $ARGV[0] // 1096,
ClientInput => sub {
$_[KERNEL]->yield('shutdown');
},
ClientConnected => sub {
my ($kernel, $session, $heap, $input) = @_[KERNEL, SESSION, HEAP, ARG0];
#print "Session ", $session->ID(), " got input: $input\n";
my @fortune = `$fortune`; # ick. But Fortune.pm is shit.
foreach my $line (@fortune) {
$heap->{client}->put($butter->buttify_string($line));
}
$kernel->yield("shutdown");
}
);
# Start the server.
$poe_kernel->run();
exit 0;