File: role-tiny-with.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 (57 lines) | stat: -rw-r--r-- 823 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
46
47
48
49
50
51
52
53
54
55
56
57
use strict;
use warnings;
use Test::More;

BEGIN {
  package MyRole;

  use Role::Tiny;

  sub bar { 'role bar' }

  sub baz { 'role baz' }
}

BEGIN {
  package MyClass;

  use Role::Tiny::With;

  with 'MyRole';

  sub foo { 'class foo' }

  sub baz { 'class baz' }

}

is(MyClass->foo, 'class foo', 'method from class no override');
is(MyClass->bar, 'role bar',  'method from role');
is(MyClass->baz, 'class baz', 'method from class');

BEGIN {
  package RoleWithStub;

  use Role::Tiny;

  sub foo { 'role foo' }

  sub bar ($$);
}

{
  package ClassConsumeStub;
  use Role::Tiny::With;

  eval {
    with 'RoleWithStub';
  };
}

is $@, '', 'stub composed without error';
ok exists &ClassConsumeStub::bar,
  'stub exists in consuming class';
ok !defined &ClassConsumeStub::bar,
  'stub consumed as stub';

done_testing;