2 use Test::More qw(no_plan);
5 package My::Role::OnOff;
8 importing => { 'Moo::Role' => [] },
9 subs => [ qw(has before after around) ];
12 my ($me, $into, %args) = @_;
13 my $name = $args{name};
14 has $name => (is => 'rw');
15 install "${name}_on" => sub { shift->$name(1); };
16 install "${name}_off" => sub { shift->$name(0); };
18 $INC{"My/Role/OnOff.pm"} = __FILE__;
27 with OnOff(name => 'lights');
30 my $lights = LightSwitch->new;
32 is($lights->lights, undef, 'Initial state');
33 is($lights->lights_on, 1, 'Turn on');
34 is($lights->lights, 1, 'On');
35 is($lights->lights_off, 0, 'Turn off');
36 is($lights->lights, 0, 'Off');