Hack for XSLoader
[gitmo/Mouse.git] / lib / Mouse / Util.pm
index a2593cf..949b654 100644 (file)
@@ -11,11 +11,17 @@ BEGIN{
 
     if(!$need_pp && !exists $INC{'Mouse/PurePerl.pm'}){
         local $@;
-        $need_pp = !eval{
+
+        # XXX: XSLoader tries to get the object path from caller's file name
+        #      $hack_mouse_file fools its mechanism
+
+        (my $hack_mouse_file = __FILE__) =~ s/.Util//; # .../Mouse/Util.pm -> .../Mouse.pm
+        print "$hack_mouse_file\n";
+        $need_pp = !eval sprintf("#line %d %s\n", __LINE__, $hack_mouse_file) . q{
             require XSLoader;
             XSLoader::load('Mouse', $VERSION);
         };
-        warn $@ if $@; # for DEBUGGING
+        #warn $@ if $@;
     }
 
     if($need_pp){
@@ -252,8 +258,7 @@ sub apply_all_roles {
         my $role_name = $roles[-1][0];
         load_class($role_name);
 
-        my $metarole = get_metaclass_by_name($role_name);
-        ( $metarole && $metarole->isa('Mouse::Meta::Role') )
+        Mouse::Util::TypeConstraints::_is_a_metarole( get_metaclass_by_name($role_name) )
             || $applicant->meta->throw_error("You can only consume roles, $role_name(".$role_name->meta.") is not a Mouse role");
     }