File Coverage

blib/lib/Module/Build/Database/Helpers.pm
Criterion Covered Total %
statement 27 41 65.8
branch 8 26 30.7
condition 2 14 14.2
subroutine 5 8 62.5
pod 0 4 0.0
total 42 93 45.1


line stmt bran cond sub pod time code
1             package Module::Build::Database::Helpers;
2 6     6   32 use strict;
  6         9  
  6         143  
3 6     6   22 use warnings;
  6         12  
  6         198  
4             our $VERSION = '0.58';
5              
6 6     6   2116 use File::Which qw( which );
  6         4327  
  6         294  
7              
8 6         47 use Sub::Exporter -setup => {
9             exports => [
10             qw/do_system verify_bin info debug/
11             ]
12 6     6   2498 };
  6         44360  
13              
14 0 0   0 0 0 sub info($) { print STDERR shift(). "\n" unless $ENV{MBD_QUIET}; }
15 0 0   0 0 0 sub debug($) { print STDERR shift(). "\n" if $ENV{MBD_DEBUG}; }
16              
17             sub do_system {
18 0 0   0 0 0 my $silent = ($_[0] eq '_silent' ? shift : 0);
19 0         0 my $cmd = $_[0];
20 0 0 0     0 if ($ENV{MBD_FAKE} || $ENV{MBD_DEBUG}) {
21 0         0 info "fake: system call : @_";
22 0 0       0 return if $ENV{MBD_FAKE};
23             }
24             # Carp::cluck("doing------- @_\n");
25             system("@_") == 0
26 0 0       0 or do {
27 0 0 0     0 return 0 if $silent && !$ENV{HARNESS_ACTIVE};
28 0   0     0 warn "# Error with '@_' : $? " . ( ${^CHILD_ERROR_NATIVE} || '' ) . "\n";
29 0         0 return 0;
30             };
31 0         0 return 1;
32             }
33              
34             sub verify_bin {
35 6     6 0 13 my $bin = shift;
36 6         12 my $try = shift;
37 6         25 for my $label (keys %$bin) {
38 34 100       101 my @look_for = (ref $bin->{$label} eq 'ARRAY' ? @{ $bin->{$label} } : $bin->{$label});
  4         12  
39 34         44 my $found;
40 34         45 for my $potential_cmd (@look_for) {
41 38 50 33     699 if(defined $try && -x "$try/$potential_cmd") {
42 0         0 $found = "$try/$potential_cmd";
43 0         0 last;
44             }
45 38 50       94 last if $found = which $potential_cmd;
46             }
47 34 50       4951 unless ($found) {
48 34 100       839 warn "could not find ".(join " or ",@look_for)." in current path\n" unless $label =~ /doc/;
49 34         100 $found = "/bin/false";
50             }
51 34         51 chomp $found;
52 34 50 33     110 $found = Win32::GetShortPathName($found) if $^O eq 'MSWin32' && $found =~ /\s/;
53 34         90 $bin->{$label} = $found;
54             }
55             }
56              
57              
58             1;
59              
60