File Coverage

blib/lib/Devel/CheckBin.pm
Criterion Covered Total %
statement 35 41 85.3
branch 6 10 60.0
condition 3 6 50.0
subroutine 9 9 100.0
pod 0 2 0.0
total 53 68 77.9


line stmt bran cond sub pod time code
1             package Devel::CheckBin;
2 3     3   50966 use strict;
  3         6  
  3         114  
3 3     3   16 use warnings;
  3         5  
  3         99  
4 3     3   84 use 5.008001;
  3         20  
5             our $VERSION = "0.04";
6 3     3   1779 use parent qw(Exporter);
  3         1041  
  3         18  
7              
8             our @EXPORT = qw(can_run check_bin);
9              
10 3     3   2853 use ExtUtils::MakeMaker;
  3         340048  
  3         464  
11 3     3   41 use File::Spec;
  3         5  
  3         68  
12 3     3   14 use Config;
  3         5  
  3         801  
13              
14             # Check if we can run some command
15             sub can_run {
16 4     4 0 1120 my ($cmd) = @_;
17              
18 4         8 my $_cmd = $cmd;
19 4 50 33     108 return $_cmd if (-x $_cmd or $_cmd = MM->maybe_command($_cmd));
20              
21 4         131 for my $dir ((split /$Config::Config{path_sep}/, $ENV{PATH}), '.') {
22 26 50       339 next if $dir eq '';
23 26         217 my $abs = File::Spec->catfile($dir, $cmd);
24 26 100 66     619 return $abs if (-x $abs or $abs = MM->maybe_command($abs));
25             }
26              
27 1         16 return;
28             }
29              
30             sub check_bin {
31 1     1 0 957 my ( $bin, $version) = @_;
32 1 50       4 if ( $version ) {
33 0         0 die "check_bin does not support versions yet";
34             }
35              
36             # Locate the bin
37 1         4 print "Locating bin:$bin...";
38 1         3 my $found_bin = can_run( $bin );
39 1 50       4 if ( $found_bin ) {
40 1         3 print " found at $found_bin.\n";
41 1         5 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