[Catalyst] setup_home() bug

Adam Herzog adam at herzogdesigns.com
Sun Jul 8 20:01:55 GMT 2007


I think I stumbled across a silly bug in setup_home(), when trying to  
set the home directory via an ENV var for an application named  
something like 'MyApp::Web' instead of just 'MyApp'. It would look  
for the existence of MYAPP::WEB_HOME, but then try to set the home  
directory from MYAPP_WEB_HOME. The patch changes it to always look  
for and use MYAPP_WEB_HOME.

Here's the output from an svn diff, against trunk. It's a very minor  
change, but I know patches have a better chance of being applied if  
they include tests so I included a test file, as well. :) I didn't  
see any existing tests for setup_home, so I created a new unit_core  
file... let me know if I should have put the tests somewhere else  
better.

Thanks,
-A

Index: t/unit_core_setup_home.t
===================================================================
--- t/unit_core_setup_home.t    (revision 0)
+++ t/unit_core_setup_home.t    (revision 0)
@@ -0,0 +1,31 @@
+use strict;
+use warnings;
+
+use Test::More tests => 5;
+
+use_ok('Catalyst');
+
+####################################################################### 
#######
+$ENV{'MYAPP_HOME'} = '/some/directory/myapp';
+{
+
+    package MyApp;
+    use base qw/Catalyst/;
+}
+
+ok( MyApp->setup_home(), 'Called setup_home() successfully' );
+is( MyApp->config->{home},
+    '/some/directory/myapp', 'Got the right home directory' );
+
+####################################################################### 
#######
+$ENV{'MYAPP_WEB_HOME'} = '/some/directory/myapp_web';
+{
+
+    package MyApp::Web;
+    use base qw/Catalyst/;
+}
+
+ok( MyApp::Web->setup_home(), 'Called setup_home() successfully' );
+is( MyApp::Web->config->{home},
+    '/some/directory/myapp_web', 'Got the right home directory' );
+
Index: lib/Catalyst.pm
===================================================================
--- lib/Catalyst.pm     (revision 6518)
+++ lib/Catalyst.pm     (working copy)
@@ -2081,9 +2081,9 @@
          $home = $ENV{CATALYST_HOME};
      }
-    if ( $ENV{ uc($class) . '_HOME' } ) {
-        $class =~ s/::/_/g;
-        $home = $ENV{ uc($class) . '_HOME' };
+    my $class_env_home = Catalyst::Utils::class2env($class) . '_HOME';
+    if ( $ENV{$class_env_home} ) {
+        $home = $ENV{$class_env_home};
      }
      unless ($home) {




More information about the Catalyst mailing list