From 01dcdb6958f188e5aa30f44f06989e4f0cac8e41 Mon Sep 17 00:00:00 2001 From: Marius Gavrilescu Date: Thu, 24 Mar 2016 15:16:48 +0200 Subject: [PATCH] Support configuration via the environment --- lib/App/Statsbot.pm | 14 ++++++++++++++ statsbot | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/lib/App/Statsbot.pm b/lib/App/Statsbot.pm index 902f9d3..fcc7959 100644 --- a/lib/App/Statsbot.pm +++ b/lib/App/Statsbot.pm @@ -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