Checking in changes prior to tagging of version 0.40_04. Changelog diff is:
[gitmo/Mouse.git] / lib / Mouse / Role.pm
index 956ab99..be99409 100644 (file)
@@ -1,17 +1,31 @@
 package Mouse::Role;
-use strict;
-use warnings;
+use Mouse::Exporter; # enables strict and warnings
 
-use Exporter;
+our $VERSION = '0.40_04';
 
-use Carp 'confess';
-use Scalar::Util 'blessed';
+use Carp         qw(confess);
+use Scalar::Util qw(blessed);
 
-use Mouse::Util qw(load_class get_code_package not_supported);
+use Mouse::Util  qw(not_supported);
+use Mouse::Meta::Role;
 use Mouse ();
 
-our @ISA = qw(Exporter);
+Mouse::Exporter->setup_import_methods(
+    as_is => [qw(
+        extends with
+        has
+        before after around
+        override super
+        augment  inner
+
+        requires excludes
+    ),
+        \&Scalar::Util::blessed,
+        \&Carp::confess,
+    ],
+);
 
+# XXX: for backward compatibility
 our @EXPORT = qw(
     extends with
     has
@@ -24,10 +38,6 @@ our @EXPORT = qw(
     blessed confess
 );
 
-our %is_removable = map{ $_ => undef } @EXPORT;
-delete $is_removable{confess};
-delete $is_removable{blessed};
-
 sub before {
     my $meta = Mouse::Meta::Role->initialize(scalar caller);
 
@@ -101,45 +111,26 @@ sub excludes {
     not_supported;
 }
 
-sub import {
-    my $class = shift;
+sub init_meta{
+    shift;
+    my %args = @_;
 
-    strict->import;
-    warnings->import;
+    my $class = $args{for_class}
+        or Carp::confess("Cannot call init_meta without specifying a for_class");
 
-    my $caller = caller;
+    my $metaclass  = $args{metaclass}  || 'Mouse::Meta::Role';
 
-    # we should never export to main
-    if ($caller eq 'main') {
-        warn qq{$class does not export its sugar to the 'main' package.\n};
-        return;
-    }
+    my $meta = $metaclass->initialize($class);
 
-    Mouse::Meta::Role->initialize($caller)->add_method(meta => sub {
-        return Mouse::Meta::Role->initialize(ref($_[0]) || $_[0]);
+    $meta->add_method(meta => sub{
+        $metaclass->initialize(ref($_[0]) || $_[0]);
     });
 
-    Mouse::Role->export_to_level(1, @_);
-}
-
-sub unimport {
-    my $caller = caller;
+    # make a role type for each Mouse role
+    Mouse::Util::TypeConstraints::role_type($class)
+        unless Mouse::Util::TypeConstraints::find_type_constraint($class);
 
-    my $stash = do{
-        no strict 'refs';
-        \%{$caller . '::'}
-    };
-
-    for my $keyword (@EXPORT) {
-        my $code;
-        if(exists $is_removable{$keyword}
-            && ($code = $caller->can($keyword))
-            && get_code_package($code) eq __PACKAGE__){
-
-            delete $stash->{$keyword};
-        }
-    }
-    return;
+    return $meta;
 }
 
 1;
@@ -150,6 +141,10 @@ __END__
 
 Mouse::Role - The Mouse Role
 
+=head1 VERSION
+
+This document describes Mouse version 0.40_04
+
 =head1 SYNOPSIS
 
     package MyRole;