aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet.pm
diff options
context:
space:
mode:
authorChris Mytton <self@hecticjeff.net>2013-09-13 12:12:14 +0100
committerChris Mytton <self@hecticjeff.net>2013-09-13 12:12:14 +0100
commitb44f9edab53f59fb442e5ee4db28cb25408c652c (patch)
treee7cd62bd148a5332e1ec625dda6c3bc6b09ceb62 /perllib/FixMyStreet.pm
parent2099ac31a4410f2cf8e1c7d31dc35cdd9ac1e070 (diff)
parent94ac7786132a538a5742ba325eb7fe9eff89cfc9 (diff)
Merge branch 'master' into oxfordshire-usability-recommendations
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();