2 # This is automatically generated by author/import-moose-test.pl.
3 # DO NOT EDIT THIS FILE. ANY CHANGES WILL BE LOST!!!
4 use t::lib::MooseCompat;
10 $TODO = q{Mouse is not yet completed};
15 This tests the more complex
16 delegation cases and that they
17 do not fail at compile time.
26 sub child_a_super_method { "as" }
31 extends "ChildASuper";
33 sub child_a_method_1 { "a1" }
34 sub child_a_method_2 { Scalar::Util::blessed($_[0]) . " a2" }
41 sub child_a_method_3 { "a3" }
46 sub child_b_method_1 { "b1" }
47 sub child_b_method_2 { "b2" }
48 sub child_b_method_3 { "b3" }
53 sub child_c_method_1 { "c1" }
54 sub child_c_method_2 { "c2" }
55 sub child_c_method_3_la { "c3" }
56 sub child_c_method_4_la { "c4" }
61 sub child_d_method_1 { "d1" }
62 sub child_d_method_2 { "d2" }
67 sub new { bless {}, shift }
68 sub child_e_method_1 { "e1" }
69 sub child_e_method_2 { "e2" }
74 sub new { bless {}, shift }
75 sub child_f_method_1 { "f1" }
76 sub child_f_method_2 { "f2" }
81 sub child_g_method_1 { "g1" }
86 sub child_h_method_1 { "h1" }
87 sub parent_method_1 { "child_parent_1" }
92 sub child_i_method_1 { "i1" }
93 sub parent_method_1 { "child_parent_1" }
98 sub parent_method_1 { "parent_1" }
99 ::can_ok('Parent', 'parent_method_1');
104 default => sub { ChildA->new },
107 } "all_methods requires explicit isa";
113 default => sub { ChildA->new },
116 } "allow all_methods with explicit isa";
121 default => sub { ChildB->new },
122 handles => [qw/child_b_method_1/],
124 } "don't need to declare isa if method list is predefined";
130 default => sub { ChildC->new },
133 } "can declare regex collector";
138 default => sub { ChildD->new },
140 my ( $class, $delegate_class ) = @_;
143 } "can't create attr with generative handles parameter and no isa";
149 default => sub { ChildD->new },
151 my ( $class, $delegate_class ) = @_;
155 } "can't create attr with generative handles parameter and no isa";
161 default => sub { ChildE->new },
162 handles => ["child_e_method_2"],
164 } "can delegate to non moose class using explicit method list";
171 default => sub { ChildF->new },
173 $delegate_class = $_[1]->name;
177 } "subrefs on non moose class give no meta";
179 ::is( $delegate_class, "ChildF", "plain classes are handed down to subs" );
184 default => sub { ChildG->new },
185 handles => ["child_g_method_1"],
187 } "can delegate to object even without explicit reader";
189 ::can_ok('Parent', 'parent_method_1');
194 default => sub { ChildH->new },
195 handles => sub { map { $_, $_ } $_[1]->get_all_method_names },
197 } "Can't override exisiting class method in delegate";
198 ::can_ok('Parent', 'parent_method_1');
204 default => sub { ChildI->new },
206 map { $_, $_ } grep { !/^parent_method_1|meta$/ }
207 $_[1]->get_all_method_names;
210 } "Test handles code ref for skipping predefined methods";
213 sub parent_method { "p" }
218 isa_ok( my $p = Parent->new, "Parent" );
219 isa_ok( $p->child_a, "ChildA" );
220 isa_ok( $p->child_b, "ChildB" );
221 isa_ok( $p->child_c, "ChildC" );
222 isa_ok( $p->child_d, "ChildD" );
223 isa_ok( $p->child_e, "ChildE" );
224 isa_ok( $p->child_f, "ChildF" );
225 isa_ok( $p->child_i, "ChildI" );
227 ok(!$p->can('child_g'), '... no child_g accessor defined');
228 ok(!$p->can('child_h'), '... no child_h accessor defined');
231 is( $p->parent_method, "p", "parent method" );
232 is( $p->child_a->child_a_super_method, "as", "child supermethod" );
233 is( $p->child_a->child_a_method_1, "a1", "child method" );
235 can_ok( $p, "child_a_super_method" );
236 can_ok( $p, "child_a_method_1" );
237 can_ok( $p, "child_a_method_2" );
238 ok( !$p->can( "child_a_method_3" ), "but not subclass of delegate class" );
240 is( $p->child_a_method_1, $p->child_a->child_a_method_1, "delegate behaves the same" );
241 is( $p->child_a_method_2, "ChildA a2", "delegates are their own invocants" );
244 can_ok( $p, "child_b_method_1" );
245 ok( !$p->can("child_b_method_2"), "but not ChildB's unspecified siblings" );
248 ok( !$p->can($_), "none of ChildD's methods ($_)" )
249 for grep { /^child/ } map { $_->name } ChildD->meta->get_all_methods();
251 can_ok( $p, "child_c_method_3_la" );
252 can_ok( $p, "child_c_method_4_la" );
254 is( $p->child_c_method_3_la, "c3", "ChildC method delegated OK" );
256 can_ok( $p, "child_e_method_2" );
257 ok( !$p->can("child_e_method_1"), "but not child_e_method_1");
259 is( $p->child_e_method_2, "e2", "delegate to non moose class (child_e_method_2)" );
261 can_ok( $p, "child_g_method_1" );
262 is( $p->child_g_method_1, "g1", "delegate to moose class without reader (child_g_method_1)" );
264 can_ok( $p, "child_i_method_1" );
265 is( $p->parent_method_1, "parent_1", "delegate doesn't override existing method" );