From: Dave Rolsky Date: Thu, 16 Jun 2011 15:21:05 +0000 (-0500) Subject: Tidy new code X-Git-Tag: 2.0009~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4d518b1e4a018e649597d9978d20321227ade845;p=gitmo%2FMoose.git Tidy new code --- diff --git a/t/basics/rebless.t b/t/basics/rebless.t index c443ec5..a232f26 100644 --- a/t/basics/rebless.t +++ b/t/basics/rebless.t @@ -44,7 +44,7 @@ subtype 'Positive' ); has '+lazy_classname' => ( - default => sub { "Child" }, + default => sub {"Child"}, ); has '+type_constrained' => ( @@ -56,13 +56,14 @@ subtype 'Positive' our %initializer_calls; has new_attr => ( - is => 'rw', isa => 'Str', + is => 'rw', + isa => 'Str', trigger => sub { - my ($self, $val, $attr) = @_; + my ( $self, $val, $attr ) = @_; $trigger_calls{new_attr}++; }, initializer => sub { - my ($self, $value, $set, $attr) = @_; + my ( $self, $value, $set, $attr ) = @_; $initializer_calls{new_attr}++; $set->($value); }, @@ -71,37 +72,62 @@ subtype 'Positive' my @classes = qw(Parent Child); -with_immutable -{ +with_immutable { my $foo = Parent->new; my $bar = Parent->new; - is(blessed($foo), 'Parent', 'Parent->new gives a Parent object'); - is($foo->name, undef, 'No name yet'); - is($foo->lazy_classname, 'Parent', "lazy attribute initialized"); - is( exception { $foo->type_constrained(10.5) }, undef, "Num type constraint for now.." ); + is( blessed($foo), 'Parent', 'Parent->new gives a Parent object' ); + is( $foo->name, undef, 'No name yet' ); + is( $foo->lazy_classname, 'Parent', "lazy attribute initialized" ); + is( + exception { $foo->type_constrained(10.5) }, undef, + "Num type constraint for now.." + ); # try to rebless, except it will fail due to Child's stricter type constraint - like( exception { Child->meta->rebless_instance($foo) }, qr/^Attribute \(type_constrained\) does not pass the type constraint because\: Validation failed for 'Int' with value 10\.5/, '... this failed because of type check' ); - like( exception { Child->meta->rebless_instance($bar) }, qr/^Attribute \(type_constrained\) does not pass the type constraint because\: Validation failed for 'Int' with value 5\.5/, '... this failed because of type check' ); + like( + exception { Child->meta->rebless_instance($foo) }, + qr/^Attribute \(type_constrained\) does not pass the type constraint because\: Validation failed for 'Int' with value 10\.5/, + '... this failed because of type check' + ); + like( + exception { Child->meta->rebless_instance($bar) }, + qr/^Attribute \(type_constrained\) does not pass the type constraint because\: Validation failed for 'Int' with value 5\.5/, + '... this failed because of type check' + ); $foo->type_constrained(10); $bar->type_constrained(5); Child->meta->rebless_instance($foo); - Child->meta->rebless_instance($bar, new_attr => 'blah'); - - is(blessed($foo), 'Child', 'successfully reblessed into Child'); - is($foo->name, 'Junior', "Child->name's default came through"); + Child->meta->rebless_instance( $bar, new_attr => 'blah' ); - is($foo->lazy_classname, 'Parent', "lazy attribute was already initialized"); - is($bar->lazy_classname, 'Child', "lazy attribute just now initialized"); + is( blessed($foo), 'Child', 'successfully reblessed into Child' ); + is( $foo->name, 'Junior', "Child->name's default came through" ); - like( exception { $foo->type_constrained(10.5) }, qr/^Attribute \(type_constrained\) does not pass the type constraint because\: Validation failed for 'Int' with value 10\.5/, '... this failed because of type check' ); + is( + $foo->lazy_classname, 'Parent', + "lazy attribute was already initialized" + ); + is( + $bar->lazy_classname, 'Child', + "lazy attribute just now initialized" + ); + like( + exception { $foo->type_constrained(10.5) }, + qr/^Attribute \(type_constrained\) does not pass the type constraint because\: Validation failed for 'Int' with value 10\.5/, + '... this failed because of type check' + ); - is_deeply(\%Child::trigger_calls, { new_attr => 1 }, 'Trigger fired on rebless_instance'); - is_deeply(\%Child::initializer_calls, { new_attr => 1 }, 'Initializer fired on rebless_instance'); + is_deeply( + \%Child::trigger_calls, { new_attr => 1 }, + 'Trigger fired on rebless_instance' + ); + is_deeply( + \%Child::initializer_calls, { new_attr => 1 }, + 'Initializer fired on rebless_instance' + ); undef %Child::trigger_calls; undef %Child::initializer_calls;