bin/backup-hanoi

filter: Statementstmt 86.6% 26 / 30 Branchbran 75.0% 6 / 8 Conditioncond 50.0% 6 / 12 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 100% 5 / 5 Podpod n/a totaltotal 70.4% 43 / 61 SCAR 0.1
CC
1
Cov
76%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« blib/lib/Backup/Hanoi.pm ↑ Summary
1 #!/usr/bin/env perl
2 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 # Autor: Boris Däppen, 2018
5 # No guarantee given, use at own risk and will
6  
7 # PODNAME: backup-hanoi
8 # ABSTRACT: predict on which device to put next backup
9  
10 5 ▶use v5.6.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use Backup::Hanoi;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 # we fake say, to support older perl
14 sub say {
15 15 ▶ print "$_[0]\n";
Subroutine say: called CC=1 SCAR=0.0
16 }
17  
18 5 my $help = <<'END_MESSAGE';
19  
20 backup-hanoi tells you where to write your next backup
21  
22 You need to list your devices in a text file, separated by newline
23  
24 example usages:
25  
26 # list repeatable pattern
27 backup-hanoi device-list.txt
28  
29 # list which device should be used for backup number 40
30 backup-hanoi device-list.txt 40
31  
32 # create a device-list for the backups 40 up to 60
33 backup-hanoi device-list.txt 40 60
34  
35 # first initialise all backups (fifo), then replace 40 times (hanoi)
36 backup-hanoi device-list.txt init 40
37  
38 END_MESSAGE
39 5 ▶unless (@ARGV) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@ARGV) 0 5 5
40 0 say $help;
41 0 exit 0;
42 }
43  
44  
45 5 my $devices_file = shift @ARGV;
46 5 my $cycle = shift @ARGV;
47 5 my $cycle_top = shift @ARGV;
48  
49 5 open my $file_handle, '<', $devices_file;
50 5 chomp(my @devices = <$file_handle>);
51 5 close $file_handle;
52  
53 5 my $backup = Backup::Hanoi->new(\@devices);
54  
55 5 ▶if (defined $cycle_top and ($cycle_top or $cycle_top == 0)) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $cycle_top and $cycle_top || $cycle_top == 0) { } 3 2 5
elsif (defined $cycle and $cycle || $cycle == 0) { } 2 0 2
Condition66%4/6
defined $cycle_top and $cycle_top || $cycle_top == 0
!ll&&!rl&&r
203
$cycle_top or $cycle_top == 0
l!l&&r!l&&!r
120
MC/DC0%0/3
defined $cycle_top and $cycle_top || $cycle_top == 0
defined $cycle_top $cycle_top $cycle_top == 0
Truth table0%0/4
A and B or C
A= defined $cycle_topB= $cycle_topC= $cycle_top == 0
ABCresult
0XX0
1000
11X1
1011
56  
57 # start with negative number for FIFO
58 3 ▶ $cycle = 1 - (scalar @devices) if ($cycle eq 'init');
Branch: 1 branch
BranchTrueFalseTotal
if $cycle eq "init" 1 2 3
59  
60 3 for ($cycle .. $cycle_top) {
61 13 say $backup->get_device_for_cycle($_);
62 }
63 }
64 ▶elsif (defined $cycle and ($cycle or $cycle == 0)) {
Condition33%2/6
defined $cycle and $cycle || $cycle == 0
!ll&&!rl&&r
002
$cycle or $cycle == 0
l!l&&r!l&&!r
200
MC/DC0%0/3
defined $cycle and $cycle || $cycle == 0
defined $cycle $cycle $cycle == 0
Truth table0%0/4
A and B or C
A= defined $cycleB= $cycleC= $cycle == 0
ABCresult
0XX0
1000
11X1
1011
65 2 say $backup->get_device_for_cycle($cycle);
66 }
67 else {
68 0 for (0 .. ((2**(scalar @devices))/2)-1) {
69 0 say $backup->get_device_for_cycle($_);
70 }
71 }
72  
73 __END__
« blib/lib/Backup/Hanoi.pm ↑ Summary