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   97192 use strict;
  3         8  
  3         223  
3 3     3   17 use warnings;
  3         7  
  3         91  
4 3     3   222 use 5.008001;
  3         21  
  3         211  
5             our $VERSION = "0.02";
6 3     3   3104 use parent qw(Exporter);
  3         1128  
  3         17  
7              
8             our @EXPORT = qw(can_run check_bin);
9              
10 3     3   5074 use ExtUtils::MakeMaker;
  3         372725  
  3         487  
11 3     3   24 use File::Spec;
  3         6  
  3         49  
12 3     3   13 use Config;
  3         7  
  3         891  
13              
14             # Check if we can run some command
15             sub can_run {
16 4     4 0 1176 my ($cmd) = @_;
17              
18 4         16 my $_cmd = $cmd;
19 4 50 33     96 return $_cmd if (-x $_cmd or $_cmd = MM->maybe_command($_cmd));
20              
21 4         129 for my $dir ((split /$Config::Config{path_sep}/, $ENV{PATH}), '.') {
22 26 50       478 next if $dir eq '';
23 26         238 my $abs = File::Spec->catfile($dir, $cmd);
24 26 100 66     565 return $abs if (-x $abs or $abs = MM->maybe_command($abs));
25             }
26              
27 1         18 return;
28             }
29              
30             sub check_bin {
31 1     1 0 1536 my ( $bin, $version) = @_;
32 1 50       8 if ( $version ) {
33 0         0 die "check_bin does not support versions yet";
34             }
35              
36             # Locate the bin
37 1         9 print "Locating bin:$bin...";
38 1         4 my $found_bin = can_run( $bin );
39 1 50       5 if ( $found_bin ) {
40 1         4 print " found at $found_bin.\n";
41 1         4 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__
53              
54             =for stopwords distro
55              
56             =head1 NAME
57              
58             Devel::CheckBin - check that a command is available
59              
60             =head1 SYNOPSIS
61              
62             use Devel::CheckBin;
63              
64             =head1 DESCRIPTION
65              
66             Devel::CheckBin is a perl module that checks whether a particular command is available.
67              
68             =head1 USING IT IN Makefile.PL or Build.PL
69              
70             If you want to use this from Makefile.PL or Build.PL, do not simply copy the module into your distribution as this may cause problems when PAUSE and search.cpan.org index the distro. Instead, use the 'configure_requires'.
71              
72              
73             =head1 LICENSE
74              
75             Copyright (C) tokuhirom
76              
77             This library is free software; you can redistribute it and/or modify
78             it under the same terms as Perl itself.
79              
80             =head1 AUTHOR
81              
82             tokuhirom E<lt>tokuhirom@gmail.comE<gt>
83