sub load_class {
my $class = shift;
- if (ref($class) || !defined($class) || !length($class)) {
+ if ( ref($class)
+ || !defined($class)
+ || !length($class)
+ || $class !~ /^\w+(?::\w+)*$/ ) {
my $display = defined($class) ? $class : 'undef';
confess "Invalid class name ($display)";
}
#!/usr/bin/env perl
use strict;
use warnings;
-use Test::More tests => 14;
+use Test::More tests => 15;
use Test::Exception;
require Class::MOP;
throws_ok { Class::MOP::load_class() } qr/Invalid class name \(undef\)/;
throws_ok { Class::MOP::load_class('') } qr/Invalid class name \(\)/;
throws_ok { Class::MOP::load_class(\"foo") } qr/Invalid class name \(SCALAR\(\w+\)\)/;
+throws_ok { Class::MOP::load_class('bogus name') } qr/Invalid class name \(bogus name\)/;
my $meta = Class::MOP::load_class('BinaryTree');
ok($meta, "successfully loaded the class BinaryTree");
use constant foo => "bar";
}
-lives_ok { ok(Class::MOP::is_class_loaded("Other")) } "a class with just constants is still a class";
+lives_ok {
+ ok( Class::MOP::is_class_loaded("Other"), 'is_class_loaded(Other)' );
+}
+"a class with just constants is still a class";