line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Trap::Builder::TempFile; |
2
|
|
|
|
|
|
|
|
3
|
27
|
|
|
27
|
|
303731
|
use version; $VERSION = qv('0.3.3'); |
|
27
|
|
|
|
|
7686
|
|
|
27
|
|
|
|
|
269
|
|
4
|
|
|
|
|
|
|
|
5
|
27
|
|
|
27
|
|
2710
|
use strict; |
|
27
|
|
|
|
|
74
|
|
|
27
|
|
|
|
|
840
|
|
6
|
27
|
|
|
27
|
|
191
|
use warnings; |
|
27
|
|
|
|
|
86
|
|
|
27
|
|
|
|
|
985
|
|
7
|
27
|
|
|
27
|
|
8071
|
use IO::Handle; |
|
27
|
|
|
|
|
114838
|
|
|
27
|
|
|
|
|
1558
|
|
8
|
27
|
|
|
27
|
|
10709
|
use File::Temp qw( tempfile ); |
|
27
|
|
|
|
|
236067
|
|
|
27
|
|
|
|
|
1936
|
|
9
|
27
|
|
|
27
|
|
1774
|
use Test::Trap::Builder; |
|
27
|
|
|
|
|
83
|
|
|
27
|
|
|
|
|
1587
|
|
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
|
|
220
|
use constant GOTPERLIO => (eval "use PerlIO (); 1" || 0); |
|
27
|
|
|
27
|
|
84
|
|
|
27
|
|
|
|
|
1908
|
|
|
27
|
|
|
|
|
766
|
|
|
27
|
|
|
|
|
126
|
|
|
27
|
|
|
|
|
323
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub import { |
20
|
60
|
|
|
60
|
|
304
|
shift; # package name |
21
|
60
|
100
|
|
|
|
252
|
my $strategy_name = @_ ? shift : 'tempfile'; |
22
|
60
|
100
|
|
|
|
198
|
my $strategy_option = @_ ? shift : {}; |
23
|
60
|
|
|
|
|
671
|
Test::Trap::Builder->capture_strategy( $strategy_name => $_ ) for sub { |
24
|
404
|
|
|
404
|
|
916
|
my $self = shift; |
25
|
404
|
|
|
|
|
1094
|
my ($name, $fileno, $globref) = @_; |
26
|
404
|
|
|
|
|
1203
|
my $pid = $$; |
27
|
404
|
|
|
|
|
761
|
my ($fh, $file) = do { |
28
|
404
|
|
|
|
|
2388
|
local ($!, $^E); |
29
|
404
|
|
|
|
|
1810
|
tempfile( UNLINK => 1 ); # XXX: Test? |
30
|
|
|
|
|
|
|
}; |
31
|
|
|
|
|
|
|
# make an alias to $self->{$name}, so that the closure does not hold $self: |
32
|
404
|
|
|
|
|
178296
|
for my $buffer ($self->{$name}) { |
33
|
404
|
|
|
|
|
3904
|
$self->Teardown($_) for sub { |
34
|
|
|
|
|
|
|
# if the file is opened by some other process, that one should deal with it: |
35
|
389
|
100
|
|
|
|
1532
|
return unless $pid == $$; |
36
|
387
|
|
|
|
|
1845
|
local $/; |
37
|
387
|
|
|
|
|
2214
|
local ($!, $^E); |
38
|
387
|
|
|
|
|
9290
|
$buffer .= <$fh>; |
39
|
387
|
|
|
|
|
3131
|
close $fh; |
40
|
387
|
|
|
|
|
16282
|
unlink $file; |
41
|
|
|
|
|
|
|
}; |
42
|
|
|
|
|
|
|
} |
43
|
404
|
|
|
|
|
937
|
my @io_layers; |
44
|
|
|
|
|
|
|
IO_LAYERS: { |
45
|
404
|
|
|
|
|
801
|
GOTPERLIO or last IO_LAYERS; |
|
404
|
|
|
|
|
786
|
|
46
|
404
|
|
|
|
|
1952
|
local($!, $^E); |
47
|
404
|
100
|
|
|
|
1418
|
if ($strategy_option->{preserve_io_layers}) { |
48
|
50
|
|
|
|
|
381
|
@io_layers = PerlIO::get_layers(*$globref, output => 1); |
49
|
|
|
|
|
|
|
} |
50
|
404
|
100
|
|
|
|
1239
|
if ($strategy_option->{io_layers}) { |
51
|
18
|
|
|
|
|
47
|
push @io_layers, $strategy_option->{io_layers}; |
52
|
|
|
|
|
|
|
} |
53
|
404
|
|
|
|
|
1371
|
binmode $fh; # set the perlio layers for reading: |
54
|
404
|
|
|
1
|
|
2316
|
binmode $fh, $_ for @io_layers; |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
9
|
|
55
|
|
|
|
|
|
|
} |
56
|
404
|
|
|
|
|
2572
|
local *$globref; |
57
|
|
|
|
|
|
|
{ |
58
|
27
|
|
|
27
|
|
244
|
no warnings 'io'; |
|
27
|
|
|
|
|
80
|
|
|
27
|
|
|
|
|
5397
|
|
|
404
|
|
|
|
|
778
|
|
59
|
404
|
|
|
|
|
1494
|
local ($!, $^E); |
60
|
404
|
|
|
|
|
10295
|
open *$globref, '>>', $file; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
IO_LAYERS: { |
63
|
404
|
|
|
|
|
1132
|
GOTPERLIO or last IO_LAYERS; |
|
404
|
|
|
|
|
965
|
|
64
|
404
|
|
|
|
|
1561
|
local($!, $^E); |
65
|
404
|
|
|
|
|
1130
|
binmode *$globref; # set the perlio layers for writing: |
66
|
404
|
|
|
|
|
1841
|
binmode *$globref, $_ for @io_layers; |
67
|
|
|
|
|
|
|
} |
68
|
404
|
|
|
|
|
3059
|
*$globref->autoflush(1); |
69
|
404
|
|
|
|
|
22511
|
$self->Next; |
70
|
|
|
|
|
|
|
}; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
1; # End of Test::Trap::Builder::TempFile |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
__END__ |