File Coverage

blib/lib/Selenium/CanStartBinary/FindBinary.pm
Criterion Covered Total %
statement 21 46 45.6
branch 0 12 0.0
condition 0 5 0.0
subroutine 7 11 63.6
pod 0 2 0.0
total 28 76 36.8


line stmt bran cond sub pod time code
1             package Selenium::CanStartBinary::FindBinary;
2             $Selenium::CanStartBinary::FindBinary::VERSION = '1.47';
3 1     1   6 use strict;
  1         3  
  1         26  
4 1     1   5 use warnings;
  1         2  
  1         25  
5              
6             # ABSTRACT: Coercions for finding webdriver binaries on your system
7 1     1   5 use Cwd qw/abs_path/;
  1         2  
  1         60  
8 1     1   433 use File::Which qw/which/;
  1         984  
  1         56  
9 1     1   462 use IO::Socket::INET;
  1         20352  
  1         8  
10 1     1   1206 use Selenium::Firefox::Binary qw/firefox_path/;
  1         4  
  1         104  
11              
12             require Exporter;
13             our @ISA = qw/Exporter/;
14             our @EXPORT_OK = qw/coerce_simple_binary coerce_firefox_binary/;
15              
16 1     1   6 use constant IS_WIN => $^O eq 'MSWin32';
  1         3  
  1         347  
17              
18              
19             sub coerce_simple_binary {
20 0     0 0   my ($executable) = @_;
21              
22 0           my $manual_binary = _validate_manual_binary($executable);
23 0 0         if ($manual_binary) {
24 0           return $manual_binary;
25             }
26             else {
27 0           return _naive_find_binary($executable);
28             }
29             }
30              
31             sub coerce_firefox_binary {
32 0     0 0   my ($executable) = @_;
33              
34 0           my $manual_binary = _validate_manual_binary($executable);
35 0 0         if ($manual_binary) {
36 0           return $manual_binary;
37             }
38             else {
39 0           return firefox_path();
40             }
41             }
42              
43             sub _validate_manual_binary {
44 0     0     my ($executable) = @_;
45              
46 0           my $abs_executable = eval {
47 0           my $path = abs_path($executable);
48 0 0 0       die if $path && !-f $path;
49 0           $path;
50             };
51              
52 0 0         if ($abs_executable) {
53 0 0 0       if ( -x $abs_executable || IS_WIN ) {
54 0           return $abs_executable;
55             }
56             else {
57 0           die 'The binary at '
58             . $executable
59             . ' is not executable. Choose the correct file or chmod +x it as needed.';
60             }
61             }
62             }
63              
64             sub _naive_find_binary {
65 0     0     my ($executable) = @_;
66              
67 0           my $naive_binary = which($executable);
68 0 0         if ( defined $naive_binary ) {
69 0           return $naive_binary;
70             }
71             else {
72 0           warn qq(Unable to find the $executable binary in your \$PATH.);
73 0           return;
74             }
75             }
76              
77             __END__