Re: There is something about namespaces!
On Wed, Jun 16, 2010 at 03:11:34PM -0700, Kate Yoak wrote: > > (Unrelated, but indirect method calls are evil! Stop that!) > > > Indirect method calls? Whatever do you mean? > my $one = new Foo::Child; This should be my $one = Foo::Child->new; See http://www.shadowcat.co.uk/blog/matt-s-trout/indirect-but-still-fatal/ and http://search.cpan.org/~vpit/indirect-0.21/lib/indirect.pm for an explanation. - doy
Re: There is something about namespaces!
> > '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. HEY! That actually makes sense! That's nice. :-) > > (Unrelated, but indirect method calls are evil! Stop that!) > Indirect method calls? Whatever do you mean?
Re: There is something about namespaces!
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
There is something about namespaces!
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!