File: role-duplication.t

package info (click to toggle)
librole-tiny-perl 2.002004-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 292 kB
  • sloc: perl: 454; makefile: 2
file content (45 lines) | stat: -rw-r--r-- 696 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use strict;
use warnings;
use Test::More;

BEGIN {
  package Role1; use Role::Tiny;
  sub foo1 { 1 }
}
BEGIN {
  package Role2; use Role::Tiny;
  sub foo2 { 2 }
}
BEGIN {
  package BaseClass;
  sub foo { 0 }
}

eval {
  Role::Tiny->create_class_with_roles(
    'BaseClass',
    qw(Role2 Role1 Role1 Role2 Role2),
  );
};

like $@, qr/\ADuplicated roles: Role1, Role2 /,
  'duplicate roles detected';

BEGIN {
  package AnotherRole;
  use Role::Tiny;
  with 'Role1';
}

BEGIN {
  package AnotherClass;
  use Role::Tiny::With;
  with 'AnotherRole';
  delete $AnotherClass::{foo1};
  with 'AnotherRole';
}

ok +AnotherClass->can('foo1'),
  'reapplying roles re-adds missing methods';

done_testing;