Created
November 18, 2010 11:38
-
-
Save wchristian/704881 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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