Subject: | Error when using exporter with additional traits |
See attached test case. Moose currently tries to locate the trait in
Moose::Meta::1::Custom::Trait::MyClassTrait instead of
Moose::Meta::Class::Custom::Trait::MyClassTrait.
Subject: | exporter_traits_bug.t |
From 7612d9fbdfd9851f4f63764b21312d693c4c6bfc Mon Sep 17 00:00:00 2001
From: Maros Kollar <maros@k-1.com>
Date: Sat, 23 Jun 2012 08:55:52 +0200
Subject: [PATCH] Tests for possible M::Exporter bug
---
t/bugs/traits_with_exporter.t | 73 +++++++++++++++++++++++++++++++++++++++++
t/lib/MyExporterRole.pm | 27 +++++++++++++++
2 files changed, 100 insertions(+), 0 deletions(-)
create mode 100644 t/bugs/traits_with_exporter.t
create mode 100644 t/lib/MyExporterRole.pm
diff --git a/t/bugs/traits_with_exporter.t b/t/bugs/traits_with_exporter.t
new file mode 100644
index 0000000..11b31a6
--- /dev/null
+++ b/t/bugs/traits_with_exporter.t
@@ -0,0 +1,73 @@
+#!/usr/bin/perl
+
+use lib "t/lib";
+use strict;
+use warnings;
+
+use Test::More;
+
+{
+ package MyMetaRole;
+ use Moose::Role;
+
+ sub some_meta_class_method {
+ return "HEY"
+ }
+}
+
+{
+ package MyRole;
+ use Moose::Role;
+
+ # Does not work ?!?
+ around 'run' => sub {
+ my $orig = shift;
+ my $self = shift;
+
+ my $return = $self->$orig(@_);
+ $return .= 'ELY,DOKELY';
+ return $return;
+ };
+}
+
+{
+ 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';
+
+ sub run {
+ return "OK";
+ }
+}
+
+
+
+my $my_class = MyClass->new;
+
+isa_ok($my_class,'MyClass');
+
+# Check if role has been applied
+is($my_class->run(),'OKELY,DOKELY');
+
+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;
diff --git a/t/lib/MyExporterRole.pm b/t/lib/MyExporterRole.pm
new file mode 100644
index 0000000..93ee097
--- /dev/null
+++ b/t/lib/MyExporterRole.pm
@@ -0,0 +1,27 @@
+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'],
+ },
+ );
+
+ Moose::Util::apply_all_roles($args{for_class},'MyRole');
+
+ return $meta;
+}
+
+1;
\ No newline at end of file
--
1.7.7.4