+ - correctly apply modifiers with role composition
- 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
} keys %conflicts;
die $fail;
}
- delete $INFO{$to}{methods}; # reset since we're about to add methods
+
+ # the if guard here is essential since otherwise we accidentally create
+ # a $INFO for something that isn't a Role::Tiny (or Moo::Role) because
+ # autovivification hates us and wants us to die()
+ if ($INFO{$to}) {
+ delete $INFO{$to}{methods}; # reset since we're about to add methods
+ }
+
$me->apply_role_to_package($to, $_) for @roles;
$APPLIED_TO{$to}{join('|',@roles)} = 1;
}
}
BEGIN {
+ package ExtraRole;
+
+ use Role::Tiny;
+}
+
+BEGIN {
package MyClass;
sub foo { 'class foo' }
}
BEGIN {
+ package ExtraClass;
+
+ use Role::Tiny::With;
+
+ with qw(MyRole ExtraRole);
+
+ sub foo { 'class foo' }
+}
+
+BEGIN {
package BrokenRole;
use Role::Tiny;
is(try_apply_to('MyClass'), undef, 'role applies cleanly');
is(MyClass->foo, 'role foo class foo', 'method modifier');
+is(ExtraClass->foo, 'role foo class foo', 'method modifier with composition');
ok(exception {
my $new_class = Role::Tiny->create_class_with_roles('MyClass', 'BrokenRole');