# ex:ts=8 sw=4:
-# $OpenBSD: State.pm,v 1.27 2014/03/18 18:53:29 espie Exp $
+# $OpenBSD: State.pm,v 1.28 2014/05/20 05:43:55 espie Exp $
#
# Copyright (c) 2007-2014 Marc Espie <espie@openbsd.org>
#
sub _system
{
- my ($self, $todo, $todo2, @r) = @_;
+ my $self = shift;
my $r = fork;
+ my ($todo, $todo2);
+ if (ref $_[0] eq 'CODE') {
+ $todo = shift;
+ } else {
+ $todo = sub {};
+ }
+ if (ref $_[0] eq 'CODE') {
+ $todo2 = shift;
+ } else {
+ $todo2 = sub {};
+ }
if (!defined $r) {
return 1;
} elsif ($r == 0) {
&$todo;
- exec {$r[0]} @r or return 1;
+ exec {$_[0]} @_ or return 1;
} else {
&$todo2;
waitpid($r, 0);
sub system
{
my $self = shift;
- my ($todo, $todo2);
- if (ref $_[0] eq 'CODE') {
- $todo = shift;
- } else {
- $todo = sub {};
- }
- if (ref $_[0] eq 'CODE') {
- $todo2 = shift;
- } else {
- $todo2 = sub {};
- }
- my $r = $self->_system($todo, $todo2, @_);
+ my $r = $self->_system(@_);
if ($r != 0) {
$self->say("system(#1) failed: #2",
join(", ", @_), $self->child_error);
sub verbose_system
{
my $self = shift;
- my $todo;
- if (ref $_[0] eq 'CODE') {
- $todo = shift;
- } else {
- $todo = sub {};
- }
$self->print("Running #1", join(' ', @_));
- my $r = $self->_system($todo, @_);
+ my $r = $self->_system(@_);
if ($r != 0) {
$self->say("... failed: #1", $self->child_error);
} else {