line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Trap::Builder::TempFile; |
2
|
|
|
|
|
|
|
|
3
|
27
|
|
|
27
|
|
321586
|
use version; $VERSION = qv('0.3.4'); |
|
27
|
|
|
|
|
7507
|
|
|
27
|
|
|
|
|
161
|
|
4
|
|
|
|
|
|
|
|
5
|
27
|
|
|
27
|
|
2186
|
use strict; |
|
27
|
|
|
|
|
1574
|
|
|
27
|
|
|
|
|
548
|
|
6
|
27
|
|
|
27
|
|
134
|
use warnings; |
|
27
|
|
|
|
|
65
|
|
|
27
|
|
|
|
|
764
|
|
7
|
27
|
|
|
27
|
|
8972
|
use IO::Handle; |
|
27
|
|
|
|
|
100051
|
|
|
27
|
|
|
|
|
1211
|
|
8
|
27
|
|
|
27
|
|
12377
|
use File::Temp qw( tempfile ); |
|
27
|
|
|
|
|
205538
|
|
|
27
|
|
|
|
|
1708
|
|
9
|
27
|
|
|
27
|
|
2246
|
use Test::Trap::Builder; |
|
27
|
|
|
|
|
61
|
|
|
27
|
|
|
|
|
1342
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
######## |
12
|
|
|
|
|
|
|
# |
13
|
|
|
|
|
|
|
# I can no longer (easily?) install Devel::Cover on 5.6.2, so silence the coverage report: |
14
|
|
|
|
|
|
|
# |
15
|
|
|
|
|
|
|
# uncoverable condition right |
16
|
|
|
|
|
|
|
# uncoverable condition false |
17
|
27
|
|
50
|
27
|
|
179
|
use constant GOTPERLIO => (eval "use PerlIO (); 1" || 0); |
|
27
|
|
|
27
|
|
59
|
|
|
27
|
|
|
|
|
1672
|
|
|
27
|
|
|
|
|
772
|
|
|
27
|
|
|
|
|
102
|
|
|
27
|
|
|
|
|
236
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub import { |
20
|
60
|
|
|
60
|
|
146
|
shift; # package name |
21
|
60
|
100
|
|
|
|
212
|
my $strategy_name = @_ ? shift : 'tempfile'; |
22
|
60
|
100
|
|
|
|
157
|
my $strategy_option = @_ ? shift : {}; |
23
|
60
|
|
|
|
|
488
|
Test::Trap::Builder->capture_strategy( $strategy_name => $_ ) for sub { |
24
|
406
|
|
|
406
|
|
686
|
my $self = shift; |
25
|
406
|
|
|
|
|
960
|
my ($name, $fileno, $globref) = @_; |
26
|
406
|
|
|
|
|
1028
|
my $pid = $$; |
27
|
406
|
|
|
|
|
600
|
my ($fh, $file) = do { |
28
|
406
|
|
|
|
|
1849
|
local ($!, $^E); |
29
|
406
|
|
|
|
|
1401
|
tempfile( UNLINK => 1 ); # XXX: Test? |
30
|
|
|
|
|
|
|
}; |
31
|
|
|
|
|
|
|
# make an alias to $self->{$name}, so that the closure does not hold $self: |
32
|
406
|
|
|
|
|
161463
|
for my $buffer ($self->{$name}) { |
33
|
406
|
|
|
|
|
3239
|
$self->Teardown($_) for sub { |
34
|
|
|
|
|
|
|
# if the file is opened by some other process, that one should deal with it: |
35
|
391
|
100
|
|
|
|
1200
|
return unless $pid == $$; |
36
|
389
|
|
|
|
|
1339
|
local $/; |
37
|
389
|
|
|
|
|
1938
|
local ($!, $^E); |
38
|
389
|
|
|
|
|
10887
|
$buffer .= <$fh>; |
39
|
389
|
|
|
|
|
3895
|
close $fh; |
40
|
389
|
|
|
|
|
16761
|
unlink $file; |
41
|
|
|
|
|
|
|
}; |
42
|
|
|
|
|
|
|
} |
43
|
406
|
|
|
|
|
743
|
my @io_layers; |
44
|
|
|
|
|
|
|
IO_LAYERS: { |
45
|
406
|
|
|
|
|
616
|
GOTPERLIO or last IO_LAYERS; |
|
406
|
|
|
|
|
568
|
|
46
|
406
|
|
|
|
|
1718
|
local($!, $^E); |
47
|
406
|
100
|
|
|
|
1096
|
if ($strategy_option->{preserve_io_layers}) { |
48
|
50
|
|
|
|
|
332
|
@io_layers = PerlIO::get_layers(*$globref, output => 1); |
49
|
|
|
|
|
|
|
} |
50
|
406
|
100
|
|
|
|
922
|
if ($strategy_option->{io_layers}) { |
51
|
18
|
|
|
|
|
37
|
push @io_layers, $strategy_option->{io_layers}; |
52
|
|
|
|
|
|
|
} |
53
|
406
|
|
|
|
|
1117
|
binmode $fh; # set the perlio layers for reading: |
54
|
406
|
|
|
1
|
|
2079
|
binmode $fh, $_ for @io_layers; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
6
|
|
55
|
|
|
|
|
|
|
} |
56
|
406
|
|
|
|
|
2347
|
local *$globref; |
57
|
|
|
|
|
|
|
{ |
58
|
27
|
|
|
27
|
|
223
|
no warnings 'io'; |
|
27
|
|
|
|
|
75
|
|
|
27
|
|
|
|
|
4862
|
|
|
406
|
|
|
|
|
592
|
|
59
|
406
|
|
|
|
|
1162
|
local ($!, $^E); |
60
|
406
|
|
|
|
|
14723
|
open *$globref, '>>', $file; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
IO_LAYERS: { |
63
|
406
|
|
|
|
|
1079
|
GOTPERLIO or last IO_LAYERS; |
|
406
|
|
|
|
|
575
|
|
64
|
406
|
|
|
|
|
1478
|
local($!, $^E); |
65
|
406
|
|
|
|
|
939
|
binmode *$globref; # set the perlio layers for writing: |
66
|
406
|
|
|
|
|
1893
|
binmode *$globref, $_ for @io_layers; |
67
|
|
|
|
|
|
|
} |
68
|
406
|
|
|
|
|
2272
|
*$globref->autoflush(1); |
69
|
406
|
|
|
|
|
18238
|
$self->Next; |
70
|
|
|
|
|
|
|
}; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
1; # End of Test::Trap::Builder::TempFile |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
__END__ |