++ed by:
PLICEASE ZOFFIX PREACTION KWAKWA

4 PAUSE users
1 non-PAUSE user.

Joel Berger
and 1 contributors

NAME

Mojo::Phantom::Process - Represents the running phantom process and its stream

SYNOPSIS

  my $proc = Mojo::Phantom::Process->new;
  $proc->start($file);

DESCRIPTION

A very utilitarian class representing a single execution of the PhantomJS executable. It forks the new process and attaches a stream watcher to its STDOUT and attaches to various stream events. This class is just process management and transport. All real behavior is defined by the executed javascript file and the listeners to the events defined by this class.

EVENTS

Mojo::Phantom::Process inherits all the events from Mojo::EventEmitter and emits the following new ones

close

  $proc->on(close => sub { ($proc) = @_; ... });

Emitted when the process has exitted (possibly with errors) and the stream has closed. The user will want to check "error" and "exit_status".

read

  $proc->on(read => sub { ($proc, $bytes) = @_; ... });

Re-emitted after bytes have been read from the "stream".

spawn

  $proc->on(spawn => sub { my ($proc, $pid) = @_; ... });

Emitted just after the child process is spawned. Passed the new child pid.

ATTRIBUTES

arguments

Holds an array reference of arguments passed directly to the PhantomJS executable when it is run.

  my @phantom_args = ('--proxy=127.0.0.1:8080', '--proxy-type='socks5');
  my $proc = Mojo::Phantom::Process->new(arguments => \@phantom_args);

error

Holds errors caught from the "stream"'s error event. Note that when such an error event is caught, the process is then killed by the "kill" method immediately afterwards.

exit_status

The exit status $? from the closed pid.

pid

The pid of the spawned process. The stream's close event will clear this value once the process has ended.

stream

The instance of Mojo::IOLoop::Stream used to monitor the STDOUT of the external process. It is created automatically attacted to the "singleton" in Mojo::IOLoop by running "start".

exe

The executable name or path to call PhantomJS. You may substitute a compatible platform, for example using casperjs to use CasperJS.

METHODS

kill

  $proc->kill

Kills the child process (KILL) and closes the stream. Note that since the process might exit before the kill signal is sent, it is not guaranteed that the "exit_status" will reflect the signal.

start

  $proc->start($file);

Starts a PhantomJS in a child process running a given file, creates a stream listener and attaches to its events. Returns itself.