| 1 | #=============================================== | ||||||||||||||||||||||||||||
| 2 | package Banal::Utils::General; | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use utf8; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 2 | require Exporter; | |||||||||||||||||||||||||||
| 6 | 2 | ▶ | no warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 2 | @ISA = qw(Exporter); | |||||||||||||||||||||||||||
| 11 | 2 | @EXPORT_OK = qw( run_cmd run_perl debug_dump_vars); | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | ##############################################################################" | ||||||||||||||||||||||||||||
| 15 | # Utility functions | ||||||||||||||||||||||||||||
| 16 | ##############################################################################" | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | #------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 19 | 0 | ▶ | sub run_cmd { | ||||||||||||||||||||||||||
|
Subroutine
run_cmd: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||
| 20 | 0 | my ($opts, $cmd) = @_; | |||||||||||||||||||||||||||
| 21 | 0 | ▶ | my $verbose = $opts->{verbose} || $opts->{debug}; | ||||||||||||||||||||||||||
|
Condition0%0/3
$opts->{'verbose'} || $opts->{'debug'}
MC/DC0%0/2
$opts->{'verbose'} || $opts->{'debug'}
$opts->{'verbose'}
$opts->{'debug'}
Truth table0%0/3
A || B
A= $opts->{'verbose'}B= $opts->{'debug'}
| |||||||||||||||||||||||||||||
| 22 | 0 | my $dryrun = $opts->{dryrun}; | |||||||||||||||||||||||||||
| 23 | 0 | ▶ | my $prompt = $dryrun ? 'sys would > ' : 'sys cmd > '; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 24 | 0 | ▶ | return unless $cmd; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 0 | ▶ | print $prompt . $cmd . "\n" if $verbose; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 0 | my $output; | |||||||||||||||||||||||||||
| 29 | 0 | ▶ | unless ($dryrun) { $output = `$cmd`; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 30 | 0 | ▶ | else { $output = $dryrun ? 'Command NOT executed (dry-run mode)' : eval($cmd); } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 0 | ▶ | print "$output\n" if ($output && $verbose > 5); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$output and $verbose > 5
MC/DC0%0/2
$output and $verbose > 5
$output
$verbose > 5
Truth table0%0/3
A and B
A= $outputB= $verbose > 5
| |||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | #------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 37 | 0 | ▶ | sub run_perl { | ||||||||||||||||||||||||||
|
Subroutine
run_perl: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||
| 38 | 0 | my ($opts, $cmd) = @_; | |||||||||||||||||||||||||||
| 39 | 0 | ▶ | my $verbose = $opts->{verbose} || $opts->{debug}; | ||||||||||||||||||||||||||
|
Condition0%0/3
$opts->{'verbose'} || $opts->{'debug'}
MC/DC0%0/2
$opts->{'verbose'} || $opts->{'debug'}
$opts->{'verbose'}
$opts->{'debug'}
Truth table0%0/3
A || B
A= $opts->{'verbose'}B= $opts->{'debug'}
| |||||||||||||||||||||||||||||
| 40 | 0 | my $dryrun = $opts->{dryrun}; | |||||||||||||||||||||||||||
| 41 | 0 | ▶ | my $prompt = $dryrun ? 'perl would > ' : 'perl cmd > '; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 0 | ▶ | return unless $cmd; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 0 | ▶ | print $prompt . $cmd . "\n" if $verbose; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 0 | my $output; | |||||||||||||||||||||||||||
| 48 | 0 | ▶ | unless ($dryrun) { $output = eval($cmd); } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | 0 | ▶ | else { $output = $dryrun ? 'Command NOT executed (dry-run mode)' : eval($cmd); } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 0 | ▶ | print "$output\n" if ($output && $verbose > 5); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$output and $verbose > 5
MC/DC0%0/2
$output and $verbose > 5
$output
$verbose > 5
Truth table0%0/3
A and B
A= $outputB= $verbose > 5
| |||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | #--------------------------------- | ||||||||||||||||||||||||||||
| 55 | 0 | ▶ | sub debug_dump_vars { | ||||||||||||||||||||||||||
|
Subroutine
debug_dump_vars: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 56 | 0 | my $msg = shift; | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 0 | print STDERR "$msg:DUMP:\n"; | |||||||||||||||||||||||||||
| 59 | 0 | $Data::Dumper::Sortkeys = 1; | |||||||||||||||||||||||||||
| 60 | 0 | print STDERR Data::Dumper->Dump([@_]); | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 2 | 1; | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | __END__ | ||||||||||||||||||||||||||||