exodist/Mock-Quick — Issue #9: Accessing original method in override
Author: imoan
Created: 2011-12-12 15:31:04+00:00
State: open

It seems I can't access the 'original' method from within a mocked method.

An example of what I would like:

```
use Mock::Quick;

my $controller = Mock::Quick::Class->takeover('DBIx::Class::ResultSet');
$controller->override( new => sub {
my $class = shift;
……
$class->ORIGINAL::new # call the original DBIx::Class::ResultSet::new method
});
```
If I've read the code correctly the original method is stashed on the control object. It seems the only way to gain access to it is via a dirty closure(*1).

use Mock::Quick;

my $controller = Mock::Quick::Class->takeover('DBIx::Class::ResultSet');
$controller->override( new => sub {} ); # Just so that the original method is stashed on object

# override method again as now 'original' method is now in scope.
# Thank goodness there's protection for this in the code!
$controller->override( new => sub {my $class = shift; ....... $controller->{'new'}(@_) } );

(*1) closures aren't dirty but that one was :)