From: Graham Knop Date: Thu, 11 Jul 2013 01:04:29 +0000 (-0400) Subject: prevent importing Moo into a Role::Tiny X-Git-Tag: v1.003000~4 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c3736593bfd271c4b0dd741721ee86e8283c4da8;p=gitmo%2FMoo.git prevent importing Moo into a Role::Tiny --- diff --git a/lib/Moo.pm b/lib/Moo.pm index e49fc38..ac088b9 100644 --- a/lib/Moo.pm +++ b/lib/Moo.pm @@ -22,7 +22,7 @@ sub import { my $target = caller; my $class = shift; strictures->import; - if ($Moo::Role::INFO{$target} and $Moo::Role::INFO{$target}{is_role}) { + if ($Role::Tiny::INFO{$target} and $Role::Tiny::INFO{$target}{is_role}) { die "Cannot import Moo into a role"; } $MAKERS{$target} ||= {}; diff --git a/lib/Moo/Role.pm b/lib/Moo/Role.pm index 704ac3a..7b10f05 100644 --- a/lib/Moo/Role.pm +++ b/lib/Moo/Role.pm @@ -259,7 +259,7 @@ sub create_class_with_roles { die "${role} is not a Role::Tiny" unless $INFO{$role}; } - $Moo::MAKERS{$new_name} = {}; + $Moo::MAKERS{$new_name} = {is_class => 1}; $me->_handle_constructor($new_name, $_) for @roles; diff --git a/t/not-both.t b/t/not-both.t index b894b1f..bb7079a 100644 --- a/t/not-both.t +++ b/t/not-both.t @@ -4,14 +4,26 @@ use Test::More; # Compile-time exceptions, so need stringy eval; hence not Test::Fatal. { local $@; - ok not eval q { package XXX; use Moo; use Moo::Role; 1; }; - like $@, qr{Cannot import Moo::Role into a Moo class}; + ok !eval q { package ZZZ; use Role::Tiny; use Moo; 1; }, + "can't import Moo into a Role::Tiny role"; + like $@, qr{Cannot import Moo into a role}, + " ... with correct error message"; } { local $@; - ok not eval q { package YYY; use Moo::Role; use Moo; 1; }; - like $@, qr{Cannot import Moo into a role}; + ok !eval q { package XXX; use Moo; use Moo::Role; 1; }, + "can't import Moo::Role into a Moo class"; + like $@, qr{Cannot import Moo::Role into a Moo class}, + " ... with correct error message"; +} + +{ + local $@; + ok !eval q { package YYY; use Moo::Role; use Moo; 1; }, + "can't import Moo into a Moo role"; + like $@, qr{Cannot import Moo into a role}, + " ... with correct error message"; } done_testing;