Alien-Selenium
view release on metacpan or search on metacpan
'Test::More' => 0,
'Archive::Zip' => 1.00,
},
create_makefile_pl => 'passthrough',
);
$build->create_build_script;
warn sprintf("Will build Alien::Selenium with selenium version %s\n",
$build->option_value("selenium_version"));
__END__
=head1 DESCRIPTION
This is a custom-made subclass to My::Module::Build that knows how to
build Alien::Selenium. Its package name is a nonce chosen by
L<Module::Build>.
=cut
use strict;
use base qw(My::Module::Build);
=head1 COMMAND-LINE OPTIONS
=head2 --selenium-version <version>
The Selenium version that one wishes to package. By default, will use
whatever is the current value of the variable $SELENIUM_VERSION in
L<Alien::Selenium>'s source code.
=cut
sub selenium_version : Config_Option(type="string") {
# 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);
( run in 1.419 second using v1.01-cache-2.11-cpan-13bb782fe5a )