bump version to 0.63
[gitmo/Moose.git] / lib / Moose / Meta / Role / Composite.pm
index 6e15b31..291cbb2 100644 (file)
@@ -4,12 +4,10 @@ use strict;
 use warnings;
 use metaclass;
 
-use Carp            'confess';
-use Scalar::Util    'blessed', 'reftype';
+use Scalar::Util 'blessed';
 
-use Data::Dumper;
-
-our $VERSION   = '0.01';
+our $VERSION   = '0.63';
+$VERSION = eval $VERSION;
 our $AUTHORITY = 'cpan:STEVAN';
 
 use base 'Moose::Meta::Role';
@@ -36,29 +34,39 @@ sub new {
     my ($class, %params) = @_;
     # the roles param is required ...
     ($_->isa('Moose::Meta::Role'))
-        || confess "The list of roles must be instances of Moose::Meta::Role, not $_"
+        || Moose->throw_error("The list of roles must be instances of Moose::Meta::Role, not $_")
             foreach @{$params{roles}};
     # and the name is created from the
     # roles if one has not been provided
     $params{name} ||= (join "|" => map { $_->name } @{$params{roles}});
-    $class->meta->new_object(%params);
+    $class->_new(\%params);
 }
 
-# NOTE:
-# we need to override this cause 
-# we dont have that package I was
-# talking about above.
-# - SL
-sub alias_method {
+# This is largely a cope of what's in Moose::Meta::Role (itself
+# largely a copy of Class::MOP::Class). However, we can't actually
+# call add_package_symbol, because there's no package to which which
+# add the symbol.
+sub add_method {
     my ($self, $method_name, $method) = @_;
     (defined $method_name && $method_name)
-        || confess "You must define a method name";
-
-    my $body = (blessed($method) ? $method->body : $method);
-    ('CODE' eq (reftype($body) || ''))
-        || confess "Your code block must be a CODE reference";
-
-    $self->get_method_map->{$method_name} = $body;
+    || Moose->throw_error("You must define a method name");
+
+    my $body;
+    if (blessed($method)) {
+        $body = $method->body;
+        if ($method->package_name ne $self->name) {
+            $method = $method->clone(
+                package_name => $self->name,
+                name         => $method_name            
+            ) if $method->can('clone');
+        }
+    }
+    else {
+        $body = $method;
+        $method = $self->wrap_method_body( body => $body, name => $method_name );
+    }
+
+    $self->get_method_map->{$method_name} = $method;
 }
 
 1;
@@ -85,7 +93,7 @@ Moose::Meta::Role::Composite - An object to represent the set of roles
 
 =item B<get_method_map>
 
-=item B<alias_method>
+=item B<add_method>
 
 =back
 
@@ -101,11 +109,11 @@ Stevan Little E<lt>stevan@iinteractive.comE<gt>
 
 =head1 COPYRIGHT AND LICENSE
 
-Copyright 2006, 2007 by Infinity Interactive, Inc.
+Copyright 2006-2008 by Infinity Interactive, Inc.
 
 L<http://www.iinteractive.com>
 
 This library is free software; you can redistribute it and/or modify
 it under the same terms as Perl itself.
 
-=cut
\ No newline at end of file
+=cut