aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStruan Donald <struan@exo.org.uk>2020-08-31 12:37:15 +0100
committerStruan Donald <struan@exo.org.uk>2020-09-10 10:53:41 +0100
commit342e235b916696da4ef7982885cefe0f8b069adf (patch)
tree78c487d4ea4f892a5d60b3148510a50ddf383aa1
parent5da5a6ee1f85df8946c795af82b6353a31eb1d97 (diff)
make override config use a readonly hash
The actual config uses a readonly hash so make the overridden config readonly too otherwise you end up with subtle bugs which tests don't catch.
-rw-r--r--perllib/FixMyStreet.pm7
1 files changed, 5 insertions, 2 deletions
diff --git a/perllib/FixMyStreet.pm b/perllib/FixMyStreet.pm
index 94ba7685f..5b8dda079 100644
--- a/perllib/FixMyStreet.pm
+++ b/perllib/FixMyStreet.pm
@@ -97,6 +97,9 @@ sub override_config($&) {
mySociety::MaPit::configure($config->{MAPIT_URL}) if $config->{MAPIT_URL};
+ use Readonly;
+ Readonly my %ro_config => %$config;
+
# NB: though we have this, templates tend to use [% c.config %].
# This overriding happens after $c->config is set, so note that
# FixMyStreet::App->setup_request rewrites $c->config if we are in
@@ -106,8 +109,8 @@ sub override_config($&) {
"FixMyStreet::config",
sub {
my ($class, $key) = @_;
- return { %CONFIG, %$config } unless $key;
- return $config->{$key} if exists $config->{$key};
+ return { %CONFIG, %ro_config } unless $key;
+ return $ro_config{$key} if exists $ro_config{$key};
return $CONFIG{$key} if exists $CONFIG{$key};
}
);