die "No roles supplied!" unless @roles;
+ {
+ my %seen;
+ $seen{$_}++ for @roles;
+ if (my @dupes = grep $seen{$_} > 1, @roles) {
+ die "Duplicated roles: ".join(', ', @dupes);
+ }
+ }
+
my $new_name = join(
'__WITH__', $superclass, my $compose_name = join '__AND__', @roles
);
sub _union_info_for {
my ($me, @roles) = @_;
- $UNION_INFO{join('|',@roles)} ||= do {
+ $UNION_INFO{join('|', sort @roles)} ||= do {
_load_module($_) for @roles;
my %methods;
foreach my $role (@roles) {
use Test::More tests => 1;
BEGIN {
- use_ok( 'Role::Tiny::Restricted' ) || BAIL_OUT "Could not load Role::Tiny::Restricted: $!";
+ use_ok( 'Role::Tiny' ) || BAIL_OUT "Could not load Role::Tiny: $!";
}
-diag( "Testing Role::Tiny::Restricted $Role::Tiny::Restricted::VERSION, Perl $], $^X" );
+diag( "Testing Role::Tiny $Role::Tiny::VERSION, Perl $], $^X" );
# multiple roles with the same role
{
package RoleC;
- use Role::Tiny::Restricted;
+ use Role::Tiny;
sub baz { 'baz' }
package RoleB;
- use Role::Tiny::Restricted;
+ use Role::Tiny;
with 'RoleC';
sub bar { 'bar' }
package RoleA;
- use Role::Tiny::Restricted;
+ use Role::Tiny;
with 'RoleC';
sub foo { 'foo' }
package Foo;
use strict;
use warnings;
- use Role::Tiny::Restricted 'with';
+ use Role::Tiny 'with';
::is( ::exception {
with 'RoleA', 'RoleB';
}, undef, 'Composing multiple roles which use the same role should not have conflicts' );
local *UNIVERSAL::can = sub { 1 };
eval <<' END';
package Can::Can;
- use Role::Tiny::Restricted 'with';
+ use Role::Tiny 'with';
with 'A::NonExistent::Role';
END
my $error = $@ || '';
use lib 'lib', 't/role-basic/lib';
use MyTests;
-require Role::Tiny::Restricted;
+require Role::Tiny;
{
package My::Does::Basic1;
- use Role::Tiny::Restricted;
+ use Role::Tiny;
requires 'turbo_charger';
sub method {
{
package My::Does::Basic2;
- use Role::Tiny::Restricted;
+ use Role::Tiny;
requires 'turbo_charger';
sub method2 {
eval <<'END_PACKAGE';
package My::Class1;
-use Role::Tiny::Restricted 'with';
+use Role::Tiny 'with';
with qw(
My::Does::Basic1
My::Does::Basic2
{
package My::Does::Basic3;
- use Role::Tiny::Restricted;
+ use Role::Tiny;
with 'My::Does::Basic2';
sub method3 {
eval <<'END_PACKAGE';
package My::Class2;
-use Role::Tiny::Restricted 'with';
+use Role::Tiny 'with';
with qw(
My::Does::Basic3
);
{
{
package Role::Which::Imports;
- use Role::Tiny::Restricted allow => 'TestMethods';
+ use Role::Tiny allow => 'TestMethods';
use TestMethods qw(this that);
}
{
package Class::With::ImportingRole;
- use Role::Tiny::Restricted 'with';
+ use Role::Tiny 'with';
with 'Role::Which::Imports';
sub new { bless {} => shift }
}
{
{
package Role::WithImportsOnceRemoved;
- use Role::Tiny::Restricted;
+ use Role::Tiny;
with 'Role::Which::Imports';
}
{
package Class::With::ImportingRole2;
- use Role::Tiny::Restricted 'with';
+ use Role::Tiny 'with';
$ENV{DEBUG} = 1;
with 'Role::WithImportsOnceRemoved';
sub new { bless {} => shift }
use lib 'lib', 't/role-basic/lib';
use MyTests;
-require Role::Tiny::Restricted;
+require Role::Tiny;
{
package My::Does::Basic;
- use Role::Tiny::Restricted;
+ use Role::Tiny;
requires 'turbo_charger';
}
eval <<'END_PACKAGE';
-package My::Bad::MultipleWith;
-use Role::Tiny::Restricted::With;
-with 'My::Does::Basic';
-with 'My::Does::Basic'; # can't use with() more than once
-sub turbo_charger {}
-END_PACKAGE
-like $@,
- qr/with\(\) may not be called more than once for My::Bad::MultipleWith/,
- 'Trying to use with() more than once in a package should fail';
-
-eval <<'END_PACKAGE';
package My::Bad::Requirement;
-use Role::Tiny::Restricted::With;
+use Role::Tiny::With;
with 'My::Does::Basic'; # requires turbo_charger
END_PACKAGE
like $@,
{
{
package My::Conflict;
- use Role::Tiny::Restricted;
+ use Role::Tiny;
sub conflict {};
}
eval <<' END_PACKAGE';
package My::Bad::MethodConflicts;
- use Role::Tiny::Restricted::With;
+ use Role::Tiny::With;
with qw(My::Does::Basic My::Conflict);
sub turbo_charger {}
END_PACKAGE
{
{
package Role1;
- use Role::Tiny::Restricted;
+ use Role::Tiny;
requires 'missing_method';
sub method1 { 'method1' }
}
{
package Role2;
- use Role::Tiny::Restricted;
+ use Role::Tiny;
with 'Role1';
sub method2 { 'method2' }
}
eval <<" END";
package My::Class::Missing1;
- use Role::Tiny::Restricted::With;
+ use Role::Tiny::With;
with 'Role2';
END
like $@,
{
{
package Role3;
- use Role::Tiny::Restricted;
+ use Role::Tiny;
requires qw(this that);
}
eval <<" END";
package My::Class::Missing2;
- use Role::Tiny::Restricted::With;
+ use Role::Tiny::With;
with 'Role3';
END
like $@,
--- /dev/null
+use strictures 1;
+use Test::More;
+
+{
+ package Role; use Role::Tiny;
+ around foo => sub { my $orig = shift; 1 + $orig->(@_) };
+ package Base; sub foo { 1 }
+}
+
+eval { Role::Tiny->create_class_with_roles('Base', qw(Role Role)); };
+
+like $@, 'Duplication', 'duplicate role detected';
+
+done_testing;