X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F028-subclass-attr.t;h=9a4eabab827eed16609a55c853fe99a9c314e8bf;hb=ad022aac12ce95ee336af9dde0758ae98037f3ab;hp=527e0488810ba52f361a8b1531a1a527f87cb7c1;hpb=36062241ac10535c2ce8e77143c9076e0595bf81;p=gitmo%2FMouse.git diff --git a/t/028-subclass-attr.t b/t/028-subclass-attr.t index 527e048..9a4eaba 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 => 2; +use Test::More tests => 11; do { package Class; @@ -25,3 +25,47 @@ do { my $obj = Child->new(class => 1, child => 1); ok($obj->child, "local attribute set in constructor"); ok($obj->class, "inherited attribute set in constructor"); + +is_deeply([sort(Child->meta->get_all_attributes)], [sort( + Child->meta->get_attribute('child'), + Class->meta->get_attribute('class'), +)], "correct get_all_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->get_all_attributes], [ + Foo->meta->get_attribute('attr'), +], "correct get_all_attributes"); + +is_deeply([Bar->meta->get_all_attributes], [ + Bar->meta->get_attribute('attr'), +], "correct get_all_attributes"); +