1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
package FakeGit;
use strict;
use warnings;
# Test::Requires::Git must have been loaded already
BEGIN {
require Test::Requires::Git
if !$INC{'Test/Requires/Git.pm'};
}
# import to build one fake git at compile time
sub import {
my $package = shift;
my $caller = caller(0);
no strict 'refs';
*{"$caller\::fake_git"} = \&fake_git;
fake_git(shift) if @_;
}
# helper routine to build a fake fit binary
sub fake_git {
my ($version) = @_;
$version =~ s/^(?=[0-9])/git version /;
# monkey patch the code that returns git version
no strict 'refs';
no warnings 'redefine';
*{'Test::Requires::Git::_git_version'} = sub { "$version\n" };
}
1;
|