blib/lib/YATT/Lite/Test/TestFiles.pm

filter: Statementstmt 81.8% 45 / 55 Branchbran 60.7% 17 / 28 Conditioncond 83.3% 5 / 6 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 80.0% 8 / 10 Podpod 0.0% 0 / 5 totaltotal 71.3% 77 / 108 CC 18 SCAR 17.8
CC
18
Cov
75%
add
9.7
rmdir
6.0
unlink
6.0
CRAP 5.9
« blib/lib/YATT/Lite/Test/XHFTest.pm ↑ Summary blib/lib/YATT/Lite/Util/File.pm »
1 package
2 YATT::Lite::Test::TestFiles;
3 sub MY () {__PACKAGE__}
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use warnings qw(FATAL all NONFATAL misc);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use base qw/File::Spec/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use fields qw(basedir Dict List cf_auto_clean cf_quiet);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 7 ▶sub new {
Subroutine new: called CC=2 SCAR=6.9
Pod undocumented
10 7 my MY $self = fields::new(shift);
11 7 $self->{basedir} = shift;
12 7 ▶ while (my ($name, $value) = splice @_, 0, 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@_, 0, 2)) 8 7 15
13 8 $self->{"cf_$name"} = $value;
14 }
15 7 $self->mkdir();
16 7 $self
17 }
18  
19 17 ▶sub mkdir {
Subroutine mkdir: called CC=5 SCAR=16.2
Pod undocumented
20 17 (my MY $self, my ($fn)) = @_;
21 17 my $real = $_[2] = $self->catdir(grep {defined} $self->{basedir}, $fn);
22 17 ▶ unless (-d $real) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $real) { } 1 16 17
23 16 ▶ CORE::mkdir($real) or die "Can't mkdir $real: $!";
Branch: 1 branch
BranchTrueFalseTotal
CORE::mkdir $real or die "Can't mkdir ${real}: $!" 16 0 16
24 16 ▶ print "# o mkdir $real\n" unless $self->{cf_quiet};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"cf_quiet"} 12 4 16
25 16 push @{$self->{List}}, [rmdir => $real];
26 } else {
27 1 ▶ print "# o exists $real\n" unless $self->{cf_quiet};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"cf_quiet"} 0 1 1
28 }
29 17 $fn;
30 }
31  
32 32 ▶sub add {
Subroutine add: called CC=9 SCAR=22.7
Pod undocumented
33 32 (my MY $self, my ($fn, $content)) = @_;
34 32 my $real = "$self->{basedir}/$fn";
35 32 my $old_mtime;
36 32 ▶ while (-e $real and ($old_mtime = (stat($real))[9]) == time) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $real and ($old_mtime = (stat $real)[9]) == time) 3 32 35
Condition100%3/3
-e $real and ($old_mtime = (stat $real)[9]) == time
!ll&&!rl&&r
2843
MC/DC100%2/2
-e $real and ($old_mtime = (stat $real)[9]) == time
-e $real ($old_mtime = (stat $real)[9]) == time
Truth table100%3/3
A and B
A= -e $realB= ($old_mtime = (stat $real)[9]) == time
ABresult
0X0
100
111
37 # wait until mtime is changed.
38 3 sleep 1;
39 }
40 32 ▶ open my $fh, '>', $real or die "Can't create $real: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $real or die "Can't create ${real}: $!" 32 0 32
41 32 print $fh $content;
42 32 close $fh;
43 32 ▶ if (defined $old_mtime and (stat($real))[9] <= $old_mtime) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $old_mtime and (stat $real)[9] <= $old_mtime) 0 32 32
Condition66%2/3
defined $old_mtime and (stat $real)[9] <= $old_mtime
!ll&&!rl&&r
2840
MC/DC0%0/2
defined $old_mtime and (stat $real)[9] <= $old_mtime
defined $old_mtime (stat $real)[9] <= $old_mtime
Truth table66%2/3
A and B
A= defined $old_mtimeB= (stat $real)[9] <= $old_mtime
ABresult
0X0
100
111
44 0 sleep 1;
45 0 ▶ utime(undef, undef, $real) || warn "Can't touch $real: $!";
Branch: 1 branch
BranchTrueFalseTotal
utime undef, undef, $real or warn "Can't touch ${real}: $!" 0 0 0
46 }
47 32 ▶ unless ($self->{Dict}{$real}++) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"Dict"}{$real}++) 28 4 32
48 28 push @{$self->{List}}, [unlink => $real];
49 }
50 32 ▶ print "# o written: $real\n" unless $self->{cf_quiet};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"cf_quiet"} 20 12 32
51 32 $self
52 }
53  
54 0 ▶sub rmdir {my ($self, $fn) = @_; CORE::rmdir($fn) or warn "# rmdir $fn: $!"};
Subroutine rmdir: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
CORE::rmdir $fn or warn "# rmdir ${fn}: $!" 0 0 0
55 0 ▶sub unlink {my ($self, $fn) = @_; CORE::unlink($fn) or warn "# rm $fn: $!"};
Subroutine unlink: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
CORE::unlink $fn or warn "# rm ${fn}: $!" 0 0 0
56  
57 7 ▶sub DESTROY {
Subroutine DESTROY: called CC=3 SCAR=16.5
58 7 my MY $self = shift;
59 7 ▶ return unless $self->{cf_auto_clean};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"cf_auto_clean"} 7 0 7
60 0 foreach my $item (reverse @{$self->{List}}) {
61 0 my ($method, $arg) = @$item;
62 # print "# $method $arg\n";
63 0 $self->$method($arg);
64 }
65 }
66  
67 3 1;
« blib/lib/YATT/Lite/Test/XHFTest.pm ↑ Summary blib/lib/YATT/Lite/Util/File.pm »