Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Include class takover function from Mock-Quick? #186

Closed
exodist opened this Issue · 4 comments

3 participants

@exodist

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:

TAKING OVER EXISTING/LOADED CLASSES
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
Owner

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

Can't argue with that :-)

@notbenh

should this be closed?

@schwern
Owner

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.