7 use Moose::Util::TypeConstraints;
16 flip_switch => 'toggle',
25 my $class = Moose::Meta::Class->create(
27 superclasses => ['Moose::Object'],
30 $class->add_attribute(
37 clearer => '_clear_is_list',
42 return ( $class->name, \%handles );
47 run_tests(build_class);
48 run_tests( build_class( lazy => 1 ) );
50 # Will force the inlining code to check the entire hashref when it is modified.
51 subtype 'MyBool', as 'Bool', where { 1 };
53 run_tests( build_class( isa => 'MyBool' ) );
55 coerce 'MyBool', from 'Bool', via { $_ };
57 run_tests( build_class( isa => 'MyBool', coerce => 1 ) );
61 my ( $class, $handles ) = @_;
63 can_ok( $class, $_ ) for sort keys %{$handles};
66 my $obj = $class->new;
69 ok( $obj->is_lit, 'set is_lit to 1 using ->illuminate' );
70 ok( !$obj->is_dark, 'check if is_dark does the right thing' );
72 throws_ok { $obj->illuminate(1) }
73 qr/Cannot call set with any arguments/,
74 'set throws an error when an argument is passed';
77 ok( !$obj->is_lit, 'set is_lit to 0 using ->darken' );
78 ok( $obj->is_dark, 'check if is_dark does the right thing' );
80 throws_ok { $obj->darken(1) }
81 qr/Cannot call unset with any arguments/,
82 'unset throws an error when an argument is passed';
85 ok( $obj->is_lit, 'toggle is_lit back to 1 using ->flip_switch' );
86 ok( !$obj->is_dark, 'check if is_dark does the right thing' );
88 throws_ok { $obj->flip_switch(1) }
89 qr/Cannot call toggle with any arguments/,
90 'toggle throws an error when an argument is passed';
94 'toggle is_lit back to 0 again using ->flip_switch' );
95 ok( $obj->is_dark, 'check if is_dark does the right thing' );