+ - check for conflicts during role-to-object application (test from mmcleric)
- add an explicit return to all exported subs so people don't accidentally
rely on the return value
- store coderefs as well as their refaddrs to protect against crazy
require MRO::Compat;
}
+ my %conflicts = %{$me->_composite_info_for(@roles)->{conflicts}};
+ if (keys %conflicts) {
+ my $fail =
+ join "\n",
+ map {
+ "Method name conflict for '$_' between roles "
+ ."'".join(' and ', sort values %{$conflicts{$_}})."'"
+ .", cannot apply these simultaneously to an object."
+ } keys %conflicts;
+ die $fail;
+ }
+
my @composable = map $me->_composable_package_for($_), reverse @roles;
*{_getglob("${new_name}::ISA")} = [ @composable, $superclass ];
--- /dev/null
+use strictures 1;
+use Test::More;
+use Test::Fatal;
+
+{
+ package R1;
+ use Role::Tiny;
+
+ sub foo {}
+
+ $INC{"R1.pm"} = __FILE__;
+}
+
+{
+ package R2;
+ use Role::Tiny;
+
+ sub foo {}
+
+ $INC{"R2.pm"} = __FILE__;
+}
+
+{
+ package X;
+ sub new {
+ bless {} => shift
+ }
+}
+
+ok(exception { Role::Tiny->apply_roles_to_object(X->new, "R1", "R2") }, 'apply conflicting roles to object');
+
+done_testing;