X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F028-subclass-attr.t;h=eaeb283ff836ea9c2db501ef61d00f6fbc2240b5;hb=3b46bd4991dea7ead4e7f52a089222d24554e2bd;hp=2ec4e6e49d1c5327ea11b23369fe6829c51a45a7;hpb=28d269491e4b8dad61231390965529c3993a2ba5;p=gitmo%2FMouse.git diff --git a/t/028-subclass-attr.t b/t/028-subclass-attr.t index 2ec4e6e..eaeb283 100644 --- a/t/028-subclass-attr.t +++ b/t/028-subclass-attr.t @@ -1,7 +1,7 @@ #!/usr/bin/env perl use strict; use warnings; -use Test::More tests => 3; +use Test::More tests => 11; do { package Class; @@ -31,3 +31,41 @@ is_deeply([Child->meta->compute_all_applicable_attributes], [ Class->meta->get_attribute('class'), ], "correct compute_all_applicable_attributes"); +do { + package Foo; + use Mouse; + + has attr => ( + is => 'ro', + default => 'Foo', + ); + + package Bar; + use Mouse; + extends 'Foo'; + + has attr => ( + is => 'rw', + ); +}; + +my $foo = Foo->new; +is($foo->attr, 'Foo', 'subclass does not affect parent attr'); + +my $bar = Bar->new; +is($bar->attr, undef, 'new attribute does not have the new default'); + +is(Foo->meta->get_attribute('attr')->default, 'Foo'); +is(Foo->meta->get_attribute('attr')->_is_metadata, 'ro'); + +is(Bar->meta->get_attribute('attr')->default, undef); +is(Bar->meta->get_attribute('attr')->_is_metadata, 'rw'); + +is_deeply([Foo->meta->compute_all_applicable_attributes], [ + Foo->meta->get_attribute('attr'), +], "correct compute_all_applicable_attributes"); + +is_deeply([Bar->meta->compute_all_applicable_attributes], [ + Bar->meta->get_attribute('attr'), +], "correct compute_all_applicable_attributes"); +