]> iEval git - app-statsbot.git/blobdiff - lib/App/Statsbot.pm
Support configuration via the environment
[app-statsbot.git] / lib / App / Statsbot.pm
index 902f9d336668bd930d7ad6bc87d8e4ef57ae9033..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;
@@ -198,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.021992 seconds and 4 git commands to generate.