Alien-Build
view release on metacpan or search on metacpan
lib/Alien/Build/CommandSequence.pm view on Meta::CPAN
$meta->add_requires($phase, $intr->requires($command));
}
}
$self;
}
my %built_in = (
cd => sub {
my(undef, $dir) = @_;
if(!defined $dir)
{
die "undef passed to cd";
}
elsif(-d $dir)
{
chdir($dir) || die "unable to cd $dir $!";
}
else
{
die "unable to cd $dir, does not exist";
}
},
);
sub _run_list
{
my($build, @cmd) = @_;
$build->log("+ @cmd");
return $built_in{$cmd[0]}->(@cmd) if $built_in{$cmd[0]};
system @cmd;
die "external command failed" if $?;
}
sub _run_string
{
my($build, $cmd) = @_;
$build->log("+ $cmd");
{
my $cmd = $cmd;
$cmd =~ s{\\}{\\\\}g if $^O eq 'MSWin32';
my @cmd = shellwords($cmd);
return $built_in{$cmd[0]}->(@cmd) if $built_in{$cmd[0]};
}
system $cmd;
die "external command failed" if $?;
}
sub _run_with_code
{
my($build, @cmd) = @_;
my $code = pop @cmd;
$build->log("+ @cmd");
my %args = ( command => \@cmd );
if($built_in{$cmd[0]})
{
my $error;
($args{out}, $args{err}, $error) = capture {
eval { $built_in{$cmd[0]}->(@cmd) };
$@;
};
$args{exit} = $error eq '' ? 0 : 2;
$args{builtin} = 1;
}
else
{
($args{out}, $args{err}, $args{exit}) = capture {
system @cmd; $?
};
}
$build->log("[output consumed by Alien::Build recipe]");
$code->($build, \%args);
}
sub _apply
{
my($where, $prop, $value) = @_;
if($where =~ /^(.*?)\.(.*?)$/)
{
_apply($2, $prop->{$1}, $value);
}
else
{
$prop->{$where} = $value;
}
}
sub execute
{
my($self, $build) = @_;
my $intr = $build->meta->interpolator;
foreach my $command (@{ $self->{commands} })
{
if(ref($command) eq 'CODE')
{
$command->($build);
}
elsif(ref($command) eq 'ARRAY')
{
my($command, @args) = @$command;
my $code;
$code = pop @args if $args[-1] && ref($args[-1]) eq 'CODE';
if($args[-1] && ref($args[-1]) eq 'SCALAR')
{
my $dest = ${ pop @args };
if($dest =~ /^\%\{((?:alien|)\.(?:install|runtime|hook)\.[a-z\.0-9_]+)\}$/)
{
$dest = $1;
$dest =~ s/^\./alien./;
$code = sub {
my($build, $args) = @_;
die "external command failed" if $args->{exit};
my $out = $args->{out};
chomp $out;
_apply($dest, $build->_command_prop, $out);
};
}
else
{
( run in 0.380 second using v1.01-cache-2.11-cpan-efa8479b9fe )