App-Pocosi
view release on metacpan or search on metacpan
lib/App/Pocosi.pm view on Meta::CPAN
package App::Pocosi;
BEGIN {
$App::Pocosi::AUTHORITY = 'cpan:HINRIK';
}
BEGIN {
$App::Pocosi::VERSION = '0.03';
}
use strict;
use warnings FATAL => 'all';
# we want instant child process reaping
sub POE::Kernel::USE_SIGCHLD () { return 1 }
use App::Pocosi::Status;
use Class::Load qw(try_load_class);
use Fcntl qw(O_CREAT O_EXCL O_WRONLY);
use File::Glob ':glob';
use File::Spec::Functions 'rel2abs';
use IO::Handle;
use IRC::Utils qw(decode_irc);
use Net::Netmask;
use POE;
use POSIX 'strftime';
use Scalar::Util 'looks_like_number';
sub new {
my ($package, %args) = @_;
return bless \%args, $package;
}
sub run {
my ($self) = @_;
# we print IRC output, which will be UTF-8
binmode $_, ':utf8' for (*STDOUT, *STDERR);
if ($self->{list_plugins}) {
require Module::Pluggable;
Module::Pluggable->import(
sub_name => '_available_plugins',
search_path => 'POE::Component::Server::IRC::Plugin',
);
for my $plugin (sort $self->_available_plugins()) {
$plugin =~ s/^POE::Component::Server::IRC::Plugin:://;
print $plugin, "\n";
}
return;
}
$self->_setup();
if ($self->{check_cfg}) {
print "The configuration is valid and all modules could be compiled.\n";
return;
}
if ($self->{daemonize}) {
require Proc::Daemon;
eval {
Proc::Daemon::Init->();
if (defined $self->{log_file}) {
open STDOUT, '>>:encoding(utf8)', $self->{log_file}
or die "Can't open $self->{log_file}: $!\n";
open STDERR, '>>&STDOUT' or die "Can't redirect STDERR: $!\n";
STDOUT->autoflush(1);
}
$poe_kernel->has_forked();
};
chomp $@;
die "Can't daemonize: $@\n" if $@;
}
if (defined $self->{pid_file}) {
sysopen my $fh, $self->{pid_file}, O_CREAT|O_EXCL|O_WRONLY
or die "Can't create pid file or it already exists. Pocosi already running?\n";
print $fh "$$\n";
close $fh;
}
POE::Session->create(
object_states => [
$self => [qw(
_start
sig_die
sig_int
sig_term
ircd_plugin_add
ircd_plugin_del
ircd_plugin_error
ircd_plugin_status
ircd_shutdown
)],
],
);
( run in 3.154 seconds using v1.01-cache-2.11-cpan-cdf2f3d4e48 )