Commit | Line | Data |
236a4386 |
1 | use strictures 1; |
d4e02b02 |
2 | use Test::More; |
236a4386 |
3 | |
4 | BEGIN { |
24d6c55f |
5 | eval { require Moo::Role; 1 } |
6 | or plan skip_all => q{Requires Moo::Role}; |
7 | } |
8 | |
9 | BEGIN { |
236a4386 |
10 | package My::Role::OnOff; |
11 | |
12 | use Package::Variant |
13 | importing => { 'Moo::Role' => [] }, |
14 | subs => [ qw(has before after around) ]; |
15 | |
16 | sub make_variant { |
17 | my ($me, $into, %args) = @_; |
18 | my $name = $args{name}; |
19 | has $name => (is => 'rw'); |
20 | install "${name}_on" => sub { shift->$name(1); }; |
21 | install "${name}_off" => sub { shift->$name(0); }; |
22 | } |
23 | $INC{"My/Role/OnOff.pm"} = __FILE__; |
24 | } |
25 | |
26 | BEGIN { |
27 | package LightSwitch; |
28 | |
29 | use My::Role::OnOff; |
30 | use Moo; |
31 | |
32 | with OnOff(name => 'lights'); |
33 | } |
34 | |
35 | my $lights = LightSwitch->new; |
36 | |
37 | is($lights->lights, undef, 'Initial state'); |
38 | is($lights->lights_on, 1, 'Turn on'); |
39 | is($lights->lights, 1, 'On'); |
40 | is($lights->lights_off, 0, 'Turn off'); |
41 | is($lights->lights, 0, 'Off'); |
d4e02b02 |
42 | |
43 | done_testing; |