1
0

FindBinary.pm 1.5 KB

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