line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test2::Harness::Util::File; |
2
|
5
|
|
|
5
|
|
135070
|
use strict; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
127
|
|
3
|
5
|
|
|
5
|
|
20
|
use warnings; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
162
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.001007'; |
6
|
|
|
|
|
|
|
|
7
|
5
|
|
|
5
|
|
1428
|
use IO::Handle; |
|
5
|
|
|
|
|
21146
|
|
|
5
|
|
|
|
|
199
|
|
8
|
|
|
|
|
|
|
|
9
|
5
|
|
|
5
|
|
1361
|
use Test2::Harness::Util(); |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
95
|
|
10
|
|
|
|
|
|
|
|
11
|
5
|
|
|
5
|
|
24
|
use Carp qw/croak/; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
191
|
|
12
|
5
|
|
|
5
|
|
25
|
use Fcntl qw/SEEK_SET SEEK_CUR/; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
183
|
|
13
|
|
|
|
|
|
|
|
14
|
5
|
|
|
5
|
|
1408
|
use Test2::Harness::Util::HashBase qw{ -name -_fh done -stamped -line_pos }; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
29
|
|
15
|
|
|
|
|
|
|
|
16
|
2
|
|
|
2
|
0
|
107
|
sub exists { -e $_[0]->{+NAME} } |
17
|
|
|
|
|
|
|
|
18
|
133
|
|
|
133
|
0
|
148
|
sub decode { shift; $_[0] } |
|
133
|
|
|
|
|
232
|
|
19
|
8
|
|
|
8
|
0
|
12
|
sub encode { shift; $_[0] } |
|
8
|
|
|
|
|
56
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub init { |
22
|
7
|
|
|
7
|
0
|
13
|
my $self = shift; |
23
|
|
|
|
|
|
|
|
24
|
7
|
100
|
|
|
|
149
|
croak "'name' is a required attribute" unless $self->{+NAME}; |
25
|
|
|
|
|
|
|
|
26
|
6
|
100
|
|
|
|
20
|
if (my $fh = delete $self->{fh}) { |
27
|
1
|
|
|
|
|
10
|
$fh->blocking(0); |
28
|
1
|
|
|
|
|
2
|
$self->{+_FH} = $fh; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub open_file { |
33
|
10
|
|
|
10
|
0
|
28
|
my $self = shift; |
34
|
10
|
|
|
|
|
26
|
return Test2::Harness::Util::open_file($self->{+NAME}, @_) |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub maybe_read { |
38
|
2
|
|
|
2
|
0
|
292
|
my $self = shift; |
39
|
2
|
100
|
|
|
|
23
|
return undef unless -e $self->{+NAME}; |
40
|
1
|
|
|
|
|
3
|
return $self->read; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub read { |
44
|
4
|
|
|
4
|
0
|
13
|
my $self = shift; |
45
|
4
|
|
|
|
|
14
|
my $out = Test2::Harness::Util::read_file($self->{+NAME}); |
46
|
3
|
|
|
|
|
14
|
return $self->decode($out); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub write { |
50
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
51
|
0
|
|
|
|
|
0
|
return Test2::Harness::Util::write_file_atomic($self->{+NAME}, $self->encode(@_)); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub reset { |
55
|
4
|
|
|
4
|
0
|
7
|
my $self = shift; |
56
|
4
|
|
|
|
|
19
|
delete $self->{+_FH}; |
57
|
4
|
|
|
|
|
7
|
delete $self->{+DONE}; |
58
|
4
|
|
|
|
|
6
|
delete $self->{+LINE_POS}; |
59
|
4
|
|
|
|
|
8
|
return; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub fh { |
63
|
149
|
|
|
149
|
0
|
440
|
my $self = shift; |
64
|
149
|
100
|
|
|
|
407
|
return $self->{+_FH} if $self->{+_FH}; |
65
|
|
|
|
|
|
|
|
66
|
9
|
100
|
|
|
|
28
|
$self->{+_FH} = Test2::Harness::Util::maybe_open_file($self->{+NAME}) or return undef; |
67
|
7
|
|
|
|
|
40
|
$self->{+_FH}->blocking(0); |
68
|
7
|
|
|
|
|
22
|
return $self->{+_FH}; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub read_line { |
72
|
144
|
|
|
144
|
0
|
1357
|
my $self = shift; |
73
|
144
|
|
|
|
|
211
|
my %params = @_; |
74
|
|
|
|
|
|
|
|
75
|
144
|
|
|
|
|
173
|
my $pos = $params{from}; |
76
|
144
|
100
|
100
|
|
|
284
|
$pos = $self->{+LINE_POS} ||= 0 unless defined $pos; |
77
|
|
|
|
|
|
|
|
78
|
144
|
100
|
|
|
|
198
|
my $fh = $self->fh or return undef; |
79
|
143
|
50
|
|
|
|
403
|
seek($fh,$pos,SEEK_SET) or die "Could not seek: $!"; |
80
|
|
|
|
|
|
|
|
81
|
143
|
|
|
|
|
506
|
my $line = <$fh>; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# No line, nothing to do |
84
|
143
|
100
|
66
|
|
|
399
|
return unless defined $line && length($line); |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
# Partial line, hold off unless done |
87
|
141
|
100
|
100
|
|
|
404
|
return unless $self->{+DONE} || substr($line, -1, 1) eq "\n"; |
88
|
|
|
|
|
|
|
|
89
|
129
|
|
|
|
|
180
|
my $new_pos = tell($fh); |
90
|
129
|
50
|
|
|
|
185
|
die "Failed to 'tell': $!" if $new_pos == -1; |
91
|
|
|
|
|
|
|
|
92
|
129
|
|
|
|
|
200
|
$line = $self->decode($line); |
93
|
|
|
|
|
|
|
|
94
|
129
|
100
|
66
|
|
|
352
|
$self->{+LINE_POS} = $new_pos unless defined $params{peek} || defined $params{from}; |
95
|
129
|
|
|
|
|
303
|
return ($pos, $new_pos, $line); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
1; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
__END__ |