From: Jesse Luehrs Date: Thu, 5 Jul 2012 17:09:06 +0000 (-0500) Subject: fix "use MyExporter -traits => ..." (RT77974) X-Git-Tag: 2.0800~33 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e2a758ad2cda3f25747bd9692a46c921cad45f34;p=gitmo%2FMoose.git fix "use MyExporter -traits => ..." (RT77974) --- diff --git a/lib/Moose/Exporter.pm b/lib/Moose/Exporter.pm index da46de8..961d172 100644 --- a/lib/Moose/Exporter.pm +++ b/lib/Moose/Exporter.pm @@ -642,10 +642,11 @@ sub _apply_meta_traits { my $meta = $meta_lookup->($class); - my $type = ( split /::/, ref $meta )[-1] - or Moose->throw_error( - 'Cannot determine metaclass type for trait application . Meta isa ' - . ref $meta ); + my $type = $meta->isa('Moose::Meta::Role') ? 'Trait' + : $meta->isa('Class::MOP::Class') ? 'Class' + : Moose->throw_error('Cannot determine metaclass type for ' + . 'trait application. Meta isa ' + . ref $meta); my @resolved_traits = map { ref $_ diff --git a/t/bugs/traits_with_exporter.t b/t/bugs/traits_with_exporter.t new file mode 100644 index 0000000..9b2007a --- /dev/null +++ b/t/bugs/traits_with_exporter.t @@ -0,0 +1,79 @@ +#!/usr/bin/perl + +use lib "t/lib"; +use strict; +use warnings; + +use Test::More; + +BEGIN { + package MyExporterRole; + + use Moose (); + use Moose::Exporter; + + Moose::Exporter->setup_import_methods( + also => 'Moose', + ); + + sub init_meta { + my ($class,%args) = @_; + + my $meta = Moose->init_meta( %args ); + + Moose::Util::MetaRole::apply_metaroles( + for => $meta, + class_metaroles => { + class => ['MyMetaRole'], + }, + ); + + return $meta; + } + + $INC{'MyExporterRole.pm'} = __FILE__; +} + +{ + package MyMetaRole; + use Moose::Role; + + sub some_meta_class_method { + return "HEY" + } +} + +{ + package MyTrait; + use Moose::Role; + + sub some_meta_class_method_defined_by_trait { + return "HO" + } + + { + package Moose::Meta::Class::Custom::Trait::MyClassTrait; + use strict; + use warnings; + sub register_implementation { return 'MyTrait' } + } +} + +{ + package MyClass; + use MyExporterRole -traits => 'MyClassTrait'; +} + + + +my $my_class = MyClass->new; + +isa_ok($my_class,'MyClass'); + +my $meta = $my_class->meta(); +# Check if MyMetaRole has been applied +ok($meta->can('some_meta_class_method'),'Meta class has some_meta_class_method'); +# Check if MyTrait has been applied +ok($meta->can('some_meta_class_method_defined_by_trait'),'Meta class has some_meta_class_method_defined_by_trait'); + +done_testing;