Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 47 lines (31 sloc) 0.759 kB
297e783 [t] and [t/spec]
moritz authored
1 use v6;
2
3 use Test;
4
2de5711 @jnthn Some extra submethod in role tests.
jnthn authored
5 plan 4;
297e783 [t] and [t/spec]
moritz authored
6
7 =begin pod
8
9 Tests of roles with submethods
10
e27dccc [t/spec] smartlinks and a simplification
moritz authored
11 # L<S14/Roles>
12 # L<S12/Submethods>
13
297e783 [t] and [t/spec]
moritz authored
14 =end pod
15
16
17 role AddBuild
18 {
e27dccc [t/spec] smartlinks and a simplification
moritz authored
19 has $.did_build = 0;
8dc7d4b [t/spec] mark various tests that intentionally declare things that ar…
lwall authored
20 submethod BUILD ( $self: ) #OK not used
297e783 [t] and [t/spec]
moritz authored
21 {
e27dccc [t/spec] smartlinks and a simplification
moritz authored
22 $!did_build = 1;
297e783 [t] and [t/spec]
moritz authored
23 }
24 }
25
26 class MyClass does AddBuild {}
27
28 my $class = MyClass.new();
e27dccc [t/spec] smartlinks and a simplification
moritz authored
29 ok( $class.did_build, 'Class that does role should do submethods of role' );
30
2de5711 @jnthn Some extra submethod in role tests.
jnthn authored
31
32 role WithSM {
33 submethod ouch() { 'the pain' }
34 submethod conf() { 'FAIL' }
35 }
36
37 class Parent does WithSM {
38 submethod conf() { 'correct' }
39 }
40 class Child is Parent { }
41
42 is Parent.ouch(), 'the pain', 'submethod composes ok...';
43 is Parent.conf(), 'correct', 'submethod in class wins';
709e414 @lizmat s/dies_ok/dies-ok/g
lizmat authored
44 dies-ok { Child.ouch() }, 'composed submethod acts like one';
2de5711 @jnthn Some extra submethod in role tests.
jnthn authored
45
e27dccc [t/spec] smartlinks and a simplification
moritz authored
46 # vim: ft=perl6
Something went wrong with that request. Please try again.