Import Upstream version 1.8.5
[hcoop/debian/openafs.git] / src / tests / OpenAFS / ConfigUtils.pm
1 # This is -*- perl -*-
2
3 package OpenAFS::ConfigUtils;
4
5 use strict;
6 use vars qw( @ISA @EXPORT @unwinds $debug);
7 @ISA = qw(Exporter);
8 require Exporter;
9 @EXPORT = qw(@unwinds run unwind);
10
11 $debug = 0;
12
13 #--------------------------------------------------------------------
14 # run(cmd) - run a command. Takes a command to be executed or
15 # a perl code reference to be eval'd.
16 sub run($) {
17 my $cmd = shift;
18 if (ref($cmd) eq 'CODE') {
19 eval { &$cmd };
20 if ($@) {
21 die "ERROR: $@\n";
22 }
23 }
24 else {
25 if ($debug) {
26 print "debug: $cmd\n";
27 }
28 my $rc = system($cmd);
29 unless ($rc==0) {
30 die "ERROR: Command failed: $cmd\nerror code=$?\n";
31 }
32 }
33 }
34
35 # This subroutine takes a command to run in case of failure. After
36 # each succesful step, this routine should be run with a command to
37 # undo the successful step.
38 sub unwind($) {
39 push @unwinds, $_[0];
40 }
41
42 1;