From: wu-lee <mouse.git.wu-lee@noodlefactory.co.uk>
Date: Fri, 3 Apr 2009 16:30:37 +0000 (+0100)
Subject: Added test for the correct BUILD order after immutable-ising a class.
X-Git-Tag: 0.20~17
X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=13973ae99344d26373a62de94f6831353fb5c93b;p=gitmo%2FMouse.git

Added test for the correct BUILD order after immutable-ising a class.
---

diff --git a/t/900_bug/001_immutable_types.t b/t/900_bug/001_immutable_types.t
index f5e7ece..b3950e2 100644
--- a/t/900_bug/001_immutable_types.t
+++ b/t/900_bug/001_immutable_types.t
@@ -1,6 +1,6 @@
 use strict;
 use warnings;
-use Test::More tests => 2;
+use Test::More tests => 4;
 use Mouse::Util::TypeConstraints;
 
 subtype 'Foo', as 'Object', where { $_->isa('A') };
@@ -21,3 +21,47 @@ isa_ok(C->new(a => A->new()), 'C');
 C->meta->make_immutable;
 isa_ok(C->new(a => A->new()), 'C');
 
+
+
+# The BUILD invocation order used to get reversed after
+# making a class immutable.  This checks it is correct.
+{
+    package D;
+    use Mouse;
+
+    # we'll keep
+    has order => 
+        (is => 'ro', 
+         default => sub {[]});
+
+    sub BUILD { push @{shift->order}, 'D' }
+
+    package E;
+    use Mouse;
+    extends 'D';
+
+    sub BUILD { push @{shift->order}, 'E' }
+
+    package F;
+    use Mouse;
+    extends 'E';
+
+    sub BUILD { push @{shift->order}, 'F' }
+
+
+}
+
+my $obj = F->new;
+
+print join(", ", @{$obj->order}),"\n";
+is_deeply $obj->order, [qw(D E F)], "mutable BUILD invocation order correct";
+
+# now make the classes immutable
+$_->meta->make_immutable for qw(D E F);
+
+my $obj2 = F->new;
+
+print join(", ", @{$obj2->order}),"\n";
+is_deeply $obj2->order, [qw(D E F)], "immutable BUILD invocation order still correct";
+
+