line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package IO::InSitu; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
44268
|
use version; $VERSION = qv('0.0.2'); |
|
4
|
|
|
|
|
11011
|
|
|
4
|
|
|
|
|
26
|
|
4
|
|
|
|
|
|
|
|
5
|
4
|
|
|
4
|
|
384
|
use warnings; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
151
|
|
6
|
4
|
|
|
4
|
|
20
|
use strict; |
|
4
|
|
|
|
|
12
|
|
|
4
|
|
|
|
|
192
|
|
7
|
4
|
|
|
4
|
|
22
|
use Carp; |
|
4
|
|
|
|
|
22
|
|
|
4
|
|
|
|
|
490
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub import { |
10
|
4
|
|
|
4
|
|
21
|
no strict 'refs'; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
1305
|
|
11
|
4
|
|
|
4
|
|
41
|
*{caller().'::open_rw'} = \&open_rw; |
|
4
|
|
|
|
|
105
|
|
12
|
|
|
|
|
|
|
} |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub _make_tmp { |
15
|
1
|
|
|
1
|
|
3
|
my ($in_name) = @_; |
16
|
1
|
|
|
|
|
5
|
return "$in_name.bak"; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub open_rw { |
20
|
3
|
100
|
|
3
|
1
|
76891
|
my $opt_arg = ref $_[-1] eq 'HASH' ? pop : {}; |
21
|
|
|
|
|
|
|
|
22
|
3
|
|
|
|
|
17
|
my ($in_name, $out_name) = splice @_, 0, 2; |
23
|
3
|
50
|
|
|
|
19
|
$out_name = $in_name if !defined $out_name; |
24
|
|
|
|
|
|
|
|
25
|
3
|
50
|
33
|
|
|
103
|
croak 'Usage: open_rw($in_filename, $opt_out_filename, \%opt_options)' |
26
|
|
|
|
|
|
|
if @_ || !defined $out_name; |
27
|
|
|
|
|
|
|
|
28
|
3
|
100
|
|
|
|
18
|
my $make_tmp = defined $opt_arg->{tmp} ? $opt_arg->{tmp} : \&_make_tmp; |
29
|
|
|
|
|
|
|
|
30
|
3
|
50
|
33
|
|
|
105
|
croak "Can't open non-existent input file '$in_name'" |
31
|
|
|
|
|
|
|
if !( ref $in_name || -e $in_name ); |
32
|
|
|
|
|
|
|
|
33
|
3
|
|
|
|
|
8
|
my ($in, $out); |
34
|
|
|
|
|
|
|
|
35
|
3
|
50
|
|
|
|
43
|
if (-e $out_name) { |
36
|
3
|
|
|
|
|
59
|
my ($in_dev, $in_node) = stat $in_name; |
37
|
3
|
|
|
|
|
35
|
my ($out_dev, $out_node) = stat $out_name; |
38
|
|
|
|
|
|
|
|
39
|
3
|
100
|
66
|
|
|
36
|
goto NORMAL_IN if $in_dev != $out_dev || $in_node != $out_node; |
40
|
|
|
|
|
|
|
|
41
|
4
|
|
|
4
|
|
6349
|
use File::Temp qw( :POSIX ); |
|
4
|
|
|
|
|
145442
|
|
|
4
|
|
|
|
|
709
|
|
42
|
|
|
|
|
|
|
|
43
|
2
|
|
|
|
|
9
|
my $tmp_name = $make_tmp->($in_name); |
44
|
|
|
|
|
|
|
|
45
|
4
|
|
|
4
|
|
4303
|
use File::Copy; |
|
4
|
|
|
|
|
22229
|
|
|
4
|
|
|
|
|
1099
|
|
46
|
2
|
|
|
|
|
17
|
copy($in_name, $tmp_name); |
47
|
|
|
|
|
|
|
|
48
|
2
|
50
|
|
|
|
948
|
$in = IO::File::SE->new($tmp_name, '<') |
49
|
|
|
|
|
|
|
or croak "Can't open copy of input file '$in_name'"; |
50
|
|
|
|
|
|
|
|
51
|
2
|
|
|
|
|
23
|
goto NORMAL_OUT; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
NORMAL_IN: |
55
|
1
|
50
|
|
|
|
48
|
open $in, '<', $in_name |
56
|
|
|
|
|
|
|
or croak "Can't open input file '$in_name': $!"; |
57
|
|
|
|
|
|
|
|
58
|
3
|
50
|
|
|
|
303
|
NORMAL_OUT: |
59
|
|
|
|
|
|
|
open $out, '>', $out_name |
60
|
|
|
|
|
|
|
or croak "Can't open output file '$out_name': $!"; |
61
|
|
|
|
|
|
|
|
62
|
3
|
|
|
|
|
16
|
return ($in, $out); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
package IO::File::SE; |
66
|
4
|
|
|
4
|
|
31
|
use base qw( IO::File ); |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
4880
|
|
67
|
4
|
|
|
4
|
|
6048
|
use Carp; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
767
|
|
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
my %file_name_of; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub new { |
72
|
2
|
|
|
2
|
|
8
|
my ($class, $name, @otherargs) = @_; |
73
|
2
|
|
|
|
|
26
|
my $fh = $class->SUPER::new($name, @otherargs); |
74
|
2
|
|
|
|
|
564
|
$file_name_of{$fh} = $name; |
75
|
2
|
|
|
|
|
12
|
return $fh; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub DESTROY { |
79
|
2
|
|
|
2
|
|
92236
|
my ($self) = @_; |
80
|
2
|
|
|
|
|
35
|
$self->SUPER::DESTROY(); |
81
|
2
|
|
|
|
|
394
|
unlink $file_name_of{$self}; |
82
|
2
|
|
|
|
|
79
|
return; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
1; # Magic true value required at end of module |
86
|
|
|
|
|
|
|
__END__ |