10 Class::MOP::is_class_loaded()
11 } "is_class_loaded with no argument dies";
13 ok(!Class::MOP::is_class_loaded(''), "can't load the empty class");
14 ok(!Class::MOP::is_class_loaded(\"foo"), "can't load a class name reference??");
16 ok(!Class::MOP::_is_valid_class_name(undef), 'undef is not a valid class name');
17 ok(!Class::MOP::_is_valid_class_name(''), 'empty string is not a valid class name');
18 ok(!Class::MOP::_is_valid_class_name(\"foo"), 'a reference is not a valid class name');
19 ok(!Class::MOP::_is_valid_class_name('bogus name'), q{'bogus name' is not a valid class name});
20 ok(Class::MOP::_is_valid_class_name('Foo'), q{'Foo' is a valid class name});
21 ok(Class::MOP::_is_valid_class_name('Foo::Bar'), q{'Foo::Bar' is a valid class name});
22 ok(Class::MOP::_is_valid_class_name('Foo_::Bar2'), q{'Foo_::Bar2' is a valid class name});
23 throws_ok { Class::MOP::load_class('bogus name') } qr/Invalid class name \(bogus name\)/;
26 Class::MOP::load_class('__PACKAGE__')
27 } qr/__PACKAGE__\.pm.*\@INC/, 'errors sanely on __PACKAGE__.pm';
29 Class::MOP::load_class('BinaryTree');
30 can_ok('BinaryTree' => 'traverse');
40 eval { Class::MOP::load_class('Class') };
41 ok( ! $@, 'load_class does not die if the package is already defined' );
44 ok( !Class::MOP::does_metaclass_exist("Class"), "no metaclass for non MOP class" );
47 Class::MOP::load_class('FakeClassOhNo');
52 Class::MOP::load_class('SyntaxError');
54 qr/Missing right curly/;
57 delete $INC{'SyntaxError.pm'};
58 Class::MOP::load_first_existing_class(
59 'FakeClassOhNo', 'SyntaxError', 'Class'
62 qr/Missing right curly/,
63 'load_first_existing_class does not pass over an existing (bad) module';
66 Class::MOP::load_class('This::Does::Not::Exist');
68 qr{Can't locate This/Does/Not/Exist\.pm in \@INC},
69 'load_first_existing_class throws a familiar error for a single module';
73 use constant foo => "bar";
77 ok(Class::MOP::is_class_loaded("Other"), 'is_class_loaded(Other)');
79 "a class with just constants is still a class";
87 is(Class::MOP::load_first_existing_class("Lala", "Does::Not::Exist"), "Lala", 'load_first_existing_class 1/2 params ok, class name returned');
88 is(Class::MOP::load_first_existing_class("Does::Not::Exist", "Lala"), "Lala", 'load_first_existing_class 2/2 params ok, class name returned');
89 } 'load_classes works';
92 Class::MOP::load_first_existing_class("Does::Not::Exist", "Also::Does::Not::Exist")
93 } qr/Does::Not::Exist.*Also::Does::Not::Exist/s, 'Multiple non-existant classes cause exception';
97 TestClassLoaded::this_method_does_not_even_exist();
100 ok( ! Class::MOP::is_class_loaded('TestClassLoaded'),
101 'the mere mention of TestClassLoaded in the whatever sub does not make us think it has been loaded' );
105 require TestClassLoaded::Sub;
106 ok( ! Class::MOP::is_class_loaded('TestClassLoaded'),
107 'requiring TestClassLoaded::Sub does not make us think TestClassLoaded is loaded' );
111 require TestClassLoaded;
112 ok( Class::MOP::is_class_loaded('TestClassLoaded'),
113 'We see that TestClassLoaded is loaded after requiring it (it has methods but no $VERSION or @ISA)' );
117 require TestClassLoaded2;
118 ok( Class::MOP::is_class_loaded('TestClassLoaded2'),
119 'We see that TestClassLoaded2 is loaded after requiring it (it has a $VERSION but no methods or @ISA)' );
123 require TestClassLoaded3;
124 ok( Class::MOP::is_class_loaded('TestClassLoaded3'),
125 'We see that TestClassLoaded3 is loaded after requiring it (it has an @ISA but no methods or $VERSION)' );
134 ok( ! Class::MOP::is_class_loaded('Not::Loaded'),
135 'the mere existence of an @ISA for a package does not mean a class is loaded' );
144 ok( Class::MOP::is_class_loaded('Loaded::Ish'),
145 'an @ISA with members does mean a class is loaded' );
151 Class::MOP::load_class("MistypedPackageName")
152 } qr/empty/, 'throws for nonexistent package name with something in a sub-namespace';