| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition50%3/6
defined $cycle_top and $cycle_top || $cycle_top == 0
$cycle_top or $cycle_top == 0
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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
$cycle or $cycle == 0
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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||||||||||||