Win32-Backup-Robocopy
view release on metacpan or search on metacpan
lib/Win32/Backup/Robocopy.pm view on Meta::CPAN
$self->run();
}
sub _load_conf{
my $file = shift;
return [] unless -e -r -f $file;
# READ the configuration
my $json = JSON::PP->new->utf8->pretty->canonical;
open my $fh, '<', $file or croak "unable to read $file";
my $lines;
{
local $/ = '';
$lines = <$fh>;
}
close $fh or croak "impossible to close $file";
my $data;
{
local $@;
eval { $data = $json->decode( $lines ) };
croak "malformed json in $file!\nJSON error:\n[$@]\n" if $@;
}
croak "not an ARRAY ref retrieved from $file as conteainer for jobs! wrong configuration"
t/05-writeconf.t view on Meta::CPAN
$bkp->_write_conf();
# check the file exists
ok( -e -f -r $conf, 'configuration written in the rigth file');
# READ the configuration
my $json = JSON::PP->new->utf8->pretty->canonical;
open my $fh, '<', $conf or BAIL_OUT "unable to read $conf";
my $lines;
{
local $/ = '';
$lines = <$fh>;
}
close $fh or BAIL_OUT "impossible to close $conf";
my $data = $json->decode( $lines );
# check returned datastructure
ok( ref $data eq 'ARRAY', "json data conatains an array");
ok ( ref $data->[0] eq 'HASH', 'the array contains hash');
ok( ${$data->[0]}{name} eq 'test5_first_time_run','hash element name correctly found');
ok( ${$data->[0]}{next_time} == 0,'test5_first_time_run has time = 0 because of first_time_run set to 1');
# RUNJOBS
my ($stdout, $stderr, @result) = capture { $bkp->runjobs() };
# READ the configuration second time to see if updated
$json = JSON::PP->new->utf8->pretty->canonical;
open $fh, '<', $conf or BAIL_OUT "unable to read $conf";
undef $lines;
{
local $/ = '';
$lines = <$fh>;
}
close $fh or BAIL_OUT "impossible to close $conf";
$data = $json->decode( $lines );
# check returned datastructure
ok( ${$data->[0]}{first_time_run} == 0,'test5_first_time_run has first_time_run = 0 because already run');
ok( ${$data->[0]}{next_time} > 0,'test5_first_time_run has time > 0 because already run');
# chck both object and configuration have the same data
( run in 0.426 second using v1.01-cache-2.11-cpan-49f99fa48dc )