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 ) );
49 run_tests( build_class( trigger => sub { } ) );
51 # Will force the inlining code to check the entire hashref when it is modified.
52 subtype 'MyBool', as 'Bool', where { 1 };
54 run_tests( build_class( isa => 'MyBool' ) );
56 coerce 'MyBool', from 'Bool', via { $_ };
58 run_tests( build_class( isa => 'MyBool', coerce => 1 ) );
62 my ( $class, $handles ) = @_;
64 can_ok( $class, $_ ) for sort keys %{$handles};
67 my $obj = $class->new;
70 ok( $obj->is_lit, 'set is_lit to 1 using ->illuminate' );
71 ok( !$obj->is_dark, 'check if is_dark does the right thing' );
73 throws_ok { $obj->illuminate(1) }
74 qr/Cannot call set with any arguments/,
75 'set throws an error when an argument is passed';
78 ok( !$obj->is_lit, 'set is_lit to 0 using ->darken' );
79 ok( $obj->is_dark, 'check if is_dark does the right thing' );
81 throws_ok { $obj->darken(1) }
82 qr/Cannot call unset with any arguments/,
83 'unset throws an error when an argument is passed';
86 ok( $obj->is_lit, 'toggle is_lit back to 1 using ->flip_switch' );
87 ok( !$obj->is_dark, 'check if is_dark does the right thing' );
89 throws_ok { $obj->flip_switch(1) }
90 qr/Cannot call toggle with any arguments/,
91 'toggle throws an error when an argument is passed';
95 'toggle is_lit back to 0 again using ->flip_switch' );
96 ok( $obj->is_dark, 'check if is_dark does the right thing' );