BinaryModeBuilder.pm 648 B

123456789101112131415161718192021222324252627282930313233
  1. package Selenium::BinaryModeBuilder;
  2. # ABSTRACT: Role to teach a class how to enable its binary
  3. use Selenium::Binary qw/start_binary_on_port/;
  4. use Try::Tiny;
  5. use Moo::Role;
  6. has 'binary_mode' => (
  7. is => 'ro',
  8. init_arg => undef,
  9. builder => 1
  10. );
  11. sub _build_binary_mode {
  12. my ($self) = @_;
  13. if (! $self->has_remote_server_addr && ! $self->has_port) {
  14. try {
  15. my $port = start_binary_on_port($self->binary_name, $self->binary_port);
  16. $self->port($port);
  17. return 1;
  18. }
  19. catch {
  20. warn $_;
  21. return 0;
  22. }
  23. }
  24. else {
  25. return 0;
  26. }
  27. }
  28. 1;