]> iEval git - app-statsbot.git/blobdiff - lib/App/Statsbot.pm
Support configuration via the environment
[app-statsbot.git] / lib / App / Statsbot.pm
index eaf71a381578d6b0192d8545afa32a3066e51bb1..fcc79594eefc2656742758b52de94af9b3957aa3 100644 (file)
@@ -31,6 +31,15 @@ our $SSL = '';
 our @CHANNELS;
 our $DB = '/var/lib/statsbot/db';
 
+{
+       my %cfg = (debug => \$DEBUG, tick => \$TICK, nickname => \$NICKNAME, server => \$SERVER, port => \$PORT, ssl => \$SSL, channels => \@CHANNELS, db => \$DB);
+       for my $var (keys %cfg) {
+               my $key = "STATSBOT_\U$var";
+               ${$cfg{$var}} = $ENV{$key} if exists $ENV{$key} && ref $cfg{$var} eq 'SCALAR';
+               @{$cfg{$var}} = split ' ', $ENV{$key} if exists $ENV{$key} && ref $cfg{$var} eq 'ARRAY';
+       }
+}
+
 my $dbh;
 my $insert;
 my $update;
@@ -95,6 +104,8 @@ sub bot_start{ ## no critic (RequireArgUnpacking)
        $_[KERNEL]->delay(tick => $TICK);
 
        $irc->plugin_add(CTCP => POE::Component::IRC::Plugin::CTCP->new(
+               version => "Statsbot/$VERSION",
+               source => 'https://metacpan.org/pod/App::Statsbot',
                userinfo => 'A bot which keeps logs and computes channel statistics',
                clientinfo => 'PING VERSION CLIENTINFO USERINFO SOURCE',
        ));
@@ -196,6 +207,11 @@ a channel. It is able to answer queries of the form "In the last <time
 interval>, how much time did <nick> spend in this channel?".
 
 It is configured via global variables in the App::Statsbot package.
+These variables are initialized from environment variables with names
+of the form STATSBOT_DEBUG, STATSBOT_TICK, etc. In the case of array
+variables, the environment variable is treated as a space separated
+list. Each configuration variable has a default value used when it is
+not set explicitly or via the environment.
 
 =over
 
This page took 0.02428 seconds and 4 git commands to generate.