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;
14 This tests the more complex
15 delegation cases and that they
16 do not fail at compile time.
25 sub child_a_super_method { "as" }
30 extends "ChildASuper";
32 sub child_a_method_1 { "a1" }
33 sub child_a_method_2 { Scalar::Util::blessed($_[0]) . " a2" }
40 sub child_a_method_3 { "a3" }
45 sub child_b_method_1 { "b1" }
46 sub child_b_method_2 { "b2" }
47 sub child_b_method_3 { "b3" }
52 sub child_c_method_1 { "c1" }
53 sub child_c_method_2 { "c2" }
54 sub child_c_method_3_la { "c3" }
55 sub child_c_method_4_la { "c4" }
60 sub child_d_method_1 { "d1" }
61 sub child_d_method_2 { "d2" }
66 sub new { bless {}, shift }
67 sub child_e_method_1 { "e1" }
68 sub child_e_method_2 { "e2" }
73 sub new { bless {}, shift }
74 sub child_f_method_1 { "f1" }
75 sub child_f_method_2 { "f2" }
80 sub child_g_method_1 { "g1" }
85 sub child_h_method_1 { "h1" }
86 sub parent_method_1 { "child_parent_1" }
91 sub child_i_method_1 { "i1" }
92 sub parent_method_1 { "child_parent_1" }
97 sub parent_method_1 { "parent_1" }
98 ::can_ok('Parent', 'parent_method_1');
103 default => sub { ChildA->new },
106 } "all_methods requires explicit isa";
112 default => sub { ChildA->new },
115 } "allow all_methods with explicit isa";
120 default => sub { ChildB->new },
121 handles => [qw/child_b_method_1/],
123 } "don't need to declare isa if method list is predefined";
129 default => sub { ChildC->new },
132 } "can declare regex collector";
137 default => sub { ChildD->new },
139 my ( $class, $delegate_class ) = @_;
142 } "can't create attr with generative handles parameter and no isa";
148 default => sub { ChildD->new },
150 my ( $class, $delegate_class ) = @_;
154 } "can't create attr with generative handles parameter and no isa";
160 default => sub { ChildE->new },
161 handles => ["child_e_method_2"],
163 } "can delegate to non moose class using explicit method list";
170 default => sub { ChildF->new },
172 $delegate_class = $_[1]->name;
176 } "subrefs on non moose class give no meta";
178 ::is( $delegate_class, "ChildF", "plain classes are handed down to subs" );
183 default => sub { ChildG->new },
184 handles => ["child_g_method_1"],
186 } "can delegate to object even without explicit reader";
188 ::can_ok('Parent', 'parent_method_1');
193 default => sub { ChildH->new },
194 handles => sub { map { $_, $_ } $_[1]->get_all_method_names },
196 } "Can't override exisiting class method in delegate";
197 ::can_ok('Parent', 'parent_method_1');
203 default => sub { ChildI->new },
205 map { $_, $_ } grep { !/^parent_method_1|meta$/ }
206 $_[1]->get_all_method_names;
209 } "Test handles code ref for skipping predefined methods";
212 sub parent_method { "p" }
216 isa_ok( my $p = Parent->new, "Parent" );
217 isa_ok( $p->child_a, "ChildA" );
218 isa_ok( $p->child_b, "ChildB" );
219 isa_ok( $p->child_c, "ChildC" );
220 isa_ok( $p->child_d, "ChildD" );
221 isa_ok( $p->child_e, "ChildE" );
222 isa_ok( $p->child_f, "ChildF" );
223 isa_ok( $p->child_i, "ChildI" );
225 ok(!$p->can('child_g'), '... no child_g accessor defined');
226 { local $TODO = 'Mouse does not install delegations atomically';
227 ok(!$p->can('child_h'), '... no child_h accessor defined');
230 is( $p->parent_method, "p", "parent method" );
231 is( $p->child_a->child_a_super_method, "as", "child supermethod" );
232 is( $p->child_a->child_a_method_1, "a1", "child method" );
234 can_ok( $p, "child_a_super_method" );
235 can_ok( $p, "child_a_method_1" );
236 can_ok( $p, "child_a_method_2" );
237 ok( !$p->can( "child_a_method_3" ), "but not subclass of delegate class" );
239 is( $p->child_a_method_1, $p->child_a->child_a_method_1, "delegate behaves the same" );
240 is( $p->child_a_method_2, "ChildA a2", "delegates are their own invocants" );
243 can_ok( $p, "child_b_method_1" );
244 ok( !$p->can("child_b_method_2"), "but not ChildB's unspecified siblings" );
247 ok( !$p->can($_), "none of ChildD's methods ($_)" )
248 for grep { /^child/ } map { $_->name } ChildD->meta->get_all_methods();
250 can_ok( $p, "child_c_method_3_la" );
251 can_ok( $p, "child_c_method_4_la" );
253 is( $p->child_c_method_3_la, "c3", "ChildC method delegated OK" );
255 can_ok( $p, "child_e_method_2" );
256 ok( !$p->can("child_e_method_1"), "but not child_e_method_1");
258 is( $p->child_e_method_2, "e2", "delegate to non moose class (child_e_method_2)" );
260 can_ok( $p, "child_g_method_1" );
261 is( $p->child_g_method_1, "g1", "delegate to moose class without reader (child_g_method_1)" );
263 can_ok( $p, "child_i_method_1" );
264 is( $p->parent_method_1, "parent_1", "delegate doesn't override existing method" );