[Catalyst-commits] r8875 - in Catalyst-Runtime/5.80/trunk: . lib/Catalyst t t/lib

t0m at dev.catalyst.perl.org t0m at dev.catalyst.perl.org
Sun Dec 14 11:04:33 GMT 2008


Author: t0m
Date: 2008-12-14 11:04:33 +0000 (Sun, 14 Dec 2008)
New Revision: 8875

Added:
   Catalyst-Runtime/5.80/trunk/t/lib/NullPackage.pm
Modified:
   Catalyst-Runtime/5.80/trunk/Changes
   Catalyst-Runtime/5.80/trunk/TODO
   Catalyst-Runtime/5.80/trunk/lib/Catalyst/Utils.pm
   Catalyst-Runtime/5.80/trunk/t/unit_utils_load_class.t
Log:
Fix a 5.70/5.80 behavior change in Catalyst::Utils::ensure_class_loaded, pointed out by Bill Moseley

Modified: Catalyst-Runtime/5.80/trunk/Changes
===================================================================
--- Catalyst-Runtime/5.80/trunk/Changes	2008-12-14 10:54:32 UTC (rev 8874)
+++ Catalyst-Runtime/5.80/trunk/Changes	2008-12-14 11:04:33 UTC (rev 8875)
@@ -1,5 +1,8 @@
 # This file documents the revision history for Perl extension Catalyst.
 
+        - Fix loading of classes which do not define any symbols to not
+          die, as it didn't in 5.70 (t0m)
+          - Test for this (t0m)
         - Bump MooseX::Emulate::Class::Accessor::Fast dependency
           to force new version which fixes a lot of plugins (t0m)
         - Make log levels additive, and add documentation and tests

Modified: Catalyst-Runtime/5.80/trunk/TODO
===================================================================
--- Catalyst-Runtime/5.80/trunk/TODO	2008-12-14 10:54:32 UTC (rev 8874)
+++ Catalyst-Runtime/5.80/trunk/TODO	2008-12-14 11:04:33 UTC (rev 8875)
@@ -5,6 +5,9 @@
     http://code2.0beta.co.uk/moose/svnweb/index.cgi/moose/revision?rev=7036
     (groditi)
 
+  - Fix 'as soon as Class::MOP 0.67 + 1 is released 
+    Class::MOP::load_class($class) can be used instead' in Catalyst::Utils
+
   - Common engine test failures, look into and get tests into core.
 
   - Catalyst-Plugin-Authorization-ACL, Can't locate object method "tree" 

Modified: Catalyst-Runtime/5.80/trunk/lib/Catalyst/Utils.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/lib/Catalyst/Utils.pm	2008-12-14 10:54:32 UTC (rev 8874)
+++ Catalyst-Runtime/5.80/trunk/lib/Catalyst/Utils.pm	2008-12-14 11:04:33 UTC (rev 8875)
@@ -259,10 +259,13 @@
     croak "ensure_class_loaded should be given a classname, not a filename ($class)"
         if $class =~ m/\.pm$/;
 
+    # $opts->{ignore_loaded} can be set to true, and this causes the class to be required, even
+    # if it already has symbol table entries. This is to support things like Schema::Loader, which
+    # part-generate classes in memory, but then also load some of their contents from disk.
     return if !$opts->{ ignore_loaded }
         && Class::MOP::is_class_loaded($class); # if a symbol entry exists we don't load again
 
-    # as soon as Class::MOP 0.67 + 1 is released Class::MOP::load_class($class) can be used instead
+    # FIXME - as soon as Class::MOP 0.67 + 1 is released Class::MOP::load_class($class) can be used instead
 
     # this hack is so we don't overwrite $@ if the load did not generate an error
     my $error;
@@ -276,7 +279,7 @@
 
     die $error if $error;
 
-    die "require $class was successful but the package is not defined"
+    warn "require $class was successful but the package is not defined."
         unless Class::MOP::is_class_loaded($class);
 
     return 1;

Added: Catalyst-Runtime/5.80/trunk/t/lib/NullPackage.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/t/lib/NullPackage.pm	                        (rev 0)
+++ Catalyst-Runtime/5.80/trunk/t/lib/NullPackage.pm	2008-12-14 11:04:33 UTC (rev 8875)
@@ -0,0 +1,7 @@
+package NullPackage;
+# Do nothing class, there should be no code or symbols defined here..
+# Loading this works fine in 5.70, but a die was introduced in 5.80 which caused
+# it to fail. This has been changed to a warning to maintain back-compat.
+# See Catalyst::Utils::ensure_class_loaded() for more info.
+1;
+

Modified: Catalyst-Runtime/5.80/trunk/t/unit_utils_load_class.t
===================================================================
--- Catalyst-Runtime/5.80/trunk/t/unit_utils_load_class.t	2008-12-14 10:54:32 UTC (rev 8874)
+++ Catalyst-Runtime/5.80/trunk/t/unit_utils_load_class.t	2008-12-14 11:04:33 UTC (rev 8875)
@@ -3,7 +3,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 16;
+use Test::More tests => 18;
 use Class::MOP;
 
 use lib "t/lib";
@@ -66,3 +66,9 @@
 eval { Catalyst::Utils::ensure_class_loaded('Silly::File::Name.pm') };
 like($@, qr/Malformed class Name/, 'errored sanely when given a classname ending in .pm');
 
+undef $@;
+$warnings = 0;
+Catalyst::Utils::ensure_class_loaded("NullPackage");
+is( $warnings, 1, 'Loading a package which defines no symbols warns');
+is( $@, undef, '$@ still undef' );
+




More information about the Catalyst-commits mailing list