From 342e235b916696da4ef7982885cefe0f8b069adf Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Mon, 31 Aug 2020 12:37:15 +0100 Subject: 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. --- perllib/FixMyStreet.pm | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'perllib/FixMyStreet.pm') 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}; } ); -- cgit v1.2.3