Skip to content

Instantly share code, notes, and snippets.

@wchristian
Created November 18, 2010 11:38
Show Gist options
  • Save wchristian/704881 to your computer and use it in GitHub Desktop.
Save wchristian/704881 to your computer and use it in GitHub Desktop.
use strict;
use warnings;
package Class::Mock;
use Sub::Install;
sub import {
my ( $self, $target, $sub_masks ) = @_;
my $mock_class = caller();
( my $name = "$target.pm" ) =~ s/::/\//g;
$INC{$name} = 1;
{
no strict 'refs';
push @{"$target\::ISA"}, $mock_class;
}
Sub::Install::install_sub({ code => $sub_masks->{$_}, into => $target, as => "$_" }) for keys %{$sub_masks};
return;
}
1;
use strict;
use warnings;
package something::mock;
use SUPER;
use lib '../../../lib';
use Class::Mock something => {
new => sub {
my ( $class ) = @_;
my $obj = $class->super('new')->( @_ );
return $obj if $obj->message;
return;
}
};
sub new { return bless {}, $_[0]; }
sub message { 1 }
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment