| 1 |
use strict; |
| 2 |
use warnings; |
| 3 |
use FindBin; |
| 4 |
use lib "$FindBin::Bin/../../../"; |
| 5 |
use Test::More; |
| 6 |
use t::scan::Util; |
| 7 |
|
| 8 |
test(<<'END'); |
| 9 |
use MooseX::Declare; |
| 10 |
|
| 11 |
role Counter (Str :$name, Int :$charges = 1) { |
| 12 |
has $name => (is => 'rw', isa => 'Int', default => $charges); |
| 13 |
|
| 14 |
method "increment_${name}" { |
| 15 |
$self->$name($self->$name + 1); |
| 16 |
} |
| 17 |
|
| 18 |
method "reset_${name}" { |
| 19 |
$self->$name(0); |
| 20 |
} |
| 21 |
} |
| 22 |
|
| 23 |
class MyGame::Weapon { |
| 24 |
with Counter => { name => 'enchantment', charges => 5 }; |
| 25 |
} |
| 26 |
|
| 27 |
class MyGame::Wand { |
| 28 |
with Counter => { name => 'zapped', charges => 3 }; |
| 29 |
} |
| 30 |
|
| 31 |
class MyGame::Scroll { |
| 32 |
with Counter => { name => 'spelled' }; |
| 33 |
} |
| 34 |
|
| 35 |
END |
| 36 |
|
| 37 |
done_testing; |