line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Fennec::Collector::TB::TempFiles; |
2
|
139
|
|
|
139
|
|
734
|
use strict; |
|
139
|
|
|
|
|
197
|
|
|
139
|
|
|
|
|
3316
|
|
3
|
139
|
|
|
139
|
|
561
|
use warnings; |
|
139
|
|
|
|
|
846
|
|
|
139
|
|
|
|
|
3242
|
|
4
|
|
|
|
|
|
|
|
5
|
139
|
|
|
139
|
|
488
|
use base 'Fennec::Collector::TB'; |
|
139
|
|
|
|
|
166
|
|
|
139
|
|
|
|
|
46881
|
|
6
|
|
|
|
|
|
|
|
7
|
139
|
|
|
139
|
|
1294
|
use File::Temp; |
|
139
|
|
|
|
|
249
|
|
|
139
|
|
|
|
|
7430
|
|
8
|
|
|
|
|
|
|
|
9
|
139
|
|
|
139
|
|
685
|
use Fennec::Util qw/ accessors verbose_message /; |
|
139
|
|
|
|
|
187
|
|
|
139
|
|
|
|
|
433
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
accessors qw/tempdir handles tempobj _pid/; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
139
|
|
|
139
|
1
|
301
|
my $class = shift; |
15
|
|
|
|
|
|
|
|
16
|
139
|
|
|
|
|
1261
|
my $self = $class->SUPER::new(@_); |
17
|
|
|
|
|
|
|
|
18
|
139
|
|
|
|
|
784
|
my $temp = File::Temp::tempdir( CLEANUP => 0 ); |
19
|
139
|
|
|
|
|
63609
|
verbose_message("# Using temp dir: '$temp' for process results\n"); |
20
|
|
|
|
|
|
|
|
21
|
139
|
|
|
|
|
802
|
$self->_pid($$); |
22
|
139
|
|
|
|
|
648
|
$self->handles( {} ); |
23
|
139
|
|
|
|
|
504
|
$self->tempobj($temp); |
24
|
139
|
|
|
|
|
684
|
$self->tempdir("$temp"); |
25
|
|
|
|
|
|
|
|
26
|
139
|
|
|
|
|
1134
|
return $self; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub report { |
30
|
704
|
|
|
704
|
0
|
1530
|
my $self = shift; |
31
|
704
|
|
|
|
|
4745
|
my %params = @_; |
32
|
|
|
|
|
|
|
|
33
|
704
|
100
|
|
|
|
3118
|
if ( $$ == $self->_pid ) { |
34
|
269
|
|
|
|
|
443
|
for my $item ( @{$params{data}} ) { |
|
269
|
|
|
|
|
723
|
|
35
|
269
|
|
|
|
|
1643
|
for my $part ( split /\r?\n/, $item ) { |
36
|
259
|
|
|
|
|
1161
|
$self->render( $params{name}, $part ); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
} |
39
|
269
|
|
|
|
|
2134
|
return; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
435
|
|
|
|
|
1119
|
my $handle; |
43
|
435
|
100
|
|
|
|
1847
|
if ( $self->handles->{$$} ) { |
44
|
311
|
|
|
|
|
910
|
$handle = $self->handles->{$$}; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
else { |
47
|
124
|
|
|
|
|
856
|
my $path = $self->tempdir . "/$$"; |
48
|
124
|
50
|
|
|
|
21444
|
open( $handle, '>', $path ) || die "$!"; |
49
|
124
|
|
|
|
|
1331
|
$self->handles->{$$} = $handle; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
435
|
|
|
|
|
1003
|
for my $item ( @{$params{data}} ) { |
|
435
|
|
|
|
|
1417
|
|
53
|
435
|
|
|
|
|
4720
|
for my $part ( split /\r?\n/, $item ) { |
54
|
415
|
|
|
|
|
6902
|
print $handle "$params{name}|$params{source}|$part\n"; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub collect { |
60
|
4079
|
|
|
4079
|
1
|
15140
|
my $self = shift; |
61
|
4079
|
100
|
|
|
|
24302
|
return unless $self->_pid == $$; |
62
|
|
|
|
|
|
|
|
63
|
3624
|
|
|
|
|
10912
|
my $handle; |
64
|
3624
|
100
|
|
|
|
22680
|
if ( $self->handles->{tempdir} ) { |
65
|
3524
|
|
|
|
|
12716
|
$handle = $self->handles->{tempdir}; |
66
|
3524
|
|
|
|
|
37876
|
rewinddir $handle; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
else { |
69
|
100
|
50
|
|
|
|
2929
|
opendir( $handle, $self->tempdir ) || die "$!"; |
70
|
100
|
|
|
|
|
703
|
$self->handles->{tempdir} = $handle; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
3624
|
|
|
|
|
139477
|
while ( my $file = readdir $handle ) { |
74
|
46315
|
|
|
|
|
139200
|
my $path = $self->tempdir . "/$file"; |
75
|
46315
|
100
|
|
|
|
598823
|
next unless -f $path; |
76
|
39067
|
100
|
|
|
|
242005
|
next unless $path =~ m/\.ready$/; |
77
|
805
|
50
|
|
|
|
48588
|
open( my $fh, '<', $path ) || die $!; |
78
|
|
|
|
|
|
|
|
79
|
805
|
|
|
|
|
20810
|
while ( my $line = <$fh> ) { |
80
|
3469
|
|
|
|
|
10695
|
chomp($line); |
81
|
3469
|
50
|
|
|
|
9593
|
next unless $line; |
82
|
3469
|
|
|
|
|
33667
|
my ( $handle, $source, $part ) = ( $line =~ m/^(\w+)\|([^\|]+)\|(.*)$/g ); |
83
|
3469
|
50
|
33
|
|
|
19792
|
warn "Bad Input: '$line'\n" unless $handle && $source; |
84
|
|
|
|
|
|
|
|
85
|
3469
|
|
|
|
|
15163
|
$self->render( $handle, $part ); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
805
|
|
|
|
|
9388
|
close($fh); |
89
|
|
|
|
|
|
|
|
90
|
805
|
50
|
|
|
|
52324
|
rename( $path => "$path.done" ) || die "Could not rename file: $!"; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub finish { |
95
|
23
|
|
|
23
|
1
|
97
|
my $self = shift; |
96
|
23
|
100
|
|
|
|
136
|
return unless $self->_pid == $$; |
97
|
|
|
|
|
|
|
|
98
|
22
|
50
|
|
|
|
119
|
$self->ready() if $self->handles->{$$}; |
99
|
|
|
|
|
|
|
|
100
|
22
|
|
|
|
|
131
|
$self->collect; |
101
|
22
|
|
|
|
|
529
|
$self->SUPER::finish(); |
102
|
|
|
|
|
|
|
|
103
|
22
|
|
|
|
|
130
|
my $handle = $self->handles->{tempdir}; |
104
|
22
|
|
|
|
|
171
|
rewinddir $handle; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
die "($$) Not all files were collected?!" |
107
|
22
|
50
|
|
|
|
506
|
if grep { m/^\d+(\.ready)?$/ } readdir $handle; |
|
153
|
|
|
|
|
674
|
|
108
|
|
|
|
|
|
|
|
109
|
22
|
50
|
|
|
|
180
|
if ( !$ENV{FENNEC_DEBUG} ) { |
110
|
22
|
|
|
|
|
169
|
rewinddir $handle; |
111
|
22
|
|
|
|
|
381
|
while ( my $file = readdir $handle ) { |
112
|
153
|
100
|
|
|
|
753
|
next unless $file =~ m/\.done$/; |
113
|
109
|
50
|
|
|
|
329
|
unlink( $self->tempdir . '/' . $file ) || warn "error deleting $file: $!"; |
114
|
|
|
|
|
|
|
} |
115
|
22
|
|
|
|
|
134
|
close($handle); |
116
|
22
|
50
|
|
|
|
171
|
rmdir( $self->tempdir ) || warn "Could not cleanup temp dir: $!"; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub ready { |
121
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
122
|
0
|
0
|
|
|
|
|
warn "No Temp Dir! $$" unless $self->tempdir; |
123
|
0
|
|
|
|
|
|
my $path = $self->tempdir . "/$$"; |
124
|
0
|
0
|
|
|
|
|
return unless -e $path; |
125
|
0
|
0
|
|
|
|
|
close( $self->handles->{$$} ) || warn "Could not close file $path - $!"; |
126
|
0
|
0
|
|
|
|
|
rename( $path => "$path.ready" ) || warn "Could not rename file $path - $!"; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
173
|
1
|
|
sub end_pid { } |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub DESTROY { |
132
|
0
|
|
|
0
|
|
|
my $self = shift; |
133
|
0
|
|
|
|
|
|
$self->ready; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
1; |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
__END__ |