| 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
Condition0%0/6
defined $val and $val =~ /^\d+$/ and $val > 0
defined $val and $val =~ /^\d+$/
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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | return _clone_dir_cp(@_) if $CP; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 2 | ▶ | system($CP, '-a', $params{verbose} ? ( '-v' ) : (), "$src/.", $dest) and die "$CP returned $?"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 2 | ▶ | File::Copy::Recursive::dircopy($src, $dest) or die "$!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
$refout eq $refdef and $refdef eq "HASH"
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
$out->{$key} and $out->{$key} eq $defaults->{$key}
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}
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | return $out; | |||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | 24 | 1; | |||||||||||||||||||||||||||||||||||||||||