5 eval { require Moo::Role; 1 }
6 or plan skip_all => q{Requires Moo::Role};
10 package My::Role::OnOff;
13 importing => { 'Moo::Role' => [] },
14 subs => [ qw(has before after around) ];
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); };
23 $INC{"My/Role/OnOff.pm"} = __FILE__;
32 with OnOff(name => 'lights');
35 my $lights = LightSwitch->new;
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');