#!/usr/bin/perl -w
use strict;
use WWW::Mechanize::PhantomJS;
my $mech = WWW::Mechanize::PhantomJS->new();
$mech->get('http://google.com');
$mech->eval_in_page('alert("Hello PhantomJS")');
my $png= $mech->content_as_png();
####
Can't exec "phantomjs": No such file or directory at /home/tel2/perl5/lib/perl5/WWW/Mechanize/PhantomJS.pm line 101.
Couldn't launch [| phantomjs /home/tel2/perl5/lib/perl5/WWW/Mechanize/PhantomJS/ghostdriver/main.js --PhantomJS=8910 --logLevel=OFF]: No such file or directory / 0 at /home/tel2/perl5/lib/perl5/WWW/Mechanize/PhantomJS.pm line 101.
####
# Launch PhantomJs
$options{ launch_exe } ||= 'phantomjs';
(my $ghostdir_default= __FILE__) =~ s!\.pm$!!;
$ghostdir_default= File::Spec->catfile( $ghostdir_default, 'ghostdriver', 'main.js' );
$options{ launch_ghostdir } ||= $ghostdir_default;
$options{ launch_arg } ||= [];
push @{ $options{ launch_arg }}, "--PhantomJS=$options{ port }";
push @{ $options{ launch_arg }}, "--logLevel=\U$options{ log }";
my $cmd= "| $options{ launch_exe } $options{ launch_ghostdir } @{ $options{ launch_arg } }";
#warn $cmd;
$options{ pid } ||= open my $fh, $cmd
or die "Couldn't launch [$cmd]: $! / $?";