From: Dagfinn Ilmari Mannsåker Date: Sat, 14 Jul 2012 15:44:29 +0000 (+0100) Subject: throw an error when trying to extend a role X-Git-Tag: v0.091012~2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=88aaa04a223aea1e3ae8e10fa896c86b05f0013a;p=gitmo%2FMoo.git throw an error when trying to extend a role --- diff --git a/Changes b/Changes index 6c62557..c825859 100644 --- a/Changes +++ b/Changes @@ -1,4 +1,5 @@ - useful and detailed errors for default checker in attrib generation + - throw an error when trying to extend a role 0.091011 - 2012-06-27 - re-add #web-simple as development IRC diff --git a/lib/Moo.pm b/lib/Moo.pm index fe7bdae..1566c65 100644 --- a/lib/Moo.pm +++ b/lib/Moo.pm @@ -67,20 +67,26 @@ sub unimport { } sub _set_superclasses { - my $class = shift; - my $target = shift; - _load_module($_) for @_; - # Can't do *{...} = \@_ or 5.10.0's mro.pm stops seeing @ISA - @{*{_getglob("${target}::ISA")}{ARRAY}} = @_; - if (my $old = delete $Moo::MAKERS{$target}{constructor}) { - delete _getstash($target)->{new}; - Moo->_constructor_maker_for($target) - ->register_attribute_specs(%{$old->all_attribute_specs}); + my $class = shift; + my $target = shift; + for (@_) { + _load_module($_); + if ($INC{"Role/Tiny.pm"} && $Role::Tiny::INFO{$_}) { + require Carp; + Carp::croak("Can't extend role '$_'"); } - no warnings 'once'; # piss off. -- mst - $Moo::HandleMoose::MOUSE{$target} = [ - grep defined, map Mouse::Util::find_meta($_), @_ - ] if $INC{"Mouse.pm"}; + } + # Can't do *{...} = \@_ or 5.10.0's mro.pm stops seeing @ISA + @{*{_getglob("${target}::ISA")}{ARRAY}} = @_; + if (my $old = delete $Moo::MAKERS{$target}{constructor}) { + delete _getstash($target)->{new}; + Moo->_constructor_maker_for($target) + ->register_attribute_specs(%{$old->all_attribute_specs}); + } + no warnings 'once'; # piss off. -- mst + $Moo::HandleMoose::MOUSE{$target} = [ + grep defined, map Mouse::Util::find_meta($_), @_ + ] if $INC{"Mouse.pm"}; } sub _maybe_reset_handlemoose { diff --git a/t/extends-role.t b/t/extends-role.t new file mode 100644 index 0000000..1d6ef18 --- /dev/null +++ b/t/extends-role.t @@ -0,0 +1,15 @@ +use strictures 1; +use Test::More; +use Test::Fatal; + +{ + package MyRole; + use Moo::Role; +} +{ + package MyClass; + use Moo; + ::isnt ::exception { extends "MyRole"; }, undef, "Can't extend role"; +} + +done_testing;