Checking in changes prior to tagging of version 0.84.
[gitmo/Mouse.git] / lib / Mouse / Role.pm
index b3eb2cb..dfa08d9 100644 (file)
@@ -1,13 +1,11 @@
 package Mouse::Role;
 use Mouse::Exporter; # enables strict and warnings
 
-our $VERSION = '0.46';
+our $VERSION = '0.84';
 
 use Carp         qw(confess);
 use Scalar::Util qw(blessed);
 
-use Mouse::Util  qw(not_supported);
-use Mouse::Meta::Role;
 use Mouse ();
 
 Mouse::Exporter->setup_import_methods(
@@ -30,9 +28,8 @@ sub extends  {
     Carp::croak "Roles do not support 'extends'";
 }
 
-sub with     {
-    my $meta = Mouse::Meta::Role->initialize(scalar caller);
-    Mouse::Util::apply_all_roles($meta->name, @_);
+sub with {
+    Mouse::Util::apply_all_roles(scalar(caller), @_);
     return;
 }
 
@@ -43,43 +40,35 @@ sub has {
     $meta->throw_error(q{Usage: has 'name' => ( key => value, ... )})
         if @_ % 2; # odd number of arguments
 
-    if(ref $name){ # has [qw(foo bar)] => (...)
-        for (@{$name}){
-            $meta->add_attribute($_ => @_);
-        }
-    }
-    else{ # has foo => (...)
-        $meta->add_attribute($name => @_);
+    for my $n(ref($name) ? @{$name} : $name){
+        $meta->add_attribute($n => @_);
     }
     return;
 }
 
 sub before {
     my $meta = Mouse::Meta::Role->initialize(scalar caller);
-
     my $code = pop;
-    for (@_) {
-        $meta->add_before_method_modifier($_ => $code);
+    for my $name($meta->_collect_methods(@_)) {
+        $meta->add_before_method_modifier($name => $code);
     }
     return;
 }
 
 sub after {
     my $meta = Mouse::Meta::Role->initialize(scalar caller);
-
     my $code = pop;
-    for (@_) {
-        $meta->add_after_method_modifier($_ => $code);
+    for my $name($meta->_collect_methods(@_)) {
+        $meta->add_after_method_modifier($name => $code);
     }
     return;
 }
 
 sub around {
     my $meta = Mouse::Meta::Role->initialize(scalar caller);
-
     my $code = pop;
-    for (@_) {
-        $meta->add_around_method_modifier($_ => $code);
+    for my $name($meta->_collect_methods(@_)) {
+        $meta->add_around_method_modifier($name => $code);
     }
     return;
 }
@@ -113,7 +102,7 @@ sub requires {
 }
 
 sub excludes {
-    not_supported;
+    Mouse::Util::not_supported();
 }
 
 sub init_meta{
@@ -148,12 +137,34 @@ Mouse::Role - The Mouse Role
 
 =head1 VERSION
 
-This document describes Mouse version 0.46
+This document describes Mouse version 0.84
 
 =head1 SYNOPSIS
 
-    package MyRole;
-    use Mouse::Role;
+    package Comparable;
+    use Mouse::Role; # the package is now a Mouse role
+
+    # Declare methods that are required by this role
+    requires qw(compare);
+
+    # Define methods this role provides
+    sub equals {
+        my($self, $other) = @_;
+        return $self->compare($other) == 0;
+    }
+
+    # and later
+    package MyObject;
+    use Mouse;
+    with qw(Comparable); # Now MyObject can equals()
+
+    sub compare {
+        # ...
+    }
+
+    my $foo = MyObject->new();
+    my $bar = MyObject->new();
+    $obj->equals($bar); # yes, it is comparable
 
 =head1 KEYWORDS
 
@@ -161,15 +172,15 @@ This document describes Mouse version 0.46
 
 Returns this role's metaclass instance.
 
-=head2 C<< before (method|methods) -> CodeRef >>
+=head2 C<< before (method|methods|regexp) -> CodeRef >>
 
 Sets up a B<before> method modifier. See L<Moose/before>.
 
-=head2 C<< after (method|methods) => CodeRef >>
+=head2 C<< after (method|methods|regexp) => CodeRef >>
 
 Sets up an B<after> method modifier. See L<Moose/after>.
 
-=head2 C<< around (method|methods) => CodeRef >>
+=head2 C<< around (method|methods|regexp) => CodeRef >>
 
 Sets up an B<around> method modifier. See L<Moose/around>.