package Shell::DWIM; use warnings; use strict; our ($EVAL_ERROR, $CHILD_ERROR, $OS_ERROR, $RUN_ERROR); #Setup internal friendly error names *EVAL_ERROR = \$@; *CHILD_ERROR = \$?; if ($^O =~ /VMS|MSWin|OS\/2/) { #These systems support an extended OS error message ($^E) *OS_ERROR = \$^E; #$OS_ERROR reflects that value if it exists. This clashes somwhat with English.pm } else { *OS_ERROR = \$!; } #The public function sub run { my ($return) = 0; local $EVAL_ERROR; #The eval here is a little unexpected, so we localize $EVAL_ERROR so no one get's bitten eval { $return = (( system @_ ) == 0); }; if ($return) { $RUN_ERROR = undef; } else { SWITCH: { do { $RUN_ERROR = $EVAL_ERROR && last SWITCH } if $EVAL_ERROR ; do { $RUN_ERROR = $CHILD_ERROR && last SWITCH } if $CHILD_ERROR > 0 ; do { $RUN_ERROR = "$OS_ERROR" && last SWITCH } if $CHILD_ERROR == -1; #String version of $OS_ERROR LAST_CASE: { $RUN_ERROR = "Exception, package CommandLine: system() failed, error unknown"} } } return $return; } 1; #Because you gotta