File Coverage

lib/Bio/MLST/Validate/Executable.pm
Criterion Covered Total %
statement 25 25 100.0
branch 10 10 100.0
condition 3 3 100.0
subroutine 5 5 100.0
pod 1 2 50.0
total 44 45 97.7


line stmt bran cond sub pod time code
1             package Bio::MLST::Validate::Executable;
2             $Bio::MLST::Validate::Executable::VERSION = '2.1.1706216';
3             # ABSTRACT: Validates the executable is available in the path before running it.
4              
5              
6 18     18   85940 use Moose;
  18         292468  
  18         89  
7 18     18   80958 use File::Which;
  18         11267  
  18         3026  
8              
9             sub does_executable_exist
10             {
11 36     36 1 43 my($self, $executable) = @_;
12 36 100 100     738 if (defined $executable and -x $executable) {
    100          
13 10         20 return 1;
14             } elsif ( which($executable) ) {
15 2         135 return 1;
16             } else {
17 24         2484 return 0;
18             }
19             }
20              
21             sub preferred_executable
22             {
23 17     17 0 2542 my($self, $executable, $defaults) = @_;
24 17 100       26 if ($self->does_executable_exist($executable)) {
25 7         23 return $executable;
26             }
27 10 100       19 if (defined $executable) {
28 5         47 warn "Could not find executable '".$executable."', attempting to use defaults\n";
29             }
30 10         25 for my $default (@{$defaults}) {
  10         14  
31 11 100       16 if ($self->does_executable_exist($default)) {
32 5         18 return $default;
33             }
34             }
35 5         7 die "Could not find any usable default executables in '".join(", ", @{$defaults})."'\n";
  5         34  
36             }
37              
38 18     18   93 no Moose;
  18         21  
  18         102  
39             __PACKAGE__->meta->make_immutable;
40             1;
41              
42             __END__
43              
44             =pod
45              
46             =encoding UTF-8
47              
48             =head1 NAME
49              
50             Bio::MLST::Validate::Executable - Validates the executable is available in the path before running it.
51              
52             =head1 VERSION
53              
54             version 2.1.1706216
55              
56             =head1 SYNOPSIS
57              
58             Validates the executable is available in the path before running it.
59              
60             use Bio::MLST::Validate::Executable;
61             Bio::MLST::Validate::Executable
62             ->new()
63             ->does_executable_exist('abc');
64              
65             =head1 METHODS
66              
67             =head2 does_executable_exist
68              
69             Check to see if an executable is available in the current users PATH.
70              
71             =head1 AUTHOR
72              
73             Andrew J. Page <ap13@sanger.ac.uk>
74              
75             =head1 COPYRIGHT AND LICENSE
76              
77             This software is Copyright (c) 2012 by Wellcome Trust Sanger Institute.
78              
79             This is free software, licensed under:
80              
81             The GNU General Public License, Version 3, June 2007
82              
83             =cut