[Rt-commit] rt branch, 4.0/strict-config-options, created. rt-4.0.4-203-g90c42f9

Ruslan Zakirov ruz at bestpractical.com
Tue Jan 17 10:12:58 EST 2012


The branch, 4.0/strict-config-options has been created
        at  90c42f95786fecd8b688878c6b7b3b74fea2cba3 (commit)

- Log -----------------------------------------------------------------
commit 90c42f95786fecd8b688878c6b7b3b74fea2cba3
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Tue Jan 17 19:08:16 2012 +0400

    use Hash::Util::lock_keys to make sure we don't have typos
    
    It's a stab and not complete.
    
    The idea is to lock all hashes related to config during testing
    to avoid typos when we access config.
    
    Primary config defines all defaults and thus sets all possible
    hash keys, so we can lock hashes and all typos should result
    in exceptions.

diff --git a/lib/RT.pm b/lib/RT.pm
index cf4ad5f..8ae9bf0 100644
--- a/lib/RT.pm
+++ b/lib/RT.pm
@@ -150,6 +150,7 @@ sub Init {
     InitPlugins();
     RT::I18N->Init;
     RT->Config->PostLoadCheck;
+    RT->Config->LockConfig;
 
 }
 
diff --git a/lib/RT/Config.pm b/lib/RT/Config.pm
index e17ad37..09b0ef4 100644
--- a/lib/RT/Config.pm
+++ b/lib/RT/Config.pm
@@ -958,6 +958,15 @@ sub PostLoadCheck {
     }
 }
 
+sub LockConfig {
+    my $self = shift;
+    my $ref = shift || \%OPTIONS;
+
+    require Hash::Util;
+    Hash::Util::lock_ref_keys( $ref );
+    $self->LockConfig( $_ ) foreach grep ref($_) eq 'HASH', values %$ref;
+}
+
 =head2 Configs
 
 Returns list of config files found in local etc, plugins' etc

-----------------------------------------------------------------------


More information about the Rt-commit mailing list