Sophie

Sophie

distrib > Mageia > 5 > i586 > media > core-release > by-pkgid > c09b898b0969c4dc333ec75f4c8f0f2f > files > 20

perl-POE-Component-Server-Syslog-1.200.0-5.mga5.noarch.rpm

#!/usr/bin/perl

use warnings;
use strict;

use POE;
use POE::Component::Server::Syslog;
use Data::Dumper;

POE::Session->create(
	inline_states => {
		_start => sub {
			$_[KERNEL]->sig($_, 'sig') for qw(INT HUP TERM);

			$_[HEAP]->{syslog} = POE::Component::Server::Syslog->spawn(
				Type     => 'udp',
				BindPort => 4095,
				InputState => \&client_input,
				ErrorState => \&client_error,
			);
		},
		
		_stop => sub {},

		sig => sub {
			$_[KERNEL]->call($_[HEAP]->{syslog}, 'shutdown');
			return;
		},
	},
);

POE::Kernel->run();

######################################

sub client_input {
    my $msg = $_[ARG0];
    print Dumper $msg;
}

sub client_error {
    warn "BAD MESSAGE: $_[ARG0]";
}