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

I wrote about the way I solve this problem in You're Already Using Dependency Injection. In short, rather than hardcoding the name of a class to construct within your constructor, make the constructed object parametric—whether from passing an allomorphic equivalent to the constructor, using the default object, or overriding the accessor/builder from a subclass.


Improve your skills with Modern Perl: the free book.

  • 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 23:39 UTC
    Actually the name of the class I'm using is not hardcoded, and I believe the accessor where I get the name of the package to use might be an easier point to hijack the object creation instead of the actual new method. Thanks Chromatic!