From: Jesse Luehrs Date: Tue, 6 Jul 2010 06:19:39 +0000 (-0500) Subject: stop using ->meta in a last couple places, to allow it to be disabled X-Git-Tag: 1.15~37 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ed5446906441590cc1e5da57026b12b698fcfd6b;p=gitmo%2FMoose.git stop using ->meta in a last couple places, to allow it to be disabled just need to figure out how to get Moose::Exporter to let me pass that option around --- diff --git a/lib/Moose.pm b/lib/Moose.pm index 53f6f12..9492fe1 100644 --- a/lib/Moose.pm +++ b/lib/Moose.pm @@ -173,7 +173,7 @@ sub init_meta { } } } else { - # no metaclass, no 'meta' method + # no metaclass # now we check whether our ancestors have metaclass, and if so borrow that my ( undef, @isa ) = @{ mro::get_linear_isa($class) }; @@ -198,23 +198,6 @@ sub init_meta { $meta = $metaclass->initialize($class); } - if ( $class->can('meta') ) { - # check 'meta' method - - # it may be inherited - - # NOTE: - # this is the case where the metaclass pragma - # was used before the 'use Moose' statement to - # override a specific class - my $method_meta = $class->meta; - - ( blessed($method_meta) && $method_meta->isa('Moose::Meta::Class') ) - || Moose->throw_error("$class already has a &meta function, but it does not return a Moose::Meta::Class ($method_meta)"); - - $meta = $method_meta; - } - unless ( $meta->has_method("meta") ) { # don't overwrite # also check for inherited non moose 'meta' method? # FIXME also skip this if the user requested by passing an option diff --git a/lib/Moose/Role.pm b/lib/Moose/Role.pm index c473438..bdb1769 100644 --- a/lib/Moose/Role.pm +++ b/lib/Moose/Role.pm @@ -112,22 +112,30 @@ sub init_meta { my $metaclass = $args{metaclass} || "Moose::Meta::Role"; - # make a subtype for each Moose class + Moose->throw_error("The Metaclass $metaclass must be a subclass of Moose::Meta::Role.") + unless $metaclass->isa('Moose::Meta::Role'); + + # make a subtype for each Moose role role_type $role unless find_type_constraint($role); - # FIXME copy from Moose.pm my $meta; - if ($role->can('meta')) { - $meta = $role->meta(); - - unless ( blessed($meta) && $meta->isa('Moose::Meta::Role') ) { - require Moose; - Moose->throw_error("You already have a &meta function, but it does not return a Moose::Meta::Role"); + if ( $meta = Class::MOP::get_metaclass_by_name($role) ) { + unless ( $meta->isa("Moose::Meta::Role") ) { + my $error_message = "$role already has a metaclass, but it does not inherit $metaclass ($meta)."; + if ( $meta->isa('Moose::Meta::Class') ) { + Moose->throw_error($error_message . ' You cannot make the same thing a role and a class. Remove either Moose or Moose::Role.'); + } else { + Moose->throw_error($error_message); + } } } else { $meta = $metaclass->initialize($role); + } + unless ( $meta->has_method("meta") ) { # don't overwrite + # also check for inherited non moose 'meta' method? + # FIXME also skip this if the user requested by passing an option $meta->add_method( 'meta' => sub { # re-initialize so it inherits properly diff --git a/lib/Test/Moose.pm b/lib/Test/Moose.pm index c7fbe62..decd1f3 100644 --- a/lib/Test/Moose.pm +++ b/lib/Test/Moose.pm @@ -76,7 +76,7 @@ sub with_immutable (&@) { my $block = shift; my $before = $Test->current_test; $block->(); - $_->meta->make_immutable for @_; + Class::MOP::class_of($_)->make_immutable for @_; $block->(); my $num_tests = $Test->current_test - $before; return all { $_ } ($Test->summary)[-$num_tests..-1];