| 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
| |||||||||||
| 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__ | ||||||||||