line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package YATT::Lite::Util::File; |
2
|
3
|
|
|
3
|
|
171870
|
use strict; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
86
|
|
3
|
3
|
|
|
3
|
|
15
|
use warnings qw(FATAL all NONFATAL misc); |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
113
|
|
4
|
3
|
|
|
3
|
|
14
|
use Carp; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
187
|
|
5
|
3
|
|
|
3
|
|
1178
|
use YATT::Lite::Util (); |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
78
|
|
6
|
3
|
|
|
3
|
|
20
|
use File::Basename qw(dirname); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
188
|
|
7
|
3
|
|
|
3
|
|
16
|
use File::Path qw(make_path); |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
155
|
|
8
|
3
|
|
|
3
|
|
103
|
use Time::HiRes qw/usleep/; |
|
3
|
|
|
|
|
4763
|
|
|
3
|
|
|
|
|
18
|
|
9
|
3
|
|
|
3
|
|
604
|
use File::stat; |
|
3
|
|
|
|
|
24446
|
|
|
3
|
|
|
|
|
16
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub mkfile { |
12
|
36
|
|
|
36
|
0
|
15532
|
my ($pack) = shift; |
13
|
36
|
|
|
|
|
52
|
my @slept; |
14
|
36
|
|
|
|
|
149
|
while (my ($fn, $content) = splice @_, 0, 2) { |
15
|
58
|
50
|
|
|
|
181
|
($fn, my @iolayer) = ref $fn ? @$fn : ($fn); |
16
|
58
|
100
|
|
|
|
2916
|
unless (-d (my $dir = dirname($fn))) { |
17
|
36
|
50
|
|
|
|
6168
|
make_path($dir) or die "Can't mkdir $dir: $!"; |
18
|
|
|
|
|
|
|
} |
19
|
58
|
|
|
|
|
91
|
my $old_mtime; |
20
|
58
|
50
|
|
|
|
1240
|
if (-e $fn) { |
21
|
0
|
0
|
|
|
|
0
|
if (my $slept = wait_for_time(($old_mtime = stat($fn)->mtime) + 1.05)) { |
22
|
0
|
|
|
|
|
0
|
push @slept, $slept; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
} |
25
|
58
|
50
|
|
|
|
3684
|
open my $fh, join('', '>', @iolayer), $fn or die "$fn: $!"; |
26
|
58
|
|
|
|
|
301
|
print $fh $content; |
27
|
58
|
|
|
|
|
1931
|
close $fh; |
28
|
58
|
50
|
33
|
|
|
467
|
unless (not defined $old_mtime or $old_mtime < stat($fn)->mtime) { |
29
|
0
|
|
|
|
|
0
|
croak "Failed to update mtime for $fn!"; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
} |
32
|
36
|
|
|
|
|
100
|
@slept; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# |
36
|
|
|
|
|
|
|
sub wait_for_time { |
37
|
0
|
|
|
0
|
0
|
|
my ($time) = @_; |
38
|
0
|
|
|
|
|
|
my $now = Time::HiRes::time; |
39
|
0
|
|
|
|
|
|
my $diff = $time - $now; |
40
|
0
|
0
|
|
|
|
|
return if $diff <= 0; |
41
|
0
|
|
|
|
|
|
usleep(int($diff * 1000 * 1000)); |
42
|
0
|
|
|
|
|
|
$diff; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# Auto Export. |
46
|
|
|
|
|
|
|
my $symtab = YATT::Lite::Util::symtab(__PACKAGE__); |
47
|
|
|
|
|
|
|
our @EXPORT_OK = grep { |
48
|
|
|
|
|
|
|
*{$symtab->{$_}}{CODE} |
49
|
|
|
|
|
|
|
} keys %$symtab; |
50
|
|
|
|
|
|
|
|
51
|
3
|
|
|
3
|
|
1356
|
use Exporter qw(import); |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
133
|
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
1; |