Commit | Line | Data |
e3c07b19 |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
a28e50e4 |
6 | use Test::More; |
e3c07b19 |
7 | |
8 | { |
9 | package Room; |
10 | use Moose; |
a5209c26 |
11 | |
e3c07b19 |
12 | has 'is_lit' => ( |
d50fc84a |
13 | traits => ['Bool'], |
14 | is => 'rw', |
15 | isa => 'Bool', |
16 | default => 0, |
17 | handles => { |
18 | illuminate => 'set', |
19 | darken => 'unset', |
20 | flip_switch => 'toggle', |
21 | is_dark => 'not', |
22 | }, |
23 | ) |
e3c07b19 |
24 | } |
25 | |
26 | my $room = Room->new; |
27 | $room->illuminate; |
d50fc84a |
28 | ok( $room->is_lit, 'set is_lit to 1 using ->illuminate' ); |
29 | ok( !$room->is_dark, 'check if is_dark does the right thing' ); |
e3c07b19 |
30 | |
31 | $room->darken; |
d50fc84a |
32 | ok( !$room->is_lit, 'set is_lit to 0 using ->darken' ); |
33 | ok( $room->is_dark, 'check if is_dark does the right thing' ); |
e3c07b19 |
34 | |
35 | $room->flip_switch; |
d50fc84a |
36 | ok( $room->is_lit, 'toggle is_lit back to 1 using ->flip_switch' ); |
37 | ok( !$room->is_dark, 'check if is_dark does the right thing' ); |
e3c07b19 |
38 | |
39 | $room->flip_switch; |
d50fc84a |
40 | ok( !$room->is_lit, 'toggle is_lit back to 0 again using ->flip_switch' ); |
41 | ok( $room->is_dark, 'check if is_dark does the right thing' ); |
e3c07b19 |
42 | |
a28e50e4 |
43 | done_testing; |