1
0

FindBinary.pm 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package Selenium::CanStartBinary::FindBinary;
  2. # ABSTRACT: Coercions for finding webdriver binaries on your system
  3. use File::Which qw/which/;
  4. use Cwd qw/abs_path/;
  5. use File::Which qw/which/;
  6. use IO::Socket::INET;
  7. use Selenium::Firefox::Binary qw/firefox_path/;
  8. require Exporter;
  9. our @ISA = qw/Exporter/;
  10. our @EXPORT_OK = qw/coerce_simple_binary coerce_firefox_binary/;
  11. use constant IS_WIN => $^O eq 'MSWin32';
  12. sub coerce_simple_binary {
  13. my ($executable) = @_;
  14. my $manual_binary = _validate_manual_binary($executable);
  15. if ($manual_binary) {
  16. return $manual_binary;
  17. }
  18. else {
  19. return _naive_find_binary($executable);
  20. }
  21. }
  22. sub _validate_manual_binary {
  23. my ($executable) = @_;
  24. my $abs_executable = eval {
  25. my $path = abs_path($executable);
  26. die unless -e $path;
  27. $path
  28. };
  29. if ( $abs_executable ) {
  30. if ( -x $abs_executable || IS_WIN ) {
  31. return $abs_executable;
  32. }
  33. else {
  34. die 'The binary at ' . $executable . ' is not executable. Choose the correct file or chmod +x it as needed.';
  35. }
  36. }
  37. }
  38. sub _naive_find_binary {
  39. my ($executable) = @_;
  40. my $naive_binary = which($executable);
  41. if (defined $naive_binary) {
  42. return $naive_binary;
  43. }
  44. else {
  45. warn qq(Unable to find the $executable binary in your \$PATH. We'll try falling back to standard Remote Driver);
  46. return;
  47. }
  48. }