Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Include class takover function from Mock-Quick? #186

exodist opened this Issue · 4 comments

3 participants


Temporarily overriding methods in another class is hap-hazard, it often includes 'no warnings 'redefine'' as well as local and typeglobs. It is also very easy to get wrong leaving you without the ability to restore the original. It is also possible to forget the original.

Mock-Quick has a facility for creating a control object as an interface to a package. It then lets you override and restore methods quickly. Furthermore when the control class is destroyed or falls out of scope the originals are restored automatically.

From the Mock-Quick docs:

use Mock::Quick;

    my $control = qtakeover 'Some::Package' => ( %overrides );

    # Override a method
    $control->override( foo => sub { ... });

    # Restore it to the original
    $control->restore( 'foo' );

    # Destroy the control object and completely restore the original class Some::Package.
    $control = undef;

Importing this function (perhaps under a different name) could be useful. Other functions from Mock-Quick are probably not as useful outside of testing


I'm not convinced this is needed in perl5i. It's neat, but it's not something want to be doing very often, is a questionable practice outside of testing and it doesn't blend with anything else in perl5i.


Can't argue with that :-)


should this be closed?


No activity for two years, pretty firm conclusion. If anyone wants to re-propose it can be reopened.

@schwern schwern closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.