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

Yep, excellent plan. Doing so now.
  • Comment on Re^2: Testing -- making a new constructor behave differently for one package

Replies are listed 'Best First'.
Re^3: Testing -- making a new constructor behave differently for one package
by tj_thompson (Monk) on Jan 27, 2012 at 23:45 UTC
    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.

        FWIW, that is a solution, not an explanation :)