Make Moose::Util::TypeConstraints use Moose::Exporter too.
[gitmo/Moose.git] / lib / Moose / Util / TypeConstraints.pm
index ee579e8..59fb475 100644 (file)
@@ -6,7 +6,7 @@ use warnings;
 
 use Carp         'confess';
 use Scalar::Util 'blessed';
-use Sub::Exporter;
+use Moose::Exporter;
 
 our $VERSION   = '0.56';
 our $AUTHORITY = 'cpan:STEVAN';
@@ -62,38 +62,17 @@ use Moose::Meta::TypeCoercion::Union;
 use Moose::Meta::TypeConstraint::Registry;
 use Moose::Util::TypeConstraints::OptimizedConstraints;
 
-my @exports = qw/
-    type subtype class_type role_type as where message optimize_as
-    coerce from via
-    enum
-    find_type_constraint
-    register_type_constraint
-/;
-
-Sub::Exporter::setup_exporter({
-    exports => \@exports,
-    groups  => { default => [':all'] }
-});
-
-sub unimport {
-    no strict 'refs';
-    my $class = caller();
-    # loop through the exports ...
-    foreach my $name (@exports) {
-        # if we find one ...
-        if (defined &{$class . '::' . $name}) {
-            my $keyword = \&{$class . '::' . $name};
-
-            # make sure it is from Moose
-            my ($pkg_name) = Class::MOP::get_code_info($keyword);
-            next if $@;
-            next if $pkg_name ne 'Moose::Util::TypeConstraints';
-
-            # and if it is from Moose then undef the slot
-            delete ${$class . '::'}{$name};
-        }
-    }
-}
+Moose::Exporter->build_import_methods(
+    as_is => [
+        qw(
+            type subtype class_type role_type as where message optimize_as
+            coerce from via
+            enum
+            find_type_constraint
+            register_type_constraint )
+    ],
+    _export_to_main => 1,
+);
 
 ## --------------------------------------------------------
 ## type registry and some useful functions for it