Alien-Selenium

 view release on metacpan or  search on metacpan

Build.PL  view on Meta::CPAN


    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;
      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");



( run in 0.476 second using v1.01-cache-2.11-cpan-f0fbb3f571b )