line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Trap::Builder::TempFile; |
2
|
|
|
|
|
|
|
|
3
|
27
|
|
|
27
|
|
282710
|
use version; $VERSION = qv('0.3.5'); |
|
27
|
|
|
|
|
6286
|
|
|
27
|
|
|
|
|
142
|
|
4
|
|
|
|
|
|
|
|
5
|
27
|
|
|
27
|
|
1868
|
use strict; |
|
27
|
|
|
|
|
47
|
|
|
27
|
|
|
|
|
478
|
|
6
|
27
|
|
|
27
|
|
113
|
use warnings; |
|
27
|
|
|
|
|
42
|
|
|
27
|
|
|
|
|
539
|
|
7
|
27
|
|
|
27
|
|
7380
|
use IO::Handle; |
|
27
|
|
|
|
|
83060
|
|
|
27
|
|
|
|
|
1127
|
|
8
|
27
|
|
|
27
|
|
10250
|
use File::Temp qw( tempfile ); |
|
27
|
|
|
|
|
170138
|
|
|
27
|
|
|
|
|
1282
|
|
9
|
27
|
|
|
27
|
|
1982
|
use Test::Trap::Builder; |
|
27
|
|
|
|
|
53
|
|
|
27
|
|
|
|
|
1149
|
|
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
|
|
156
|
use constant GOTPERLIO => (eval "use PerlIO (); 1" || 0); |
|
27
|
|
|
27
|
|
61
|
|
|
27
|
|
|
|
|
1321
|
|
|
27
|
|
|
|
|
649
|
|
|
27
|
|
|
|
|
92
|
|
|
27
|
|
|
|
|
190
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub import { |
20
|
60
|
|
|
60
|
|
126
|
shift; # package name |
21
|
60
|
100
|
|
|
|
163
|
my $strategy_name = @_ ? shift : 'tempfile'; |
22
|
60
|
100
|
|
|
|
134
|
my $strategy_option = @_ ? shift : {}; |
23
|
60
|
|
|
|
|
375
|
Test::Trap::Builder->capture_strategy( $strategy_name => $_ ) for sub { |
24
|
406
|
|
|
406
|
|
575
|
my $self = shift; |
25
|
406
|
|
|
|
|
718
|
my ($name, $fileno, $globref) = @_; |
26
|
406
|
|
|
|
|
740
|
my $pid = $$; |
27
|
406
|
|
|
|
|
511
|
my ($fh, $file) = do { |
28
|
406
|
|
|
|
|
1541
|
local ($!, $^E); |
29
|
406
|
|
|
|
|
1196
|
tempfile( UNLINK => 1 ); # XXX: Test? |
30
|
|
|
|
|
|
|
}; |
31
|
|
|
|
|
|
|
# make an alias to $self->{$name}, so that the closure does not hold $self: |
32
|
406
|
|
|
|
|
132489
|
for my $buffer ($self->{$name}) { |
33
|
406
|
|
|
|
|
2619
|
$self->Teardown($_) for sub { |
34
|
|
|
|
|
|
|
# if the file is opened by some other process, that one should deal with it: |
35
|
391
|
100
|
|
|
|
1035
|
return unless $pid == $$; |
36
|
389
|
|
|
|
|
1155
|
local $/; |
37
|
389
|
|
|
|
|
1656
|
local ($!, $^E); |
38
|
389
|
|
|
|
|
10406
|
$buffer .= <$fh>; |
39
|
389
|
|
|
|
|
3626
|
close $fh; |
40
|
389
|
|
|
|
|
17337
|
unlink $file; |
41
|
|
|
|
|
|
|
}; |
42
|
|
|
|
|
|
|
} |
43
|
406
|
|
|
|
|
618
|
my @io_layers; |
44
|
|
|
|
|
|
|
IO_LAYERS: { |
45
|
406
|
|
|
|
|
547
|
GOTPERLIO or last IO_LAYERS; |
|
406
|
|
|
|
|
663
|
|
46
|
406
|
|
|
|
|
1439
|
local($!, $^E); |
47
|
406
|
100
|
|
|
|
915
|
if ($strategy_option->{preserve_io_layers}) { |
48
|
50
|
|
|
|
|
253
|
@io_layers = PerlIO::get_layers(*$globref, output => 1); |
49
|
|
|
|
|
|
|
} |
50
|
406
|
100
|
|
|
|
794
|
if ($strategy_option->{io_layers}) { |
51
|
18
|
|
|
|
|
28
|
push @io_layers, $strategy_option->{io_layers}; |
52
|
|
|
|
|
|
|
} |
53
|
406
|
|
|
|
|
912
|
binmode $fh; # set the perlio layers for reading: |
54
|
406
|
|
|
1
|
|
1741
|
binmode $fh, $_ for @io_layers; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
55
|
|
|
|
|
|
|
} |
56
|
406
|
|
|
|
|
1840
|
local *$globref; |
57
|
|
|
|
|
|
|
{ |
58
|
27
|
|
|
27
|
|
182
|
no warnings 'io'; |
|
27
|
|
|
|
|
67
|
|
|
27
|
|
|
|
|
4077
|
|
|
406
|
|
|
|
|
471
|
|
59
|
406
|
|
|
|
|
939
|
local ($!, $^E); |
60
|
406
|
|
|
|
|
11932
|
open *$globref, '>>', $file; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
IO_LAYERS: { |
63
|
406
|
|
|
|
|
918
|
GOTPERLIO or last IO_LAYERS; |
|
406
|
|
|
|
|
475
|
|
64
|
406
|
|
|
|
|
1193
|
local($!, $^E); |
65
|
406
|
|
|
|
|
788
|
binmode *$globref; # set the perlio layers for writing: |
66
|
406
|
|
|
|
|
1534
|
binmode *$globref, $_ for @io_layers; |
67
|
|
|
|
|
|
|
} |
68
|
406
|
|
|
|
|
1979
|
*$globref->autoflush(1); |
69
|
406
|
|
|
|
|
14707
|
$self->Next; |
70
|
|
|
|
|
|
|
}; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
1; # End of Test::Trap::Builder::TempFile |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
__END__ |