Mouse::Util::does_role() respects $thing->does() method
[gitmo/Mouse.git] / lib / Mouse / Exporter.pm
index 98f7eca..9d538ba 100644 (file)
@@ -1,16 +1,16 @@
 package Mouse::Exporter;
 use strict;
 use warnings;
-
 use Carp ();
 
 my %SPEC;
 
 my $strict_bits;
-BEGIN{ $strict_bits = strict::bits(qw(subs refs vars)); }
-
 my $warnings_extra_bits;
-BEGIN{ $warnings_extra_bits = warnings::bits(FATAL => 'recursion') }
+BEGIN{
+    $strict_bits         = strict::bits(qw(subs refs vars));
+    $warnings_extra_bits = warnings::bits(FATAL => 'recursion');
+}
 
 # it must be "require", because Mouse::Util depends on Mouse::Exporter,
 # which depends on Mouse::Util::import()
@@ -114,7 +114,7 @@ sub build_import_methods{
     $args{EXPORTS}    = \%exports;
     $args{REMOVABLES} = \@removables;
 
-    $args{groups}{all}     ||= \@all;
+    $args{groups}{all} ||= \@all;
 
     if(my $default_list = $args{groups}{default}){
         my %default;
@@ -136,7 +136,6 @@ sub build_import_methods{
     return (\&do_import, \&do_unimport);
 }
 
-
 # the entity of general import()
 sub do_import {
     my($package, @args) = @_;
@@ -169,7 +168,8 @@ sub do_import {
         }
     }
 
-    $^H              |= $strict_bits;                                 # strict->import;
+    # strict->import;
+    $^H              |= $strict_bits;
     # warnings->import('all', FATAL => 'recursion');
     ${^WARNING_BITS} |= $warnings::Bits{all};
     ${^WARNING_BITS} |= $warnings_extra_bits;
@@ -182,15 +182,15 @@ sub do_import {
 
         if(@traits){
             my $type = (split /::/, ref $meta)[-1]; # e.g. "Class" for "My::Meta::Class"
-            @traits =
-                map{
-                    ref($_) ? $_
-                            : Mouse::Util::resolve_metaclass_alias($type => $_, trait => 1)
-                } @traits;
+            @traits = map{
+              ref($_)
+                ? $_
+                : Mouse::Util::resolve_metaclass_alias($type => $_, trait => 1)
+            } @traits;
 
             require Mouse::Util::MetaRole;
             Mouse::Util::MetaRole::apply_metaroles(
-                for       => $into,
+                for => $into,
                 Mouse::Util::is_a_metarole($into->meta)
                     ? (role_metaroles  => { role  => \@traits })
                     : (class_metaroles => { class => \@traits }),
@@ -234,7 +234,9 @@ sub do_unimport {
     for my $keyword (@{ $spec->{REMOVABLES} }) {
         next if !exists $stash->{$keyword};
         my $gv = \$stash->{$keyword};
-        if(ref($gv) eq 'GLOB' && *{$gv}{CODE} == $spec->{EXPORTS}{$keyword}){ # make sure it is from us
+
+        # remove what is from us
+        if(ref($gv) eq 'GLOB' && *{$gv}{CODE} == $spec->{EXPORTS}{$keyword}){
             delete $stash->{$keyword};
         }
     }
@@ -256,8 +258,6 @@ sub _get_caller_package {
     }
 }
 
-#sub _spec{ %SPEC }
-
 1;
 __END__
 
@@ -267,7 +267,7 @@ Mouse::Exporter - make an import() and unimport() just like Mouse.pm
 
 =head1 VERSION
 
-This document describes Mouse version 0.68
+This document describes Mouse version 0.95
 
 =head1 SYNOPSIS
 
@@ -277,8 +277,8 @@ This document describes Mouse version 0.68
     use Mouse::Exporter;
 
     Mouse::Exporter->setup_import_methods(
-      as_is     => [ 'has_rw', 'other_sugar', \&Some::Random::thing ],
-      also      => 'Mouse',
+      as_is => [ 'has_rw', 'other_sugar', \&Some::Random::thing ],
+      also  => 'Mouse',
     );
 
     sub has_rw {