From: Shawn M Moore Date: Tue, 10 Jun 2008 04:54:21 +0000 (+0000) Subject: Invalid class names should throw an exception X-Git-Tag: 0.04~44 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=9694b71b9fb63978f813900224f556ad62da729f;p=gitmo%2FMouse.git Invalid class names should throw an exception --- diff --git a/lib/Mouse.pm b/lib/Mouse.pm index 59ddd5c..58637af 100644 --- a/lib/Mouse.pm +++ b/lib/Mouse.pm @@ -83,7 +83,10 @@ do { sub load_class { my $class = shift; - return 0 if ref($class) || !defined($class) || !length($class); + if (ref($class) || !defined($class) || !length($class)) { + my $display = defined($class) ? $class : 'undef'; + confess "Invalid class name ($display)"; + } return 1 if is_class_loaded($class); diff --git a/t/020-load-class.t b/t/020-load-class.t index 479bc08..d115db7 100644 --- a/t/020-load-class.t +++ b/t/020-load-class.t @@ -7,12 +7,13 @@ use Test::Exception; require Mouse; use lib 't/lib'; -for my $method ('load_class', 'is_class_loaded') { - my $code = Mouse->can($method); - ok(!$code->(), "$method with no argument returns false"); - ok(!$code->(''), "can't load the empty class"); - ok(!$code->(\"foo"), "can't load a class name reference??"); -} +ok(!Mouse::is_class_loaded(), "is_class_loaded with no argument returns false"); +ok(!Mouse::is_class_loaded(''), "can't load the empty class"); +ok(!Mouse::is_class_loaded(\"foo"), "can't load a class name reference??"); + +throws_ok { Mouse::load_class() } qr/Invalid class name \(undef\)/; +throws_ok { Mouse::load_class('') } qr/Invalid class name \(\)/; +throws_ok { Mouse::load_class(\"foo") } qr/Invalid class name \(SCALAR\(\w+\)\)/; ok(Mouse::load_class('Anti::Mouse')); can_ok('Anti::Mouse' => 'antimouse');