Alien-Selenium
view release on metacpan or search on metacpan
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;
mkdir($target_dir) unless -d $target_dir;
chdir($target_dir);
# Also, Archive::Zip is stupid.
$zip = Archive::Zip->new( catfile($origdir, $selenium_archive) );
}
$zip->extractTree() == Archive::Zip::AZ_OK() or
die "Error extracting file $selenium_archive\n";
chdir($origdir);
return;
}
=head2 install_selenium
Copies select bits of the unpacked copy of Selenium into blib/lib/, so
that they get embedded into the Alien::Selenium Perl package.
=cut
sub install_selenium {
my $self = shift;
print "Installing Selenium...\n";
my $srcdir = $self->selenium_directory;
{
my $selenium_installdir =
catdir(qw(blib lib Alien Selenium javascript));
rmtree($selenium_installdir); mkpath($selenium_installdir);
my @seleniumfiles = grep { -f $_ }
( glob(catfile($srcdir, "selenium", "*")), # Before 0.7.0
glob(catfile($srcdir, "core", "*")) ); # After
foreach my $file ( @seleniumfiles ) {
my $dest = catfile( $selenium_installdir, basename( $file ) );
$self->copy_if_modified( from => $file,
to => $dest,
verbose => 1,
);
}
}
{
mkpath ( my $xpi_installdir =
catdir(qw(blib lib Alien Selenium xpi)) );
my @xpifiles = 'readyState.xpi';
foreach my $file ( @xpifiles ) {
my $src = catfile ($srcdir, $file);
warn "Cannot find $file in $srcdir, skipping", next
if (! -f $src);
my $dest = catfile ( $xpi_installdir, $file );
$self->copy_if_modified( from => $src,
to => $dest,
verbose => 1,
);
}
}
}
=head1 UTILITY METHODS
=cut
=head2 selenium_archive_basename()
Returns the basename of the Selenium zipball with version number,
e.g. C<selenium-0.x> or C<selenium-core-0.x>
=cut
sub selenium_archive_basename {
my ($self) = @_;
if ($self->option_value("selenium_version") lt '0.7') {
return 'selenium-' . $self->option_value("selenium_version");
} else {
return 'selenium-core-' . $self->option_value("selenium_version");
}
}
=head2 selenium_archive()
Returns the full name of the Selenium zipball,
e.g. C<selenium-0.x.zip>
=cut
sub selenium_archive {
my ($self) = @_;
return $self->selenium_archive_basename . ".zip";
}
=head2 selenium_url()
( run in 0.806 second using v1.01-cache-2.11-cpan-119454b85a5 )