| 1 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | package App::Whiff 0.008; | ||||||||||||||||||||||||||||
| 4 | # ABSTRACT: find the first executable of a series of alternatives | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use File::Which (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | #pod =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 9 | #pod | ||||||||||||||||||||||||||||
| 10 | #pod This module implements logic used by the F<whiff> command, which takes a number | ||||||||||||||||||||||||||||
| 11 | #pod of command names and returns the first one that exists and is executable. | ||||||||||||||||||||||||||||
| 12 | #pod | ||||||||||||||||||||||||||||
| 13 | #pod =method find_first | ||||||||||||||||||||||||||||
| 14 | #pod | ||||||||||||||||||||||||||||
| 15 | #pod my $filename = App::Whiff->find_first(\@names); | ||||||||||||||||||||||||||||
| 16 | #pod | ||||||||||||||||||||||||||||
| 17 | #pod Given an arrayref of command names (which should I<not> be anything other than | ||||||||||||||||||||||||||||
| 18 | #pod base filename), this method either returns an absolute path to the first of the | ||||||||||||||||||||||||||||
| 19 | #pod alternatives found in the path (using L<File::Which>) or false. | ||||||||||||||||||||||||||||
| 20 | #pod | ||||||||||||||||||||||||||||
| 21 | #pod =cut | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 0 | ▶ | sub find_first { | ||||||||||||||||||||||||||
|
Subroutine
find_first: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 24 | 0 | my ($self, $names) = @_; | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 0 | my $file; | |||||||||||||||||||||||||||
| 27 | 0 | for my $name (@$names) { | |||||||||||||||||||||||||||
| 28 | 0 | ▶ | return $name if $name =~ m{\A/} && -x $name; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$name =~ m[\A/] and -x $name
MC/DC0%0/2
$name =~ m[\A/] and -x $name
$name =~ m[\A/]
-x $name
Truth table0%0/3
A and B
A= $name =~ m[\A/]B= -x $name
| |||||||||||||||||||||||||||||
| 29 | 0 | $file = File::Which::which($name); | |||||||||||||||||||||||||||
| 30 | 0 | ▶ | return $file if $file; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 0 | return; | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | #pod =method run | ||||||||||||||||||||||||||||
| 37 | #pod | ||||||||||||||||||||||||||||
| 38 | #pod This method is called by the F<whiff> program to ... well, run. | ||||||||||||||||||||||||||||
| 39 | #pod | ||||||||||||||||||||||||||||
| 40 | #pod =cut | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 0 | ▶ | sub run { | ||||||||||||||||||||||||||
|
Subroutine
run: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 43 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 0 | ▶ | die "usage: whiff <command ...>\n" unless @ARGV; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 0 | my $file = $self->find_first([ @ARGV ]); | |||||||||||||||||||||||||||
| 47 | 0 | ▶ | die "no alternative found\n" unless $file; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | 0 | print "$file\n"; | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 1 | 1; | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | __END__ | ||||||||||||||||||||||||||||