bin/backup-hanoi

filter: Statementstmt 86.2% 25 / 29 Branchbran 66.6% 4 / 6 Conditioncond 41.6% 5 / 12 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 66.6% 38 / 57 CC 1 SCAR 0.0
CC
1
Cov
72%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« blib/lib/Backup/Hanoi.pm ↑ Summary
1 #!/usr/bin/env perl
2 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶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 3 ▶use feature 'say';
Subroutine BEGIN: called CC=1 SCAR=0.0
11
12 3 ▶use Backup::Hanoi;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 3 my $help = <<'END_MESSAGE';
15  
16 backup-hanoi tells you where to write your next backup
17  
18 You need to list your devices in a text file, separated by newline
19  
20 example usages:
21  
22 # list repeatable pattern
23 backup-hanoi device-list.txt
24  
25 # list which device should be used for backup number 40
26 backup-hanoi device-list.txt 40
27  
28 # create a device-list for the backups 40 up to 60
29 backup-hanoi device-list.txt 40 60
30 END_MESSAGE
31 3 ▶unless (@ARGV) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@ARGV) 0 3 3
32 0 say $help;
33 0 exit 0;
34 }
35  
36  
37 3 my $devices_file = shift @ARGV;
38 3 my $cycle = shift @ARGV;
39 3 my $cycle_top = shift @ARGV;
40  
41 3 open my $file_handle, '<', $devices_file;
42 3 chomp(my @devices = <$file_handle>);
43 3 close $file_handle;
44  
45 3 my $backup = Backup::Hanoi->new(\@devices);
46  
47 3 ▶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) { } 1 2 3
elsif (defined $cycle and $cycle || $cycle == 0) { } 2 0 2
Condition50%3/6
defined $cycle_top and $cycle_top || $cycle_top == 0
!ll&&!rl&&r
201
$cycle_top or $cycle_top == 0
l!l&&r!l&&!r
100
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
48  
49 1 for ($cycle .. $cycle_top) {
50 3 say $backup->get_device_for_cycle($_);
51 }
52 }
53 ▶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
54 2 say $backup->get_device_for_cycle($cycle);
55 }
56 else {
57 0 for (0 .. ((2**(scalar @devices))/2)-1) {
58 0 say $backup->get_device_for_cycle($_);
59 }
60 }
61  
62 __END__
« blib/lib/Backup/Hanoi.pm ↑ Summary