line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Fennec::Collector::TB::TempFiles; |
2
|
139
|
|
|
139
|
|
750
|
use strict; |
|
139
|
|
|
|
|
267
|
|
|
139
|
|
|
|
|
5100
|
|
3
|
139
|
|
|
139
|
|
690
|
use warnings; |
|
139
|
|
|
|
|
208
|
|
|
139
|
|
|
|
|
4330
|
|
4
|
|
|
|
|
|
|
|
5
|
139
|
|
|
139
|
|
749
|
use base 'Fennec::Collector::TB'; |
|
139
|
|
|
|
|
202
|
|
|
139
|
|
|
|
|
83055
|
|
6
|
|
|
|
|
|
|
|
7
|
139
|
|
|
139
|
|
854
|
use File::Temp; |
|
139
|
|
|
|
|
429
|
|
|
139
|
|
|
|
|
11706
|
|
8
|
|
|
|
|
|
|
|
9
|
139
|
|
|
139
|
|
934
|
use Fennec::Util qw/ accessors verbose_message /; |
|
139
|
|
|
|
|
247
|
|
|
139
|
|
|
|
|
629
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
accessors qw/tempdir handles tempobj _pid/; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
139
|
|
|
139
|
1
|
439
|
my $class = shift; |
15
|
|
|
|
|
|
|
|
16
|
139
|
|
|
|
|
1877
|
my $self = $class->SUPER::new(@_); |
17
|
|
|
|
|
|
|
|
18
|
139
|
|
|
|
|
1212
|
my $temp = File::Temp::tempdir( CLEANUP => 0 ); |
19
|
139
|
|
|
|
|
118277
|
verbose_message("# Using temp dir: '$temp' for process results\n"); |
20
|
|
|
|
|
|
|
|
21
|
139
|
|
|
|
|
1608
|
$self->_pid($$); |
22
|
139
|
|
|
|
|
848
|
$self->handles( {} ); |
23
|
139
|
|
|
|
|
970
|
$self->tempobj($temp); |
24
|
139
|
|
|
|
|
879
|
$self->tempdir("$temp"); |
25
|
|
|
|
|
|
|
|
26
|
139
|
|
|
|
|
752
|
return $self; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub report { |
30
|
700
|
|
|
700
|
0
|
3385
|
my $self = shift; |
31
|
700
|
|
|
|
|
8580
|
my %params = @_; |
32
|
|
|
|
|
|
|
|
33
|
700
|
100
|
|
|
|
5402
|
if ( $$ == $self->_pid ) { |
34
|
267
|
|
|
|
|
527
|
for my $item ( @{$params{data}} ) { |
|
267
|
|
|
|
|
730
|
|
35
|
534
|
|
|
|
|
2436
|
for my $part ( split /\r?\n/, $item ) { |
36
|
257
|
|
|
|
|
1732
|
$self->render( $params{name}, $part ); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
} |
39
|
267
|
|
|
|
|
2645
|
return; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
433
|
|
|
|
|
1349
|
my $handle; |
43
|
433
|
100
|
|
|
|
3512
|
if ( $self->handles->{$$} ) { |
44
|
309
|
|
|
|
|
2745
|
$handle = $self->handles->{$$}; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
else { |
47
|
124
|
|
|
|
|
1228
|
my $path = $self->tempdir . "/$$"; |
48
|
124
|
50
|
|
|
|
234703
|
open( $handle, '>', $path ) || die "$!"; |
49
|
124
|
|
|
|
|
1197
|
$self->handles->{$$} = $handle; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
433
|
|
|
|
|
1418
|
for my $item ( @{$params{data}} ) { |
|
433
|
|
|
|
|
3785
|
|
53
|
866
|
|
|
|
|
12133
|
for my $part ( split /\r?\n/, $item ) { |
54
|
413
|
|
|
|
|
11219
|
print $handle "$params{name}|$params{source}|$part\n"; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub collect { |
60
|
9641
|
|
|
9641
|
1
|
25155
|
my $self = shift; |
61
|
9641
|
100
|
|
|
|
250732
|
return unless $self->_pid == $$; |
62
|
|
|
|
|
|
|
|
63
|
8542
|
|
|
|
|
38075
|
my $handle; |
64
|
8542
|
100
|
|
|
|
69689
|
if ( $self->handles->{tempdir} ) { |
65
|
8444
|
|
|
|
|
42094
|
$handle = $self->handles->{tempdir}; |
66
|
8444
|
|
|
|
|
1054945
|
rewinddir $handle; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
else { |
69
|
98
|
50
|
|
|
|
4441
|
opendir( $handle, $self->tempdir ) || die "$!"; |
70
|
98
|
|
|
|
|
1289
|
$self->handles->{tempdir} = $handle; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
8542
|
|
|
|
|
397990
|
while ( my $file = readdir $handle ) { |
74
|
109846
|
|
|
|
|
481050
|
my $path = $self->tempdir . "/$file"; |
75
|
109846
|
100
|
|
|
|
5546908
|
next unless -f $path; |
76
|
92762
|
100
|
|
|
|
826804
|
next unless $path =~ m/\.ready$/; |
77
|
814
|
50
|
|
|
|
114763
|
open( my $fh, '<', $path ) || die $!; |
78
|
|
|
|
|
|
|
|
79
|
814
|
|
|
|
|
132177
|
while ( my $line = <$fh> ) { |
80
|
3226
|
|
|
|
|
45562
|
chomp($line); |
81
|
3226
|
50
|
|
|
|
7750
|
next unless $line; |
82
|
3226
|
|
|
|
|
47455
|
my ( $handle, $source, $part ) = ( $line =~ m/^(\w+)\|([^\|]+)\|(.*)$/g ); |
83
|
3226
|
50
|
33
|
|
|
26186
|
warn "Bad Input: '$line'\n" unless $handle && $source; |
84
|
|
|
|
|
|
|
|
85
|
3226
|
|
|
|
|
43690
|
$self->render( $handle, $part ); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
814
|
|
|
|
|
106826
|
close($fh); |
89
|
|
|
|
|
|
|
|
90
|
814
|
50
|
|
|
|
457332
|
rename( $path => "$path.done" ) || die "Could not rename file: $!"; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub finish { |
95
|
23
|
|
|
23
|
1
|
78
|
my $self = shift; |
96
|
23
|
100
|
|
|
|
268
|
return unless $self->_pid == $$; |
97
|
|
|
|
|
|
|
|
98
|
22
|
50
|
|
|
|
148
|
$self->ready() if $self->handles->{$$}; |
99
|
|
|
|
|
|
|
|
100
|
22
|
|
|
|
|
111
|
$self->collect; |
101
|
22
|
|
|
|
|
496
|
$self->SUPER::finish(); |
102
|
|
|
|
|
|
|
|
103
|
22
|
|
|
|
|
147
|
my $handle = $self->handles->{tempdir}; |
104
|
22
|
|
|
|
|
131
|
rewinddir $handle; |
105
|
|
|
|
|
|
|
|
106
|
153
|
|
|
|
|
707
|
die "($$) Not all files were collected?!" |
107
|
22
|
50
|
|
|
|
353
|
if grep { m/^\d+(\.ready)?$/ } readdir $handle; |
108
|
|
|
|
|
|
|
|
109
|
22
|
50
|
|
|
|
168
|
if ( !$ENV{FENNEC_DEBUG} ) { |
110
|
22
|
|
|
|
|
119
|
rewinddir $handle; |
111
|
22
|
|
|
|
|
388
|
while ( my $file = readdir $handle ) { |
112
|
153
|
100
|
|
|
|
916
|
next unless $file =~ m/\.done$/; |
113
|
109
|
50
|
|
|
|
359
|
unlink( $self->tempdir . '/' . $file ) || warn "error deleting $file: $!"; |
114
|
|
|
|
|
|
|
} |
115
|
22
|
|
|
|
|
83
|
close($handle); |
116
|
22
|
50
|
|
|
|
131
|
rmdir( $self->tempdir ) || warn "Could not cleanup temp dir: $!"; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub ready { |
121
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
122
|
0
|
0
|
|
|
|
0
|
warn "No Temp Dir! $$" unless $self->tempdir; |
123
|
0
|
|
|
|
|
0
|
my $path = $self->tempdir . "/$$"; |
124
|
0
|
0
|
|
|
|
0
|
return unless -e $path; |
125
|
0
|
0
|
|
|
|
0
|
close( $self->handles->{$$} ) || warn "Could not close file $path - $!"; |
126
|
0
|
0
|
|
|
|
0
|
rename( $path => "$path.ready" ) || warn "Could not rename file $path - $!"; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
173
|
|
|
173
|
1
|
7143
|
sub end_pid { } |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub DESTROY { |
132
|
0
|
|
|
0
|
|
|
my $self = shift; |
133
|
0
|
|
|
|
|
|
$self->ready; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
1; |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
__END__ |