Alien-Selenium
view release on metacpan or search on metacpan
# Warning, single quotes don't work in the Win32 shell, see RT #28048
my $version = `$^X -Ilib -MAlien::Selenium -e "print Alien::Selenium->version"`;
die "Problem invoking Alien::Selenium in a sub-Perl" if $?;
chomp($version);
return (default => $version);
}
=head1 INTERNAL METHODS
=cut
use File::Path qw(mkpath rmtree);
use File::Basename qw(basename);
use File::Spec::Functions qw(catdir catfile);
use Fatal qw(mkdir);
=head2 ACTION_code
Overloaded from L<Module::Build> so as to also L</fetch_selenium>,
L</extract_selenium> and/or L</install_selenium>.
=cut
sub ACTION_code {
my $self = shift;
$self->SUPER::ACTION_code;
$self->fetch_selenium;
$self->extract_selenium;
$self->install_selenium;
}
=head2 process_pm_files
Overloaded from parent class so as to reserve a special treatment to
L<Alien::Selenium>; namely, the value of $SELENIUM_VERSION is changed
in place to reflect that of the L<--selenium-version> command-line
switch.
=cut
sub process_pm_files {
my ($self) = @_;
$self->SUPER::process_pm_files(@_);
my $from = catfile(qw(lib Alien Selenium.pm));
my $todir = catdir(qw(blib lib Alien));
unless (-d $todir) {
mkpath($todir) or die "Cannot create path $todir: $!";
}
my $tofile = catfile($todir, "Selenium.pm");
unlink($tofile);
my $infd = new IO::File($from, "<") or
die "Cannot open $from for reading: $!";
my $text = join('', <$infd>);
$infd->close();
my $version = $self->option_value("selenium_version");
$text =~ s|^our.*\$SELENIUM_VERSION.*$|our \$SELENIUM_VERSION = '$version';|m;
my $outfd = new IO::File($tofile, ">") or
die "Cannot open $tofile for writing: $!";
($outfd->print($text) &&
$outfd->close()) or
die "Cannot write to $tofile: $!\n";
}
=head2 fetch_selenium
As the name implies, fetches Selenium over the interweb. Does nothing
if the Selenium zipball is already here.
=cut
sub fetch_selenium {
my $self = shift;
return if -f $self->selenium_archive or -d $self->selenium_directory;
require File::Fetch;
printf "Fetching Selenium from %s...\n", $self->selenium_url;
my $path = File::Fetch->new
( uri => $self->selenium_url )->fetch;
die 'Unable to fetch archive' unless $path;
}
=head2 extract_selenium
Unpacks the Selenium zipball.
=cut
sub extract_selenium {
my $self = shift;
my $targetdir = $self->selenium_directory;
return if -d $targetdir;
my $selenium_archive = $self->selenium_archive;
die "$selenium_archive is not present, cannot extract"
if (! -f $selenium_archive);
print "Extracting Selenium...\n";
eval { require Archive::Zip }; die <<"EOT" if $@;
$@
Please either install Archive::Zip or manually extract
the Selenium distribution into $targetdir.
EOT
my $zip = Archive::Zip->new( $selenium_archive );
# Some versions of Selenium Core (eg 0.8.3) spill their beans into the
# current directory, as opposed to using a main directory named after
# the version number :-(.
use Cwd qw(getcwd);
my $origdir = getcwd();
if (grep { m|^core/?$| } $zip->memberNames()) {
my $target_dir = $self->selenium_directory;
( run in 1.111 second using v1.01-cache-2.11-cpan-13bb782fe5a )