#!/usr/bin/perl # -*- cperl -*- use strict; use warnings; BEGIN { local $| = 1; print ".:NoPaste:. loading bunch of modules... "; } use Locale::TextDomain qw(pci-nopaste); use YAML (); use Getopt::Long; use Pod::Usage; use POE qw( Component::IRC::State Component::IRC::Plugin::Connector Component::IRC::Plugin::NoPaste ); use constant ALIAS => 'pci-nopaste'; BEGIN { print "done.\n"; } my %opts; GetOptions( 'help|h' => \$opts{help}, man => \$opts{man}, 'config|c=s' => \$opts{config}, ); $opts{man} and pod2usage(-verbose => 2); $opts{help} and pod2usage(-verbose => 1); if (not $opts{config}) { if (-f '/etc/pci-nopaste.yml') { $opts{config} = '/etc/pci-nopaste.yml'; } else { die __x( "{process}: option --config= is missing.\n", process => $0, ); } } my $config = YAML::LoadFile($opts{config}); my $irc = POE::Component::IRC::State->spawn; POE::Session->create( package_states => [ __PACKAGE__, [ qw(_start _signal_stop) ], ], ); $poe_kernel->run; exit 0; sub _start { $_[KERNEL]->alias_set(ALIAS); #foreach (qw[HUP INT QUIT ABRT TERM]) { # $_[KERNEL]->sig($_ => '_signal_stop'); # } $irc->plugin_add( Connector => POE::Component::IRC::Plugin::Connector->new()); $irc->plugin_add( NoPaste => POE::Component::IRC::Plugin::NoPaste->new($config)); } sub _signal_stop { $_[KERNEL]->sig_handled; print STDERR __"Shutdown time has arrived. Telling components to stop...\n"; $_[KERNEL]->alias_remove(ALIAS); $irc->yield('shutdown'); }