From: Shawn M Moore Date: Wed, 7 Jan 2009 15:40:00 +0000 (+0000) Subject: Use Class::MOP::get_meta($thing) instead of $thing->meta X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=bda8d00f25a096f52bfd1a1c8f319b67e0080739;p=gitmo%2FMoose.git Use Class::MOP::get_meta($thing) instead of $thing->meta --- diff --git a/lib/Moose.pm b/lib/Moose.pm index 62d1f43..b7e635d 100644 --- a/lib/Moose.pm +++ b/lib/Moose.pm @@ -49,11 +49,9 @@ sub extends { my @supers = @_; foreach my $super (@supers) { - Class::MOP::load_class($super); + my $meta = Class::MOP::load_class($super); croak "You cannot inherit from a Moose Role ($super)" - if $super->can('meta') && - blessed $super->meta && - $super->meta->isa('Moose::Meta::Role') + if $meta && $meta->isa('Moose::Meta::Role') } diff --git a/lib/Moose/Meta/Attribute.pm b/lib/Moose/Meta/Attribute.pm index abb3dec..3711f12 100644 --- a/lib/Moose/Meta/Attribute.pm +++ b/lib/Moose/Meta/Attribute.pm @@ -249,7 +249,7 @@ sub clone { } else { my ( @init, @non_init ); - foreach my $attr ( grep { $_->has_value($self) } $self->meta->compute_all_applicable_attributes ) { + foreach my $attr ( grep { $_->has_value($self) } Class::MOP::get_meta($self)->compute_all_applicable_attributes ) { push @{ $attr->has_init_arg ? \@init : \@non_init }, $attr; } @@ -651,13 +651,10 @@ sub _canonicalize_handles { Class::MOP::load_class($handles) unless Class::MOP::is_class_loaded($handles); - my $role_meta = eval { $handles->meta }; - if ($@) { - $self->throw_error("Unable to canonicalize the 'handles' option with $handles because : $@", data => $handles, error => $@); - } + my $role_meta = Class::MOP::get_meta($handles); (blessed $role_meta && $role_meta->isa('Moose::Meta::Role')) - || $self->throw_error("Unable to canonicalize the 'handles' option with $handles because ->meta is not a Moose::Meta::Role", data => $handles); + || $self->throw_error("Unable to canonicalize the 'handles' option with $handles because its metaclass is not a Moose::Meta::Role", data => $handles); return map { $_ => $_ } ( $role_meta->get_method_list, @@ -671,7 +668,8 @@ sub _find_delegate_metaclass { if (my $class = $self->_isa_metadata) { # if the class does have # a meta method, use it - return $class->meta if $class->can('meta'); + my $meta = Class::MOP::get_meta($class); + return $meta if $meta; # otherwise we might be # dealing with a non-Moose # class, and need to make @@ -681,7 +679,7 @@ sub _find_delegate_metaclass { elsif (my $role = $self->_does_metadata) { # our role will always have # a meta method - return $role->meta; + return Class::MOP::get_meta($role); } else { $self->throw_error("Cannot find delegate metaclass for attribute " . $self->name); diff --git a/lib/Moose/Meta/Role.pm b/lib/Moose/Meta/Role.pm index ed00b37..23b1526 100644 --- a/lib/Moose/Meta/Role.pm +++ b/lib/Moose/Meta/Role.pm @@ -321,19 +321,10 @@ sub get_method_map { $map->{$symbol}->body == $code; my ($pkg, $name) = Class::MOP::get_code_info($code); + my $meta = Class::MOP::get_meta($pkg); - if ($pkg->can('meta') - # NOTE: - # we don't know what ->meta we are calling - # here, so we need to be careful cause it - # just might blow up at us, or just complain - # loudly (in the case of Curses.pm) so we - # just be a little overly cautious here. - # - SL - && eval { no warnings; blessed($pkg->meta) } # FIXME calls meta - && $pkg->meta->isa('Moose::Meta::Role')) { - my $role = $pkg->meta->name; - next unless $self->does_role($role); + if ($meta && $meta->isa('Moose::Meta::Role')) { + next unless $self->does_role($meta->name); } else { # NOTE: @@ -462,7 +453,7 @@ sub combine { my (@roles, %role_params); while (@role_specs) { my ($role, $params) = @{ splice @role_specs, 0, 1 }; - push @roles => $role->meta; + push @roles => Class::MOP::get_meta($role); next unless defined $params; $role_params{$role} = $params; } diff --git a/lib/Moose/Meta/Role/Application/ToInstance.pm b/lib/Moose/Meta/Role/Application/ToInstance.pm index d2778b4..2639cf1 100644 --- a/lib/Moose/Meta/Role/Application/ToInstance.pm +++ b/lib/Moose/Meta/Role/Application/ToInstance.pm @@ -29,7 +29,7 @@ sub apply { $class = $ANON_CLASSES{$anon_role_key}; } else { - my $obj_meta = eval { $object->meta } || 'Moose::Meta::Class'; + my $obj_meta = Class::MOP::get_meta($object) || 'Moose::Meta::Class'; $class = $obj_meta->create_anon_class( superclasses => [ blessed($object) ] ); diff --git a/lib/Moose/Util/TypeConstraints.pm b/lib/Moose/Util/TypeConstraints.pm index d4b97d6..8ea7614 100644 --- a/lib/Moose/Util/TypeConstraints.pm +++ b/lib/Moose/Util/TypeConstraints.pm @@ -490,7 +490,7 @@ $_->make_immutable( # these are Class::MOP accessors, so they need inlining inline_accessors => 1 ) for grep { $_->is_mutable } - map { $_->meta } + map { Class::MOP::get_meta($_) } qw( Moose::Meta::TypeConstraint Moose::Meta::TypeConstraint::Union