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

filter: Statementstmt 80.7% 46 / 57 Branchbran 60.0% 18 / 30 Conditioncond 83.3% 5 / 6 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 80.0% 8 / 10 Podpod 0.0% 0 / 5 totaltotal 70.5% 79 / 112 CC 19 SCAR 17.8
CC
19
Cov
74%
add
9.7
rmdir
6.0
unlink
6.0
CRAP 5.9
« blib/lib/YATT/Lite/VFS.pm ↑ Summary blib/lib/YATT/Lite/WebMVC0/Partial/StrictIPMatch.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 auto_clean quiet);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 7 ▶sub new {
Subroutine new: called CC=3 SCAR=11.1
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 ▶ $name =~ /^(?:auto_clean|quiet)\z/
Branch: 1 branch
BranchTrueFalseTotal
$name =~ /^(?:auto_clean|quiet)\z/ or die qq[No such option for @{["YATT::Lite::Test::TestFiles"];}: $name\n] 8 0 8
14 0 or die "No such option for @{[MY]}: $name\n";
15 8 $self->{$name} = $value;
16 }
17 7 $self->mkdir();
18 7 $self
19 }
20  
21 17 ▶sub mkdir {
Subroutine mkdir: called CC=5 SCAR=16.2
Pod undocumented
22 17 (my MY $self, my ($fn)) = @_;
23 17 my $real = $_[2] = $self->catdir(grep {defined} $self->{basedir}, $fn);
24 17 ▶ unless (-d $real) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $real) { } 1 16 17
25 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
26 16 ▶ print "# o mkdir $real\n" unless $self->{quiet};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"quiet"} 12 4 16
27 16 push @{$self->{List}}, [rmdir => $real];
28 } else {
29 1 ▶ print "# o exists $real\n" unless $self->{quiet};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"quiet"} 0 1 1
30 }
31 17 $fn;
32 }
33  
34 32 ▶sub add {
Subroutine add: called CC=9 SCAR=22.7
Pod undocumented
35 32 (my MY $self, my ($fn, $content)) = @_;
36 32 my $real = "$self->{basedir}/$fn";
37 32 my $old_mtime;
38 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
39 # wait until mtime is changed.
40 3 sleep 1;
41 }
42 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
43 32 print $fh $content;
44 32 close $fh;
45 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
46 0 sleep 1;
47 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
48 }
49 32 ▶ unless ($self->{Dict}{$real}++) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"Dict"}{$real}++) 28 4 32
50 28 push @{$self->{List}}, [unlink => $real];
51 }
52 32 ▶ print "# o written: $real\n" unless $self->{quiet};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"quiet"} 20 12 32
53 32 $self
54 }
55  
56 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
57 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
58  
59 7 ▶sub DESTROY {
Subroutine DESTROY: called CC=3 SCAR=16.5
60 7 my MY $self = shift;
61 7 ▶ return unless $self->{auto_clean};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"auto_clean"} 7 0 7
62 0 foreach my $item (reverse @{$self->{List}}) {
63 0 my ($method, $arg) = @$item;
64 # print "# $method $arg\n";
65 0 $self->$method($arg);
66 }
67 }
68  
69 3 1;
« blib/lib/YATT/Lite/VFS.pm ↑ Summary blib/lib/YATT/Lite/WebMVC0/Partial/StrictIPMatch.pm »