DBIx/QuickDB/Util.pm

filter: Statementstmt 62.7% 37 / 59 Branchbran 17.8% 5 / 28 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 71.4% 10 / 14 Podpod 0.0% 0 / 3 totaltotal 42.2% 52 / 123 CC 20 SCAR 27.7
CC
20
Cov
42%
strip_hash_defaults
41.9
env_timeout
20.0
_clone_dir_rsync
20.0
CRAP 15.9
« DBIx/QuickDB/Driver/SQLite.pm ↑ Summary DBIx/QuickDB/Driver/DuckDB.pm »
1 package DBIx::QuickDB::Util;
2 24 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 24 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 24 our $VERSION = '0.000047';
6  
7 24 ▶use File::Path qw/remove_tree/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 24 ▶use IPC::Cmd qw/can_run/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 24 ▶use Carp qw/confess/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 24 ▶use Importer Importer => 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 24 our @EXPORT_OK = qw/clone_dir strip_hash_defaults env_timeout/;
14  
15 # Read a positive-integer timeout (in seconds) from an environment variable,
16 # falling back to $default when it is unset or not a positive integer. Used to
17 # make the server start/stop timeouts generous-but-tunable so slow hosts (e.g.
18 # CPAN smoke boxes) do not spuriously time out.
19 sub env_timeout {
20 0 ▶ my ($name, $default) = @_;
Subroutine env_timeout: not called CC=4 SCAR=30.0
Pod undocumented
21 0 my $val = $ENV{$name};
22 0 ▶ return $val if defined($val) && $val =~ /^\d+$/ && $val > 0;
Branch: 1 branch
BranchTrueFalseTotal
if defined $val and $val =~ /^\d+$/ and $val > 0 0 0 0
Condition0%0/6
defined $val and $val =~ /^\d+$/ and $val > 0
!ll&&!rl&&r
000
defined $val and $val =~ /^\d+$/
!ll&&!rl&&r
000
MC/DC0%0/3
defined $val and $val =~ /^\d+$/ and $val > 0
defined $val $val =~ /^\d+$/ $val > 0
Truth table0%0/4
A and B and C
A= defined $valB= $val =~ /^\d+$/C= $val > 0
ABCresult
0XX0
10X0
1100
1111
23 0 return $default;
24 }
25  
26 24 my ($RSYNC, $CP);
27  
28 BEGIN {
29 24 ▶ local $@;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 24 $RSYNC = can_run('rsync');
31 24 $CP = can_run('cp');
32 }
33  
34 sub clone_dir {
35 0 ▶ return _clone_dir_rsync(@_) if $RSYNC;
Subroutine clone_dir: not called CC=3 SCAR=24.8
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if $RSYNC 0 0 0
36 0 ▶ return _clone_dir_cp(@_) if $CP;
Branch: 1 branch
BranchTrueFalseTotal
if $CP 0 0 0
37 0 return _clone_dir_fcr(@_);
38 }
39  
40 sub _clone_dir_rsync {
41 0 ▶ my ($src, $dest, %params) = @_;
Subroutine _clone_dir_rsync: not called CC=4 SCAR=30.0
42 0 ▶ system($RSYNC, '-a', '--delete', '--exclude' => '.nfs*', $params{checksum} ? ('-c') : (), $params{verbose} ? ( '-vP' ) : (), "$src/", $dest) and die "$RSYNC returned $?";
Branch: 3 branches
BranchTrueFalseTotal
system $RSYNC, "-a", "--delete", "--exclude", ".nfs*", $params{"checksum"} ? "-c" : (), $params{"verbose"} ? "-vP" : (), "$src/", $dest and die "$RSYNC returned $?" 0 0 0
$params{'checksum'} ? : 0 0 0
$params{'verbose'} ? : 0 0 0
43 }
44  
45 sub _clone_dir_cp {
46 2 ▶ my ($src, $dest, %params) = @_;
Subroutine _clone_dir_cp: called CC=4 SCAR=14.9
47 2 my $err;
48 2 ▶ remove_tree($dest, {safe => 1, keep_root => 1, error => \$err}) if -d $dest;
Branch: 1 branch
BranchTrueFalseTotal
if -d $dest 2 0 2
49 2 ▶ system($CP, '-a', $params{verbose} ? ( '-v' ) : (), "$src/.", $dest) and die "$CP returned $?";
Branch: 2 branches
BranchTrueFalseTotal
system $CP, "-a", $params{"verbose"} ? "-v" : (), "$src/.", $dest and die "$CP returned $?" 0 2 2
$params{'verbose'} ? : 0 2 2
50 }
51  
52 sub _clone_dir_fcr {
53 2 ▶ my ($src, $dest, %params) = @_;
Subroutine _clone_dir_fcr: called CC=3 SCAR=11.3
54 2 require File::Copy::Recursive;
55  
56 2 my $err;
57 2 ▶ remove_tree($dest, {safe => 1, keep_root => 1, error => \$err}) if -d $dest;
Branch: 1 branch
BranchTrueFalseTotal
if -d $dest 2 0 2
58 2 ▶ File::Copy::Recursive::dircopy($src, $dest) or die "$!";
Branch: 1 branch
BranchTrueFalseTotal
File::Copy::Recursive::dircopy($src, $dest) or die "$!" 0 2 2
59 }
60  
61 sub strip_hash_defaults {
62 0 ▶ my ($hash, $defaults) = @_;
Subroutine strip_hash_defaults: not called CC=7 SCAR=37.3
Pod undocumented
63  
64 0 my $out = {%$hash};
65  
66 0 for my $key (keys %$defaults) {
67 0 my $refout = ref($out->{$key});
68 0 my $refdef = ref($defaults->{$key});
69  
70 0 ▶ if ($refout eq $refdef && $refdef eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if ($refout eq $refdef and $refdef eq "HASH") 0 0 0
Condition0%0/3
$refout eq $refdef and $refdef eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
$refout eq $refdef and $refdef eq "HASH"
$refout eq $refdef $refdef eq "HASH"
Truth table0%0/3
A and B
A= $refout eq $refdefB= $refdef eq "HASH"
ABresult
0X0
100
111
71 0 $out->{$key} = strip_hash_defaults($out->{$key}, $defaults->{$key});
72 0 next;
73 }
74  
75 0 ▶ if ($refout ne $refdef) {
Branch: 1 branch
BranchTrueFalseTotal
if ($refout ne $refdef) 0 0 0
76 0 delete $out->{$key};
77 0 next;
78 }
79  
80 24 ▶ no warnings 'numeric';
Subroutine BEGIN: called CC=1 SCAR=0.0
81 0 ▶ delete $out->{$key} if $out->{$key} && $out->{$key} eq $defaults->{$key};
Branch: 1 branch
BranchTrueFalseTotal
if $out->{$key} and $out->{$key} eq $defaults->{$key} 0 0 0
Condition0%0/3
$out->{$key} and $out->{$key} eq $defaults->{$key}
!ll&&!rl&&r
000
MC/DC0%0/2
$out->{$key} and $out->{$key} eq $defaults->{$key}
$out->{$key} $out->{$key} eq $defaults->{$key}
Truth table0%0/3
A and B
A= $out->{$key}B= $out->{$key} eq $defaults->{$key}
ABresult
0X0
100
111
82 }
83  
84 0 return $out;
85 }
86  
87 24 1;
« DBIx/QuickDB/Driver/SQLite.pm ↑ Summary DBIx/QuickDB/Driver/DuckDB.pm »