File: 032_roles_and_method_cloning.t

package info (click to toggle)
librole-basic-perl 0.16-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 252 kB
  • sloc: perl: 1,725; makefile: 7
file content (66 lines) | stat: -rw-r--r-- 1,278 bytes parent folder | download | duplicates (6)
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
58
59
60
61
62
63
64
65
66
#!/usr/bin/perl

use strict;
use warnings;

use lib 'lib', 't/lib';
use MyTests tests => 10;

{
    package Role::Foo;
    use Role::Basic;

    sub foo { (caller(0))[3] }
}

{
    package ClassA;
    use Role::Basic 'with';

    with 'Role::Foo';
}

{
    my $meth = ClassA->can('foo');
    ok( $meth, 'ClassA has a foo method' );
    is( $meth, Role::Foo->can('foo'),
        'ClassA->foo was cloned from Role::Foo->foo' );
}

{
    package Role::Bar;
    use Role::Basic;
    with 'Role::Foo';

    sub bar { }
}

{
    my $meth = Role::Bar->can('foo');
    ok( $meth, 'Role::Bar has a foo method' );
    is( $meth, Role::Foo->can('foo'),
        'Role::Bar->foo was cloned from Role::Foo->foo' );
}

{
    package ClassB;
    use Role::Basic 'with';

    with 'Role::Bar';
}

{
    my $meth = ClassB->can('foo');
    ok( $meth, 'ClassB has a foo method' );
    is( $meth, Role::Bar->can('foo'),
        'ClassA->foo was cloned from Role::Bar->foo' );
    is( $meth, Role::Foo->can('foo'),
        '... which in turn was cloned from Role::Foo->foo' );
}

isnt( ClassA->foo, "ClassB::foo", "ClassA::foo is not confused with ClassB::foo");

is( ClassB->foo, 'Role::Foo::foo', 'ClassB::foo knows its name' );
is( ClassA->foo, 'Role::Foo::foo', 'ClassA::foo knows its name' );