use B ();
+
+# taken from Class/MOP.pm
+sub is_valid_class_name {
+ my $class = shift;
+
+ return 0 if ref($class);
+ return 0 unless defined($class);
+
+ return 1 if $class =~ /\A \w+ (?: :: \w+ )* \z/xms;
+
+ return 0;
+}
+
sub is_class_loaded {
my $class = shift;
sub get_code_info;
sub get_code_package;
-# taken from Class/MOP.pm
-sub is_valid_class_name {
- my $class = shift;
-
- return 0 if ref($class);
- return 0 unless defined($class);
-
- return 1 if $class =~ /\A \w+ (?: :: \w+ )* \z/xms;
-
- return 0;
-}
+sub is_valid_class_name;
# taken from Class/MOP.pm
sub load_first_existing_class {
#!/usr/bin/env perl
use strict;
use warnings;
-use Test::More tests => 11;
+use Test::More;
use Test::Exception;
require Mouse;
use lib 't/lib';
-ok(!Mouse::is_class_loaded(undef), "is_class_loaded with undef 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??");
+lives_and {
+ ok(!Mouse::is_class_loaded(undef), "is_class_loaded with undef 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");
+
+ ok(Mouse::is_class_loaded("Mouse"), "Mouse is loaded");
+ ok(Mouse::is_class_loaded("Test::More"), "Test::More is loaded");
+};
throws_ok { Mouse::load_class(undef) } 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+\)\)/;
+throws_ok { Mouse::load_class("Foo!") } qr/Invalid class name/;
+throws_ok { Mouse::load_class("Foo::Bar42!") } qr/Invalid class name/;
+
ok(Mouse::load_class('Unsweetened'));
can_ok('Unsweetened' => 'unsweetened');
Mouse::load_class('SyntaxError');
} qr/Missing right curly/;
+done_testing;
}
bool
+is_valid_class_name(SV* sv)
+CODE:
+{
+ SvGETMAGIC(sv);
+ if(SvPOKp(sv) && SvCUR(sv) > 0){
+ UV i;
+ RETVAL = TRUE;
+ for(i = 0; i < SvCUR(sv); i++){
+ char const c = SvPVX(sv)[i];
+ if(!(isALNUM(c) || c == ':')){
+ RETVAL = FALSE;
+ break;
+ }
+ }
+ }
+ else{
+ RETVAL = SvNIOKp(sv) ? TRUE : FALSE;
+ }
+}
+OUTPUT:
+ RETVAL
+
+bool
is_class_loaded(SV* sv)
void