File Coverage

blib/lib/Devel/CheckBin.pm
Criterion Covered Total %
statement 36 42 85.7
branch 6 10 60.0
condition 3 6 50.0
subroutine 9 9 100.0
pod 0 2 0.0
total 54 69 78.2


line stmt bran cond sub pod time code
1             package Devel::CheckBin;
2 3     3   27944 use strict;
  3         5  
  3         91  
3 3     3   9 use warnings;
  3         4  
  3         60  
4 3     3   55 use 5.008001;
  3         7  
  3         122  
5             our $VERSION = "0.03";
6 3     3   1109 use parent qw(Exporter);
  3         649  
  3         10  
7              
8             our @EXPORT = qw(can_run check_bin);
9              
10 3     3   1954 use ExtUtils::MakeMaker;
  3         195963  
  3         351  
11 3     3   18 use File::Spec;
  3         4  
  3         41  
12 3     3   9 use Config;
  3         3  
  3         579  
13              
14             # Check if we can run some command
15             sub can_run {
16 4     4 0 454 my ($cmd) = @_;
17              
18 4         5 my $_cmd = $cmd;
19 4 50 33     69 return $_cmd if (-x $_cmd or $_cmd = MM->maybe_command($_cmd));
20              
21 4         99 for my $dir ((split /$Config::Config{path_sep}/, $ENV{PATH}), '.') {
22 26 50       234 next if $dir eq '';
23 26         423 my $abs = File::Spec->catfile($dir, $cmd);
24 26 100 66     238 return $abs if (-x $abs or $abs = MM->maybe_command($abs));
25             }
26              
27 1         10 return;
28             }
29              
30             sub check_bin {
31 1     1 0 752 my ( $bin, $version) = @_;
32 1 50       3 if ( $version ) {
33 0         0 die "check_bin does not support versions yet";
34             }
35              
36             # Locate the bin
37 1         3 print "Locating bin:$bin...";
38 1         2 my $found_bin = can_run( $bin );
39 1 50       4 if ( $found_bin ) {
40 1         3 print " found at $found_bin.\n";
41 1         3 return 1;
42             } else {
43 0           print " missing.\n";
44 0           print "Unresolvable missing external dependency.\n";
45 0           print "Please install '$bin' seperately and try again.\n";
46 0           print STDERR "NA: Unable to build distribution on this platform.\n";
47 0           exit(0);
48             }
49             }
50              
51             1;
52             __END__