| 1 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # Copyright 2005-2008, Sam Vilain. All rights reserved. This program | ||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # is free software; you can use it and/or distribute it under the same | ||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # terms as Perl itself; either the latest stable release of Perl when | ||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # the module was written, or any subsequent stable release. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # | ||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # Please note that this applies retrospectively to all Scriptalicious | ||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | # releases; apologies for the lack of an explicit license. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | package Scriptalicious; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 61 | ▶ | use 5.006; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 61 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 61 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 61 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 52 | our $VERSION = "1.17"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 61 | ▶ | use Getopt::Long; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 61 | ▶ | use base qw(Exporter); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 61 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | # export groups, phtoey! | ||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 61 | our @EXPORT = qw(say mutter whisper abort moan barf run run_err | |||||||||||||||||||||||||||||||||||||||||||||||
| 26 | capture capture_err getopt $VERBOSE $PROGNAME | ||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | $CONFIG | ||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | start_timer show_delta show_elapsed getconf | ||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | getconf_f sci_unit prompt_for prompt_passwd | ||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | prompt_yn prompt_Yn prompt_yN prompt_string | ||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | prompt_nY prompt_Ny prompt_ny | ||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | prompt_int tsay anydump prompt_regex prompt_sub | ||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | prompt_file hush_exec unhush_exec | ||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | getopt_lenient time_unit | ||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | # define this in subclasses where appropriate | ||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | sub __package__ { __PACKAGE__ } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__package__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 52 | our ($VERBOSE, $closure, $SHOW_CMD_VERBOSE, $gotconf); | |||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 52 | $VERBOSE = 0; | |||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 52 | $SHOW_CMD_VERBOSE = 1; | |||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | #--------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | # parse import arguments and export symbols | ||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | #--------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 80 | ▶ | sub import { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 80 | my $pkg = shift; | |||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 61 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | # look for options in the importer arguments | ||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 80 | ▶ | for ( my $i = 0; $i < $#_; $i++ ) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 13 | ▶ | if ( $_[$i] =~ m/^-(.*)/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | die "Bad option `$1' from $pkg" | ||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 13 | ▶ | unless *{uc($1)}{SCALAR}; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 13 | ▶ | my $x = uc($1); ($x eq "VERSION") && ($x="main::$x"); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 13 | ${$x} = $_[$i+1]; | |||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 13 | (@_) = (@_[0..($i-1)], @_[($i+2)..$#_]); | |||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 13 | $i--; | |||||||||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 80 | unshift @_, $pkg; | |||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 80 | goto &Exporter::import; | |||||||||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | # automatically guess the program name if called for | ||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 52 | ▶ | (our $PROGNAME = $0) =~ s{.*/}{} unless $PROGNAME; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 52 | our $CONFIG; | |||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 61 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 61 | Getopt::Long::config("bundling", "pass_through"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 44 | ▶ | END { $closure->() if $closure } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
END: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 23 | ▶ | sub getopt_lenient { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getopt_lenient: called CC=3 SCAR=12.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 23 | local($closure) = \&show_usage; | |||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 23 | $gotconf = 1; | |||||||||||||||||||||||||||||||||||||||||||||||
| 82 | Getopt::Long::GetOptions | ||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | ( | ||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 'help|h' => \&show_help, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 8 | ▶ | 'verbose|v' => sub { $VERBOSE++ }, | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | 'quiet|q' => sub { $VERBOSE = -1 }, | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | ▶ | 'debug|d' => sub { $VERBOSE = 2 }, | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 23 | 'version|V' => \&show_version, | |||||||||||||||||||||||||||||||||||||||||||||||
| 89 | @_, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | # check for unknown arguments and print a nice error message | ||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | # instead of the nasty default Getopt::Long message | ||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 22 | ▶ | shift @ARGV, return if $#ARGV >= 0 and $ARGV[0] eq "--"; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$#ARGV >= 0 and $ARGV[0] eq "--"
MC/DC0%0/2
$#ARGV >= 0 and $ARGV[0] eq "--"
$#ARGV >= 0
$ARGV[0] eq "--"
Truth table66%2/3
A and B
A= $#ARGV >= 0B= $ARGV[0] eq "--"
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 21 | ▶ | sub getopt { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getopt: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 21 | local($closure) = \&show_usage; | |||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 21 | getopt_lenient(@_); | |||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 20 | ▶ | abort("unrecognised option: $ARGV[0]") | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$#ARGV >= 0 and $ARGV[0] =~ /^-/
MC/DC50%1/2
$#ARGV >= 0 and $ARGV[0] =~ /^-/
$#ARGV >= 0
$ARGV[0] =~ /^-/
Truth table66%2/3
A and B
A= $#ARGV >= 0B= $ARGV[0] =~ /^-/
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | if $#ARGV >= 0 and $ARGV[0] =~ m/^-/; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 31 | ▶ | sub say { _autoconf() unless $gotconf; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
say: called CC=3 SCAR=11.1
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 31 | ▶ | print "$PROGNAME: @_\n" unless $VERBOSE < 0 } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 1 | ▶ | sub mutter { say @_ if $VERBOSE } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mutter: called CC=2 SCAR=7.6
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 10 | ▶ | sub whisper { say @_ if $VERBOSE > 1 } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
whisper: called CC=2 SCAR=7.6
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 3 | ▶ | sub _err_say { _autoconf() unless $gotconf; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_err_say: called CC=2 SCAR=7.2
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 3 | print STDERR "$PROGNAME: @_\n" } | |||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 1 | ▶ | sub abort { _err_say "aborting: @_"; &show_usage; } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
abort: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 1 | ▶ | sub moan { _err_say "warning: @_" } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
moan: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 1 | ▶ | sub protest { _err_say "error: @_" } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
protest: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | ▶ | sub barf { if($^S){die @_}else{ _err_say "ERROR: @_"; exit(1); } } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
barf: called CC=2 SCAR=9.2
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 2 | ▶ | sub _autoconf { getopt_lenient( eval{ my @x = getconf(@_); @x } ) } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_autoconf: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | #--------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | # helpers for running commands and/or capturing their output | ||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | #--------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 52 | our (@output, $next_cmd_no_hide, $next_cmd_capture); | |||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | # use Shell::QuoteEscape? nah :-) | ||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 52 | my %map = ((map { chr($_) => sprintf("\\%.3o",$_) } (0..31, 127..255)), | |||||||||||||||||||||||||||||||||||||||||||||||
| 127 | " "=>" ","\t"=>"\\t","\r"=>"\\r","\n"=>"\\n", | ||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | "\""=>"\\\""); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 5 | ▶ | sub shellquote { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
shellquote: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 10 | ▶ | return join(" ",map { m/[\s\']/ && do { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 3 | s/[\0-\031"\s\177-\377]/$map{$&}/eg; | |||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 3 | $_ = "\"$_\""; | |||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 5 | }; $_ } map { $_ } @_); | |||||||||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 52 | our @SHOW_CMD_VERBOSE; | |||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | ▶ | sub hush_exec { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
hush_exec: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | push @SHOW_CMD_VERBOSE, $SHOW_CMD_VERBOSE; | |||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | $SHOW_CMD_VERBOSE=2; | |||||||||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | ▶ | sub unhush_exec { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unhush_exec: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | $SHOW_CMD_VERBOSE = pop @SHOW_CMD_VERBOSE; | |||||||||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 52 | our @last_cmd; | |||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 133 | ▶ | sub run { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run: called CC=10 SCAR=34.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 133 | &run_err(@_); | |||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 105 | @_ = @last_cmd; | |||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 105 | my $start = $#output - 10; | |||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 105 | ▶ | chomp($output[$#output]) if @output; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 105 | ▶ | $start = 0 if $start < 0; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 105 | ▶ | barf( | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 6 branches
Condition0%0/3
$Scriptalicious::VERBOSE >= $Scriptalicious::SHOW_CMD_VERBOSE or $Scriptalicious::next_cmd_no_hide
MC/DC0%0/2
$Scriptalicious::VERBOSE >= $Scriptalicious::SHOW_CMD_VERBOSE or $Scriptalicious::next_cmd_no_hide
$Scriptalicious::VERBOSE >= $Scriptalicious::SHOW_CMD_VERBOSE
$Scriptalicious::next_cmd_no_hide
Truth table0%0/3
A or B
A= $Scriptalicious::VERBOSE >= $Scriptalicious::SHOW_CMD_VERBOSEB= $Scriptalicious::next_cmd_no_hide
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | (ref $_[0] ? "Sub-process " : "Command `".shellquote(@_)."' "). | ||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | (($? >> 8) | ||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | ? "exited with error code ".($?>>8) | ||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | : "killed by signal $?") | ||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | .(($VERBOSE >= $SHOW_CMD_VERBOSE or $next_cmd_no_hide) ? "" | ||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | : (($start != 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | ? "\nlast lines of output:\n" | ||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | : "\nprogram output:\n") | ||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | .join("", @output[$start .. $#output]) | ||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | .($start != 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | ? "(use -v to show complete program output)" | ||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | : ""))) | ||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | ) if ($?); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 163 | ▶ | sub do_fork { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
do_fork: called CC=6 SCAR=18.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 163 | @output = (); | |||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 163 | ▶ | if (not $next_cmd_capture and | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
not $Scriptalicious::next_cmd_capture and $Scriptalicious::VERBOSE >= $Scriptalicious::SHOW_CMD_VERBOSE || $Scriptalicious::next_cmd_no_hide
$Scriptalicious::VERBOSE >= $Scriptalicious::SHOW_CMD_VERBOSE or $Scriptalicious::next_cmd_no_hide
MC/DC66%2/3
not $Scriptalicious::next_cmd_capture and $Scriptalicious::VERBOSE >= $Scriptalicious::SHOW_CMD_VERBOSE || $Scriptalicious::next_cmd_no_hide
not $Scriptalicious::next_cmd_capture
$Scriptalicious::VERBOSE >= $Scriptalicious::SHOW_CMD_VERBOSE
$Scriptalicious::next_cmd_no_hide
Truth table75%3/4
not(A) and B or C
A= not $Scriptalicious::next_cmd_captureB= $Scriptalicious::VERBOSE >= $Scriptalicious::SHOW_CMD_VERBOSEC= $Scriptalicious::next_cmd_no_hide
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | ( $VERBOSE >= $SHOW_CMD_VERBOSE or $next_cmd_no_hide )) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | return fork() | ||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 3 | } else { | |||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 160 | my $pid = open CHILD, "-|"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 160 | ▶ | if (defined($pid) && !$pid) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $pid and not $pid
MC/DC50%1/2
defined $pid and not $pid
defined $pid
not $pid
Truth table66%2/3
A and not(B)
A= defined $pidB= not $pid
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 33 | open STDERR, ">&STDOUT"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 160 | return $pid; | |||||||||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 129 | ▶ | sub _waitpid { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_waitpid: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 129 | my $pid = shift; | |||||||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 129 | ▶ | if (not $next_cmd_capture and | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
not $Scriptalicious::next_cmd_capture and $Scriptalicious::VERBOSE >= $Scriptalicious::SHOW_CMD_VERBOSE || $Scriptalicious::next_cmd_no_hide
$Scriptalicious::VERBOSE >= $Scriptalicious::SHOW_CMD_VERBOSE or $Scriptalicious::next_cmd_no_hide
MC/DC66%2/3
not $Scriptalicious::next_cmd_capture and $Scriptalicious::VERBOSE >= $Scriptalicious::SHOW_CMD_VERBOSE || $Scriptalicious::next_cmd_no_hide
not $Scriptalicious::next_cmd_capture
$Scriptalicious::VERBOSE >= $Scriptalicious::SHOW_CMD_VERBOSE
$Scriptalicious::next_cmd_no_hide
Truth table75%3/4
not(A) and B or C
A= not $Scriptalicious::next_cmd_captureB= $Scriptalicious::VERBOSE >= $Scriptalicious::SHOW_CMD_VERBOSEC= $Scriptalicious::next_cmd_no_hide
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | ($VERBOSE >= $SHOW_CMD_VERBOSE or $next_cmd_no_hide)) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 2 | waitpid($pid, 0); | |||||||||||||||||||||||||||||||||||||||||||||||
| 188 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 127 | ▶ | while (my $line = <CHILD>) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 206 | push @output, $line; | |||||||||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 127 | close CHILD; | |||||||||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 331 | ▶ | sub _load_hires { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_load_hires: called CC=4 SCAR=15.5
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 331 | ▶ | return if defined &gettimeofday; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 44 | ▶ | eval "use Time::HiRes qw(gettimeofday tv_interval)"; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | ▶ | *gettimeofday = sub { return time() } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 44 | ▶ | unless defined &gettimeofday; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | ▶ | *tv_interval = sub { return ${$_[0]}[0] - ${$_[1]}[0] } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 44 | ▶ | unless defined &tv_interval; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 163 | ▶ | sub run_err { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run_err: called CC=19 SCAR=31.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 163 | my %fds; | |||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 163 | my $fd_desc = ""; | |||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 163 | ▶ | while ( $_[0] and !ref $_[0] and $_[0]=~/^-(in|out|rw)(\d+)?$/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$_[0] and not ref $_[0] and $_[0] =~ /^-(in|out|rw)(\d+)?$/
$_[0] and not ref $_[0]
MC/DC33%1/3
$_[0] and not ref $_[0] and $_[0] =~ /^-(in|out|rw)(\d+)?$/
$_[0]
not ref $_[0]
$_[0] =~ /^-(in|out|rw)(\d+)?$/
Truth table50%2/4
A and not(B) and C
A= $_[0]B= not ref $_[0]C= $_[0] =~ /^-(in|out|rw)(\d+)?$/
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 150 | shift; | |||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 150 | ▶ | my $mode = ($1 eq "in" ? "<" : ($1 eq "out" ? ">" : "+<") ); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 150 | ▶ | my $fd = $2 || ($1 eq "out" ? 1 : 0); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$2 || ($1 eq 'out' ? 1 : 0)
MC/DC100%2/2
$2 || ($1 eq 'out' ? 1 : 0)
$2
($1 eq 'out' ? 1 : 0)
Truth table100%3/3
A || B
A= $2B= ($1 eq 'out' ? 1 : 0)
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 150 | $fds{"$fd"} = [ $mode, shift ]; | |||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 150 | ▶ | $fd_desc .= ($fd_desc ? ", " : "") . "fd$fd=$mode$fds{$fd}"; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 163 | @last_cmd = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 163 | ▶ | if ( $VERBOSE >= $SHOW_CMD_VERBOSE ) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 5 | ▶ | say("running `".shellquote(@last_cmd)."'" | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | .($next_cmd_capture | ||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | ? " (captured)" | ||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | : "") | ||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | .($fd_desc?"($fd_desc)":"") | ||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | ) unless ref($_[0]); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 163 | _load_hires; | |||||||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 163 | my $start = start_timer(); | |||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 163 | my $output; | |||||||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 163 | ▶ | if (my $pid = do_fork) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | ▶ | local $SIG{INT} = sub { kill 2, $pid }; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 129 | $output = &_waitpid($pid); | |||||||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 34 | ▶ | barf "Fork failed; $!" if not defined $pid; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 34 | ▶ | setup_fds(\%fds) if $fd_desc; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 25 | ▶ | if (ref $_[0]) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | my $code = shift; | |||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | $code->(@_); | |||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | exit(0); | |||||||||||||||||||||||||||||||||||||||||||||||
| 241 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 25 | ▶ | exec(@_) || | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | barf "exec failed; $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 129 | ▶ | if ( $VERBOSE >= $SHOW_CMD_VERBOSE ) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 3 | say sprintf("command completed in ".show_elapsed($start)) | |||||||||||||||||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 129 | return $? | |||||||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 124 | ▶ | sub capture { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
capture: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 124 | local($next_cmd_capture) = 1; | |||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 124 | run(@_); | |||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 99 | ▶ | return (wantarray ? @output : join("", @output)); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 30 | ▶ | sub capture_err { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
capture_err: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 30 | local($next_cmd_capture) = 1; | |||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 30 | my $rv = run_err(@_); | |||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 24 | return ($rv, @output) | |||||||||||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | ▶ | sub capture2 { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
capture2: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | die "capture2 not implemented yet" | |||||||||||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 52 | our $DATA = join "", <DATA>; close DATA; | |||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 52 | ▶ | our ($AUTOLOAD, $l);sub AUTOLOAD{croak"No such function $AUTOLOAD"if | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: called CC=3 SCAR=11.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 52 | $l;(undef,my($f,$n))=ll();$n+=1;eval"package ".__PACKAGE__.";\n" | |||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 52 | ▶ | ."# line $n \"$f\"\n$DATA"; $@&&die"Error in autoload: $@"; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 52 | ▶ | $l=1;goto &{$AUTOLOAD};}sub ll{sub{caller()}->();} "P E A C E"; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
ll: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | __DATA__ | ||||||||||||||||||||||||||||||||||||||||||||||||