in reply to Testing -- making a new constructor behave differently for one package

I don't see the recursing happening here. I am uncertain as to why the difference, but I'm guessing it has something to do with RapTTR being a Moose module and the way the new method is created for it.

Well, the next step would be to make Foo a moose class, ie make Foo fail the same way as your real class

  • Comment on Re: Testing -- making a new constructor behave differently for one package

Replies are listed 'Best First'.
Re^2: Testing -- making a new constructor behave differently for one package
by tj_thompson (Monk) on Jan 27, 2012 at 22:54 UTC
    Yep, excellent plan. Doing so now.
      Updated the thread above. The problem does show up in a Moose test case. So my question is...why?

        To simplify (read: lie about what's happening) the explanation: you need to get at the overridden method without going to the typeglob. You can achieve that with the even uglier:

        no warnings 'redefine'; my $real_new; BEGIN { $real_new = Foo->can( 'new' ) } *Foo::new = sub { if (caller() eq 'Bar') { print "Returning real Foo.\n"; return Foo->$real_new(); } print "Returning fake Foo.\n"; return FakeFoo->new; };

        ... to force the lookup to happen before the glob replacement, but don't do that. Remove that caller magic from the constructor and make it an external parameter. You're far better off that way.