Csistck/Test/File.pm

filter: Statementstmt 78.3% 47 / 60 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 85.0% 17 / 20 Podpod 0.0% 0 / 6 totaltotal 72.7% 64 / 88 SCAR 7.2
CC
2
Cov
76%
file_compare
6.0
file_check
2.0
file_repair
2.0
CRAP 2.1
« Csistck/Config.pm ↑ Summary Csistck/Test/NOOP.pm »
1 package Csistck::Test::File;
2  
3 17 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 17 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 17 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 17 ▶use base 'Csistck::Test::FileBase';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 17 ▶use Csistck::Oper qw/debug/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 17 ▶use Csistck::Util qw/hash_file hash_string/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 17 our @EXPORT_OK = qw/file/;
12  
13 17 ▶use Digest::MD5;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 17 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 17 ▶use File::Copy;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 17 ▶use FindBin;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 17 ▶use File::stat;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 17 ▶use Template;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 17 ▶use Sys::Hostname::Long qw//;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 17 ▶use Text::Diff ();
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 2 ▶sub file { Csistck::Test::File->new(@_); };
Subroutine file: called CC=1 SCAR=0.0
Pod undocumented
23  
24 14 ▶sub desc { sprintf("File check on %s", shift->dest); }
Subroutine desc: called CC=1 SCAR=0.0
Pod undocumented
25  
26 sub file_check {
27 0 ▶ my $self = shift;
Subroutine file_check: not called CC=1 SCAR=6.9
Pod undocumented
28 0 my ($dest, $src) = ($self->dest, $self->src);
29 0 file_compare($src, $dest);
30 }
31  
32 sub file_repair {
33 0 ▶ my $self = shift;
Subroutine file_repair: not called CC=1 SCAR=6.9
Pod undocumented
34 0 my ($dest, $src) = ($self->dest, $self->src);
35 0 debug("Copying file: <src=$src> <dest=$dest>");
36 0 copy($src, $dest);
37 }
38
39 sub file_diff {
40 1 ▶ my $self = shift;
Subroutine file_diff: called CC=1 SCAR=0.4
Pod undocumented
41 1 my ($dest, $src) = ($self->dest, $self->src);
42 0 say(Text::Diff::diff($dest, $src));
43 }
44  
45 # Compare hashes between two files
46 sub file_compare {
47 0 ▶ my @files = @_;
Subroutine file_compare: not called CC=2 SCAR=17.9
Pod undocumented
48 0 ▶ return 0 unless (scalar @files == 2);
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @files == 2 0 0 0
49
50 # Get hashes and return compare
51 0 my ($hasha, $hashb) = map hash_file($_), @files;
52 0 debug(sprintf "File compare result: <hash=%s> <hash=%s>", $hasha, $hashb);
53 0 return ($hasha eq $hashb);
54 }
55  
56 17 1;
57 __END__
« Csistck/Config.pm ↑ Summary Csistck/Test/NOOP.pm »