Utils/General.pm

filter: Statementstmt 33.3% 13 / 39 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 50.0% 3 / 6 Podpod 100% 3 / 3 totaltotal 20.6% 19 / 92 CC 17 SCAR 43.0
CC
17
Cov
17%
run_cmd
90.0
run_perl
90.0
debug_dump_vars
2.0
CRAP 73.9
« Utils/Class.pm ↑ Summary Utils/Array.pm »
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'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts->{'verbose'} || $opts->{'debug'}
$opts->{'verbose'} $opts->{'debug'}
Truth table0%0/3
A || B
A= $opts->{'verbose'}B= $opts->{'debug'}
ABresult
1X1
011
000
22 0 my $dryrun = $opts->{dryrun};
23 0 ▶ my $prompt = $dryrun ? 'sys would > ' : 'sys cmd > ';
Branch: 1 branch
BranchTrueFalseTotal
$dryrun ? : 0 0 0
24 0 ▶ return unless $cmd;
Branch: 1 branch
BranchTrueFalseTotal
unless $cmd 0 0 0
25
26 0 ▶ print $prompt . $cmd . "\n" if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 0 0 0
27
28 0 my $output;
29 0 ▶ unless ($dryrun) { $output = `$cmd`; }
Branch: 1 branch
BranchTrueFalseTotal
if ($dryrun) { } 0 0 0
30 0 ▶ else { $output = $dryrun ? 'Command NOT executed (dry-run mode)' : eval($cmd); }
Branch: 1 branch
BranchTrueFalseTotal
$dryrun ? : 0 0 0
31
32 0 ▶ print "$output\n" if ($output && $verbose > 5);
Branch: 1 branch
BranchTrueFalseTotal
if $output and $verbose > 5 0 0 0
Condition0%0/3
$output and $verbose > 5
!ll&&!rl&&r
000
MC/DC0%0/2
$output and $verbose > 5
$output $verbose > 5
Truth table0%0/3
A and B
A= $outputB= $verbose > 5
ABresult
0X0
100
111
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'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts->{'verbose'} || $opts->{'debug'}
$opts->{'verbose'} $opts->{'debug'}
Truth table0%0/3
A || B
A= $opts->{'verbose'}B= $opts->{'debug'}
ABresult
1X1
011
000
40 0 my $dryrun = $opts->{dryrun};
41 0 ▶ my $prompt = $dryrun ? 'perl would > ' : 'perl cmd > ';
Branch: 1 branch
BranchTrueFalseTotal
$dryrun ? : 0 0 0
42
43 0 ▶ return unless $cmd;
Branch: 1 branch
BranchTrueFalseTotal
unless $cmd 0 0 0
44
45 0 ▶ print $prompt . $cmd . "\n" if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 0 0 0
46
47 0 my $output;
48 0 ▶ unless ($dryrun) { $output = eval($cmd); }
Branch: 1 branch
BranchTrueFalseTotal
if ($dryrun) { } 0 0 0
49 0 ▶ else { $output = $dryrun ? 'Command NOT executed (dry-run mode)' : eval($cmd); }
Branch: 1 branch
BranchTrueFalseTotal
$dryrun ? : 0 0 0
50
51 0 ▶ print "$output\n" if ($output && $verbose > 5);
Branch: 1 branch
BranchTrueFalseTotal
if $output and $verbose > 5 0 0 0
Condition0%0/3
$output and $verbose > 5
!ll&&!rl&&r
000
MC/DC0%0/2
$output and $verbose > 5
$output $verbose > 5
Truth table0%0/3
A and B
A= $outputB= $verbose > 5
ABresult
0X0
100
111
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__
« Utils/Class.pm ↑ Summary Utils/Array.pm »