From: wu-lee Date: Mon, 6 Apr 2009 14:32:37 +0000 (+0100) Subject: Whoops. This should have been included in the previous commit. X-Git-Tag: 0.20~10 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ae7bec5e607b88e9c95cc7784f1a8c3310df3c65;hp=65715de3b166545682d0c342ef26a51cfe354842;p=gitmo%2FMouse.git Whoops. This should have been included in the previous commit. --- diff --git a/t/050-inherited-immutable-constructor-bug.t b/t/050-inherited-immutable-constructor-bug.t new file mode 100755 index 0000000..f522104 --- /dev/null +++ b/t/050-inherited-immutable-constructor-bug.t @@ -0,0 +1,62 @@ +#!/usr/bin/perl +use strict; +use warnings; +use Test::More tests => 8; + +{ + package Sausage; + use Mouse::Role; + + has gristle => (is => 'rw'); +} + +{ + package Dog; + use Mouse; + + has tail => (is => 'rw'); + + __PACKAGE__->meta->make_immutable; +} + +{ + package SausageDog; + use Mouse; + extends 'Dog'; + with 'Sausage'; + + has yap => (is => 'rw'); + +# This class is mutable, but derives from an immutable base, and so +# used to inherit an immutable constructor compiled for the wrong +# class. It is composed with a Role, and should acquire both the +# attributes in that role, and the initialisers. Likewise for it's own +# attributes. (In the bug this test exhibited, it wasn't acquiring an +# initialiser for 'gristle' or 'yap'). +# +# This has now been fixed by adding a check in the immutable +# constructor that the invoking class is the right one, else it +# redispatches to Mouse::Object::new. +} + + + + +my $fritz = SausageDog->new(gristle => 1, + tail => 1, + yap => 1); + + +isa_ok $fritz, 'SausageDog'; +isa_ok $fritz, 'Dog'; +ok !$fritz->isa('Sausage'), "Fritz is not a Sausage"; +ok $fritz->does('Sausage'), "Fritz does Sausage"; + +can_ok $fritz, qw(tail gristle yap); + +ok $fritz->gristle, "Fritz has gristle"; +ok $fritz->tail, "Fritz has a tail"; +ok $fritz->yap, "Fritz has a yap"; + + +