On Wed, Jun 16, 2010 at 03:02:23PM -0700, Kate Yoak wrote: > When I define my packages right inside a script (like for testing), Moose > inheritance breaks down: > > #!/usr/bin/perl > > use strict; > use Test::More tests => 2; > > my $one = new Foo::Child; > ok($one->can('foo'), "extends"); #fails > > my $two = new Foo::App; > ok($two->can('foo'), "isa"); #succeeds > > package Foo; > { > use Moose; > sub foo{}; 1; > } > { > package Foo::Child; > use Moose; extends qw/Foo/; > 1; > } > { > package Foo::App; > use Moose; > use base qw/Foo/; > 1; > } > > I posted a month or more ago about a similar behavior with Roles. Karen > suggested I check that I use braces properly to localize namespaces. I > didn't have time to do that at the time, but did now, trying all the obvious > things. > Moving packages into a separate file solves the problem. > > > :-) Didn't do it!
'extends' happens at runtime, so when your test stuff is running, the 'extends' call hasn't happened yet. 'use' and 'package' are compile time, so those parts *are* set up before the test stuff starts running. Either move the packages up before the tests, or wrap the packages in a BEGIN block. (Unrelated, but indirect method calls are evil! Stop that!) -doy