line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# package t::FF_Common; |
2
|
|
|
|
|
|
|
package Tie::FlatFile::TestHelper; |
3
|
1
|
|
|
1
|
|
723
|
use strict; |
|
1
|
|
|
|
|
11
|
|
|
1
|
|
|
|
|
44
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
5
|
1
|
|
|
1
|
|
6
|
use POSIX qw(tmpnam); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
11
|
|
6
|
1
|
|
|
1
|
|
99
|
use Exporter (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
19
|
|
7
|
1
|
|
|
1
|
|
5
|
use File::Spec::Functions; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
111
|
|
8
|
1
|
|
|
1
|
|
1356
|
use Fatal qw(open close); |
|
1
|
|
|
|
|
14633
|
|
|
1
|
|
|
|
|
7
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
BEGIN { |
11
|
1
|
|
|
1
|
|
1183
|
our @ISA = qw(Exporter); |
12
|
1
|
|
|
|
|
4
|
our @EXPORT = qw(%Common slurp_file unslurp_file testfile |
13
|
|
|
|
|
|
|
diff copy_binary ff_init ff_cleanup); |
14
|
1
|
|
|
|
|
611
|
our @EXPORT_OK = @EXPORT; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $DEBUG; |
19
|
|
|
|
|
|
|
our %Common; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub ff_init { |
23
|
1
|
50
|
|
1
|
0
|
12
|
if ("@_" =~ /\bdebug\b/) { |
24
|
0
|
|
|
|
|
0
|
$DEBUG = 1; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
1
|
50
|
|
|
|
136
|
my $tmpnam = $DEBUG ? '/tmp/tfa-test.dir' : tmpnam(); |
28
|
1
|
|
|
|
|
15
|
%Common = ( |
29
|
|
|
|
|
|
|
tempdir => $tmpnam, |
30
|
|
|
|
|
|
|
tempin => catfile($tmpnam,'input'), |
31
|
|
|
|
|
|
|
tempout => catfile($tmpnam,'output'), |
32
|
|
|
|
|
|
|
); |
33
|
|
|
|
|
|
|
|
34
|
1
|
50
|
|
|
|
17
|
return if (-d $Common{tempdir}); |
35
|
1
|
|
|
|
|
106
|
mkdir $Common{tempdir}; |
36
|
1
|
|
|
|
|
10
|
unslurp_file(catfile($Common{tempdir},'t.test.Tie-FlatFile-Array'), ''); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub ff_cleanup { |
42
|
1
|
50
|
|
1
|
0
|
28
|
return if $DEBUG; |
43
|
|
|
|
|
|
|
|
44
|
1
|
|
|
|
|
29
|
unlink $Common{tempin}; |
45
|
1
|
|
|
|
|
19
|
unlink $Common{tempout}; |
46
|
1
|
|
|
|
|
343
|
my @temps = glob(catfile($Common{tempdir},'t.*')); |
47
|
1
|
|
|
|
|
798
|
unlink @temps; |
48
|
1
|
|
|
|
|
220
|
rmdir $Common{tempdir}; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub slurp_file { |
52
|
15
|
|
|
15
|
0
|
21
|
my $filename = shift; |
53
|
15
|
|
|
|
|
16
|
my $fh; |
54
|
15
|
|
|
|
|
39
|
local $/; |
55
|
|
|
|
|
|
|
|
56
|
15
|
|
|
|
|
328
|
open $fh, '<:raw', $filename; |
57
|
15
|
|
|
|
|
1041
|
my $data = <$fh>; |
58
|
15
|
|
|
|
|
427
|
close $fh; |
59
|
15
|
|
|
|
|
310
|
$data; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub unslurp_file { |
63
|
5
|
|
|
5
|
0
|
81
|
my $filename = shift; |
64
|
5
|
|
|
|
|
5
|
my $fh; |
65
|
|
|
|
|
|
|
|
66
|
5
|
|
|
|
|
149
|
open $fh, '>:raw', $filename; |
67
|
5
|
|
|
|
|
485
|
print $fh @_; |
68
|
5
|
|
|
|
|
108
|
close $fh; |
69
|
5
|
|
|
|
|
307
|
1; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub testfile { |
73
|
34
|
|
|
34
|
0
|
1238
|
my $num = shift; |
74
|
34
|
|
|
|
|
423
|
catfile($Common{tempdir}, "t.$num"); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub diff { |
78
|
6
|
|
|
6
|
0
|
11
|
my ($name1, $name2) = @_; |
79
|
6
|
|
|
|
|
13
|
my $file1 = slurp_file($name1); |
80
|
6
|
|
|
|
|
15
|
my $file2 = slurp_file($name2); |
81
|
6
|
|
|
|
|
37
|
$file1 eq $file2; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub copy_binary { |
85
|
2
|
|
|
2
|
0
|
5
|
my ($source, $dest) = @_; |
86
|
2
|
|
|
|
|
11
|
local $/ = \1024; |
87
|
|
|
|
|
|
|
|
88
|
2
|
|
|
|
|
51
|
open (my $ifh, '<:raw', $source); |
89
|
2
|
|
|
|
|
162
|
open (my $ofh, '>:raw', $dest); |
90
|
2
|
|
|
|
|
199
|
while (my $line = <$ifh>) { |
91
|
2
|
|
|
|
|
23
|
print $ofh $line; |
92
|
|
|
|
|
|
|
} |
93
|
2
|
|
|
|
|
50
|
close $ofh; |
94
|
2
|
|
|
|
|
133
|
close $ifh; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
1; |
100
|
|
|
|
|
|
|
|