Mojo::Phantom::Process - Represents the running phantom process and its stream
my $proc = Mojo::Phantom::Process->new; $proc->start($file);
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.
Mojo::Phantom::Process inherits all the events from Mojo::EventEmitter and emits the following new ones
$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".
$proc->on(read => sub { ($proc, $bytes) = @_; ... });
Re-emitted after bytes have been read from the "stream".
$proc->on(spawn => sub { my ($proc, $pid) = @_; ... });
Emitted just after the child process is spawned. Passed the new child pid.
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);
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.
The exit status $? from the closed pid.
$?
The pid of the spawned process. The stream's close event will clear this value once the process has ended.
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".
The executable name or path to call PhantomJS. You may substitute a compatible platform, for example using casperjs to use CasperJS.
casperjs
$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.
$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.
To install Mojo::Phantom, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mojo::Phantom
CPAN shell
perl -MCPAN -e shell install Mojo::Phantom
For more information on module installation, please visit the detailed CPAN module installation guide.