From: Jeff Bisbee Date: Sat, 24 Oct 2009 17:39:22 +0000 (-0400) Subject: tests for handles => CODE block X-Git-Tag: 0.93~11 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=665592617dddf7d385ca8c07b26ab079a055d34e;p=gitmo%2FMoose.git tests for handles => CODE block --- diff --git a/t/020_attributes/011_more_attr_delegation.t b/t/020_attributes/011_more_attr_delegation.t index 99a3b40..05393ad 100644 --- a/t/020_attributes/011_more_attr_delegation.t +++ b/t/020_attributes/011_more_attr_delegation.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 39; +use Test::More tests => 43; use Test::Exception; =pod @@ -76,9 +76,23 @@ do not fail at compile time. 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 { "parrent_1" } + ::dies_ok { has child_a => ( is => "ro", @@ -167,6 +181,25 @@ do not fail at compile time. ); } "can delegate to object even without explicit reader"; + ::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"; + + ::lives_ok { + has child_i => ( + isa => "ChildI", + is => "ro", + default => sub { ChildI->new }, + handles => sub { map { $_, $_ } grep { !/^parent_method_1$/ }$_[1]->get_all_method_names }, + ); + } "Test handles code ref for skipping predefined methods"; + + sub parent_method { "p" } } @@ -179,8 +212,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" );