Fix has_method() for backward compatibility
[gitmo/Mouse.git] / lib / Mouse / Util.pm
index e86da70..254ddbc 100644 (file)
@@ -5,6 +5,7 @@ use warnings;
 use Exporter;
 
 use Carp qw(confess);
+use B ();
 
 use constant _MOUSE_VERBOSE => !!$ENV{MOUSE_VERBOSE};
 
@@ -22,6 +23,8 @@ our @EXPORT_OK = qw(
     get_linear_isa
     get_code_info
 
+    get_code_package
+
     not_supported
 
     does meta dump
@@ -99,8 +102,6 @@ BEGIN {
         my ($coderef) = @_;
         ref($coderef) or return;
 
-        require B;
-
         my $cv = B::svref_2object($coderef);
         $cv->isa('B::CV') or return;
 
@@ -109,6 +110,18 @@ BEGIN {
 
         return ($gv->STASH->NAME, $gv->NAME);
     }
+
+    sub get_code_package{
+        my($coderef) = @_;
+
+        my $cv = B::svref_2object($coderef);
+        $cv->isa('B::CV') or return '';
+
+        my $gv = $cv->GV;
+        $gv->isa('B::GV') or return '';
+
+        return $gv->STASH->NAME;
+    }
 }
 
 # taken from Mouse::Util (0.90)