17 cut_in_half => [ div => 2 ],
31 my $class = Moose::Meta::Class->create(
33 superclasses => ['Moose::Object'],
36 $class->add_attribute(
43 clearer => '_clear_integer',
48 return ( $class->name, \%handles );
53 run_tests(build_class);
54 run_tests( build_class( lazy => 1 ) );
58 my ( $class, $handles ) = @_;
60 can_ok( $class, $_ ) for sort keys %{$handles};
63 my $obj = $class->new;
65 is( $obj->integer, 5, 'Default to five' );
69 is( $obj->integer, 15, 'Add ten for fithteen' );
71 throws_ok { $obj->add( 10, 2 ) }
72 qr/Cannot call add with more than 1 argument/,
73 'add throws an error when 2 arguments are passed';
77 is( $obj->integer, 12, 'Subtract three for 12' );
79 throws_ok { $obj->sub( 10, 2 ) }
80 qr/Cannot call sub with more than 1 argument/,
81 'sub throws an error when 2 arguments are passed';
85 is( $obj->integer, 10, 'Set to ten' );
87 throws_ok { $obj->set( 10, 2 ) }
88 qr/Cannot call set with more than 1 argument/,
89 'set throws an error when 2 arguments are passed';
93 is( $obj->integer, 5, 'divide by 2' );
95 throws_ok { $obj->div( 10, 2 ) }
96 qr/Cannot call div with more than 1 argument/,
97 'div throws an error when 2 arguments are passed';
101 is( $obj->integer, 10, 'multiplied by 2' );
103 throws_ok { $obj->mul( 10, 2 ) }
104 qr/Cannot call mul with more than 1 argument/,
105 'mul throws an error when 2 arguments are passed';
109 is( $obj->integer, 0, 'Mod by 2' );
111 throws_ok { $obj->mod( 10, 2 ) }
112 qr/Cannot call mod with more than 1 argument/,
113 'mod throws an error when 2 arguments are passed';
119 is( $obj->integer, 2, 'Mod by 5' );
125 throws_ok { $obj->abs(10) }
126 qr/Cannot call abs with any arguments/,
127 'abs throws an error when an argument is passed';
129 is( $obj->integer, 1, 'abs 1' );
135 is( $obj->integer, 13, 'inc 12' );
139 is( $obj->integer, 12, 'dec 13' );
141 if ( $class->meta->get_attribute('integer')->is_lazy ) {
142 my $obj = $class->new;
146 is( $obj->integer, 7, 'add with lazy default' );
148 $obj->_clear_integer;
152 is( $obj->integer, 1, 'mod with lazy default' );