X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F020_attributes%2F011_more_attr_delegation.t;h=18b8fc11ba2b9997ba5b03fd50377622b73a1b83;hb=ad3882b59692e4e4eab99f9b183c941e6f63d3bd;hp=10d5e8ce388d4f4c2beab101d6a620865b9d48fd;hpb=e59a5c292a333cac504b65ebd4bba20b5e98d796;p=gitmo%2FMoose.git diff --git a/t/020_attributes/011_more_attr_delegation.t b/t/020_attributes/011_more_attr_delegation.t index 10d5e8c..18b8fc1 100644 --- a/t/020_attributes/011_more_attr_delegation.t +++ b/t/020_attributes/011_more_attr_delegation.t @@ -3,9 +3,17 @@ use strict; use warnings; -use Test::More tests => 35; +use Test::More; use Test::Exception; +=pod + +This tests the more complex +delegation cases and that they +do not fail at compile time. + +=cut + { package ChildASuper; @@ -63,9 +71,29 @@ use Test::Exception; sub child_f_method_1 { "f1" } sub child_f_method_2 { "f2" } + package ChildG; + use Moose; + + sub child_g_method_1 { "g1" } + + package ChildH; + use Moose; + + sub child_h_method_1 { "h1" } + sub parent_method_1 { "child_parent_1" } + + package ChildI; + use Moose; + + sub child_i_method_1 { "i1" } + sub parent_method_1 { "child_parent_1" } + package Parent; use Moose; + sub parent_method_1 { "parent_1" } + ::can_ok('Parent', 'parent_method_1'); + ::dies_ok { has child_a => ( is => "ro", @@ -146,6 +174,38 @@ use Test::Exception; ::is( $delegate_class, "ChildF", "plain classes are handed down to subs" ); + ::lives_ok { + has child_g => ( + isa => "ChildG", + default => sub { ChildG->new }, + handles => ["child_g_method_1"], + ); + } "can delegate to object even without explicit reader"; + + ::can_ok('Parent', 'parent_method_1'); + ::dies_ok { + has child_h => ( + isa => "ChildH", + is => "ro", + default => sub { ChildH->new }, + handles => sub { map { $_, $_ } $_[1]->get_all_method_names }, + ); + } "Can't override exisiting class method in delegate"; + ::can_ok('Parent', 'parent_method_1'); + + ::lives_ok { + has child_i => ( + isa => "ChildI", + is => "ro", + default => sub { ChildI->new }, + handles => sub { + map { $_, $_ } grep { !/^parent_method_1|meta$/ } + $_[1]->get_all_method_names; + }, + ); + } "Test handles code ref for skipping predefined methods"; + + sub parent_method { "p" } } @@ -158,6 +218,10 @@ isa_ok( $p->child_c, "ChildC" ); isa_ok( $p->child_d, "ChildD" ); isa_ok( $p->child_e, "ChildE" ); isa_ok( $p->child_f, "ChildF" ); +isa_ok( $p->child_i, "ChildI" ); + +ok(!$p->can('child_g'), '... no child_g accessor defined'); +ok(!$p->can('child_h'), '... no child_h accessor defined'); is( $p->parent_method, "p", "parent method" ); @@ -178,7 +242,7 @@ ok( !$p->can("child_b_method_2"), "but not ChildB's unspecified siblings" ); ok( !$p->can($_), "none of ChildD's methods ($_)" ) - for grep { /^child/ } map { $_->{name} } ChildD->meta->compute_all_applicable_methods(); + for grep { /^child/ } map { $_->name } ChildD->meta->get_all_methods(); can_ok( $p, "child_c_method_3_la" ); can_ok( $p, "child_c_method_4_la" ); @@ -189,3 +253,11 @@ can_ok( $p, "child_e_method_2" ); ok( !$p->can("child_e_method_1"), "but not child_e_method_1"); is( $p->child_e_method_2, "e2", "delegate to non moose class (child_e_method_2)" ); + +can_ok( $p, "child_g_method_1" ); +is( $p->child_g_method_1, "g1", "delegate to moose class without reader (child_g_method_1)" ); + +can_ok( $p, "child_i_method_1" ); +is( $p->parent_method_1, "parent_1", "delegate doesn't override existing method" ); + +done_testing;