-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
plan(6); | ||
|
||
role TheRole { | ||
has $!a; | ||
method role_meth() { "called role method" } | ||
method get_attr() { $!a } | ||
method set_attr($v) { $!a := $v } | ||
method override_me() { "role method" } | ||
} | ||
|
||
class Example { | ||
method override_me() { "class method" } | ||
} | ||
|
||
my $obj := Example.new(); | ||
my $obj_m := Example.new(); | ||
|
||
ok($obj.override_me() eq "class method", "sanity (1)"); | ||
ok($obj_m.override_me() eq "class method", "sanity (2)"); | ||
|
||
$obj_m.HOW.mixin($obj_m, TheRole); | ||
|
||
ok($obj_m.role_meth() eq "called role method", "role method mxied in"); | ||
|
||
$obj_m.set_attr("stout"); | ||
ok($obj_m.get_attr() eq "stout", "attributes from role work properly"); | ||
|
||
ok($obj_m.override_me() eq "role method", "mixed in method overrides original one"); | ||
ok($obj.override_me() eq "class method", "mixing in is per object"); |