9 use Moose::Util::TypeConstraints;
10 use NoInlineAttribute;
19 flip_switch => 'toggle',
28 my $class = Moose::Meta::Class->create(
30 superclasses => ['Moose::Object'],
34 push @traits, 'NoInlineAttribute'
35 if delete $attr{no_inline};
37 $class->add_attribute(
44 clearer => '_clear_is_list',
49 return ( $class->name, \%handles );
54 run_tests(build_class);
55 run_tests( build_class( lazy => 1 ) );
56 run_tests( build_class( trigger => sub { } ) );
57 run_tests( build_class( no_inline => 1 ) );
59 # Will force the inlining code to check the entire hashref when it is modified.
60 subtype 'MyBool', as 'Bool', where { 1 };
62 run_tests( build_class( isa => 'MyBool' ) );
64 coerce 'MyBool', from 'Bool', via { $_ };
66 run_tests( build_class( isa => 'MyBool', coerce => 1 ) );
70 my ( $class, $handles ) = @_;
72 can_ok( $class, $_ ) for sort keys %{$handles};
75 my $obj = $class->new;
77 ok( $obj->illuminate, 'set returns true' );
78 ok( $obj->is_lit, 'set is_lit to 1 using ->illuminate' );
79 ok( !$obj->is_dark, 'check if is_dark does the right thing' );
81 like( exception { $obj->illuminate(1) }, qr/Cannot call set with any arguments/, 'set throws an error when an argument is passed' );
83 ok( !$obj->darken, 'unset returns false' );
84 ok( !$obj->is_lit, 'set is_lit to 0 using ->darken' );
85 ok( $obj->is_dark, 'check if is_dark does the right thing' );
87 like( exception { $obj->darken(1) }, qr/Cannot call unset with any arguments/, 'unset throws an error when an argument is passed' );
89 ok( $obj->flip_switch, 'toggle returns new value' );
90 ok( $obj->is_lit, 'toggle is_lit back to 1 using ->flip_switch' );
91 ok( !$obj->is_dark, 'check if is_dark does the right thing' );
93 like( exception { $obj->flip_switch(1) }, qr/Cannot call toggle with any arguments/, 'toggle throws an error when an argument is passed' );
97 'toggle is_lit back to 0 again using ->flip_switch' );
98 ok( $obj->is_dark, 'check if is_dark does the right thing' );