Include class takover function from Mock-Quick? #186

exodist opened this Issue Apr 3, 2011 · 4 comments


None yet

3 participants

exodist commented Apr 3, 2011

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

schwern commented Apr 3, 2011

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.

exodist commented Apr 3, 2011

Can't argue with that :-)

notbenh commented Mar 8, 2013

should this be closed?

schwern commented Mar 8, 2013

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

@schwern schwern closed this Mar 8, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment