File: FakeGit.pm

package info (click to toggle)
libtest-requires-git-perl 1.008-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 200 kB
  • sloc: perl: 297; makefile: 2
file content (32 lines) | stat: -rw-r--r-- 692 bytes parent folder | download | duplicates (3)
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;