use strict;
use warnings;
-use Test::More tests => 39;
+use Test::More;
use Test::Exception;
=pod
-This tests the more complex
-delegation cases and that they
+This tests the more complex
+delegation cases and that they
do not fail at compile time.
=cut
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",
} "subrefs on non moose class give no meta";
::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 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" }
}
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" );
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;