Zucchini/Rsync.pm

filter: Statementstmt 48.9% 23 / 47 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 85.7% 6 / 7 Podpod 100% 1 / 1 totaltotal 41.6% 30 / 72 CC 10 SCAR 42.4
CC
10
Cov
37%
remote_sync
110.0
BEGIN
1.0
BEGIN
1.0
CRAP 69.1
« Zucchini/Fsync.pm ↑ Summary Zucchini.pm »
1 package Zucchini::Rsync;
2 6 $Zucchini::Rsync::VERSION = '0.0.21';
3 {
4 6 $Zucchini::Rsync::DIST = 'Zucchini';
5 }
6 # ABSTRACT: move files using rsync
7 # vim: ts=8 sts=4 et sw=4 sr sta
8 6 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 6 ▶use strict; # for kwalitee testing
Subroutine BEGIN: called CC=1 SCAR=0.0
10 6 ▶use Zucchini::Types qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 6 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 6 ▶use Config::Any;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 6 ▶use File::Rsync;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 # class data
17 6 has config => (
18 reader => 'get_config',
19 writer => 'set_config',
20 isa => ZucchiniConfig,
21 is => 'ro',
22 );
23  
24 0 ▶sub remote_sync {
Subroutine remote_sync: not called CC=10 SCAR=47.0
Pod documented
25 0 my $self = shift;
26  
27 0 my $config = $self->get_config->get_siteconfig();
28 0 my $local_dir = $config->{output_dir};
29 0 my $rsync_data = $config->{rsync};
30  
31 # we need a remote host and a path
32 0 foreach my $required (qw[ hostname path ]) {
33 0 ▶ if (not exists $rsync_data->{$required}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $rsync_data->{$required}) 0 0 0
34 0 warn "missing rsync option '$required'. rsync aborted\n";
35 0 return;
36 }
37 }
38  
39 # create a new rsync object
40 0 ▶ my $syncer = File::Rsync->new(
Condition0%0/2
$self->get_config->is_dry_run || 0
l!l
00
MC/DC0%0/1
$self->get_config->is_dry_run || 0
$self->get_config->is_dry_run
Truth table0%0/2
A
A= $self->get_config->is_dry_run
Aresult
11
00
41 {
42 recursive => 1,
43 compress => 1,
44 verbose => $self->get_config->verbose(2),
45 'dry-run' => $self->get_config->is_dry_run() || 0,
46 }
47 );
48  
49 # make sure it was successfully created
50 0 ▶ if (not defined $syncer) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $syncer) 0 0 0
51 0 warn "Can't create File::Rsync object\n";
52 0 return;
53 }
54  
55 # perform the rsync operation
56 0 ▶ if ($self->get_config->verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_config->verbose) 0 0 0
57 0 ▶ if ($self->get_config->is_dry_run()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_config->is_dry_run) 0 0 0
58 0 warn "Running rsync in dryrun mode\n";
59 }
60 0 warn "Starting rsync\n";
61 }
62 $syncer->exec(
63 {
64 0 src => "$local_dir/",
65 dest => "$rsync_data->{hostname}:$rsync_data->{path}/",
66 }
67 );
68  
69 # give feedback if we're verbose
70 0 ▶ if ($self->get_config->verbose(2)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_config->verbose(2)) 0 0 0
71 0 warn $syncer->out();
72 }
73 0 ▶ if ($self->get_config->verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_config->verbose) 0 0 0
74 0 warn "Completed rsync\n";
75 }
76  
77 # give feedback if there were any errors
78 0 ▶ if ($syncer->err()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($syncer->err) 0 0 0
79 0 warn $syncer->err();
80 }
81  
82 0 return;
83 }
84  
85 6 1;
86  
87 __END__
« Zucchini/Fsync.pm ↑ Summary Zucchini.pm »