aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet.pm
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2013-09-13 10:46:54 +0100
committerMatthew Somerville <matthew@mysociety.org>2013-09-13 10:46:54 +0100
commit94ac7786132a538a5742ba325eb7fe9eff89cfc9 (patch)
treea2d34378e69ba30dfe26118d947459ed739c67bc /perllib/FixMyStreet.pm
parentce1978dc64b37f9335b08abaf5db6665ac6377bb (diff)
Have a central config-override function.
You only need to pass in the values you wish to be different.
Diffstat (limited to 'perllib/FixMyStreet.pm')
-rw-r--r--perllib/FixMyStreet.pm36
1 files changed, 36 insertions, 0 deletions
diff --git a/perllib/FixMyStreet.pm b/perllib/FixMyStreet.pm
index be488a796..6c664f1d1 100644
--- a/perllib/FixMyStreet.pm
+++ b/perllib/FixMyStreet.pm
@@ -7,6 +7,7 @@ use Path::Class;
my $ROOT_DIR = file(__FILE__)->parent->parent->absolute->resolve;
use Readonly;
+use Sub::Override;
use mySociety::Config;
use mySociety::DBHandle;
@@ -85,6 +86,41 @@ sub config {
return exists $CONFIG{$key} ? $CONFIG{$key} : undef;
}
+sub override_config($&) {
+ my $config = shift;
+ my $code = \&{shift @_};
+
+ mySociety::MaPit::configure($config->{MAPIT_URL}) if $config->{MAPIT_URL};
+
+ # For historical reasons, we have two ways of askig for config variables.
+ # Override them both, I'm sure we'll find time to get rid of one eventually.
+ my $override_guard1 = Sub::Override->new(
+ "FixMyStreet::config",
+ sub {
+ my ($class, $key) = @_;
+ return $config->{$key} if exists $config->{$key};
+ my $orig_config = mySociety::Config::load_default();
+ return $orig_config->{$key} if exists $orig_config->{$key};
+ }
+ );
+ my $override_guard2 = Sub::Override->new(
+ "mySociety::Config::get",
+ sub ($;$) {
+ my ($key, $default) = @_;
+ return $config->{$key} if exists $config->{$key};
+ my $orig_config = mySociety::Config::load_default();
+ return $orig_config->{$key} if exists $orig_config->{$key};
+ return $default if @_ == 2;
+ }
+ );
+
+ $code->();
+
+ $override_guard1->restore();
+ $override_guard2->restore();
+ mySociety::MaPit::configure() if $config->{MAPIT_URL};;
+}
+
=head2 dbic_connect_info
$connect_info = FixMyStreet->dbic_connect_info();