]> gitweb @ CieloNegro.org - pci-nopaste.git/blob - bin/pci-nopaste
migrate from GNU arch to Git
[pci-nopaste.git] / bin / pci-nopaste
1 #!/usr/bin/perl
2 # -*- cperl -*-
3 use strict;
4 use warnings;
5
6 BEGIN {
7     local $| = 1;
8     print ".:NoPaste:. loading bunch of modules... ";
9 }
10
11 use Locale::TextDomain qw(pci-nopaste);
12 use YAML ();
13 use Getopt::Long;
14 use Pod::Usage;
15 use POE qw(
16            Component::IRC::State
17            Component::IRC::Plugin::Connector
18            Component::IRC::Plugin::NoPaste
19           );
20 use constant ALIAS => 'pci-nopaste';
21
22 BEGIN {
23     print "done.\n";
24 }
25
26 my %opts;
27 GetOptions(
28     'help|h'     => \$opts{help},
29     man          => \$opts{man},
30     'config|c=s' => \$opts{config},
31    );
32
33 $opts{man} and
34   pod2usage(-verbose => 2);
35
36 $opts{help} and
37   pod2usage(-verbose => 1);
38
39 if (not $opts{config}) {
40     if (-f '/etc/pci-nopaste.yml') {
41         $opts{config} = '/etc/pci-nopaste.yml';
42     }
43     else {
44         die __x(
45             "{process}: option --config=<config-file> is missing.\n",
46             process => $0,
47            );
48     }
49 }
50
51 my $config = YAML::LoadFile($opts{config});
52 my $irc = POE::Component::IRC::State->spawn;
53
54 POE::Session->create(
55     package_states => [
56         __PACKAGE__, [ qw(_start _signal_stop) ],
57        ],
58    );
59
60 $poe_kernel->run;
61 exit 0;
62
63 sub _start {
64     $_[KERNEL]->alias_set(ALIAS);
65     #foreach (qw[HUP INT QUIT ABRT TERM]) {
66 #       $_[KERNEL]->sig($_ => '_signal_stop');
67 #    }
68     
69     $irc->plugin_add(
70         Connector => POE::Component::IRC::Plugin::Connector->new());
71
72     $irc->plugin_add(
73         NoPaste => POE::Component::IRC::Plugin::NoPaste->new($config));
74 }
75
76 sub _signal_stop {
77     $_[KERNEL]->sig_handled;
78
79     print STDERR __"Shutdown time has arrived. Telling components to stop...\n";
80     
81     $_[KERNEL]->alias_remove(ALIAS);
82     $irc->yield('shutdown');
83 }