line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package IO::Die; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
169507
|
use 5.006; |
|
2
|
|
|
|
|
8
|
|
4
|
2
|
|
|
2
|
|
10
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
1255
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
#not in production |
7
|
|
|
|
|
|
|
#use warnings; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
IO::Die - Namespaced, error-checked I/O |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 VERSION |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
Version 0.057 |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=cut |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our $VERSION = '0.057'; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
22
|
|
|
|
|
|
|
#PROTECTED |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
#Override in subclasses as needed |
25
|
|
|
|
|
|
|
sub _CREATE_ERROR { |
26
|
11
|
|
|
11
|
|
22
|
shift; |
27
|
11
|
50
|
|
|
|
29
|
return shift() . ": " . join( ' ', map { defined() ? $_ : q<> } @_ ); |
|
70
|
|
|
|
|
246
|
|
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
12
|
|
|
12
|
|
157
|
sub _DO_WITH_ERROR { die $_[1] } |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
33
|
|
|
|
|
|
|
#PRIVATES |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub __THROW { |
36
|
12
|
|
|
12
|
|
38
|
my ( $NS, $type, @args ) = @_; |
37
|
|
|
|
|
|
|
|
38
|
12
|
|
|
|
|
39
|
$NS->_DO_WITH_ERROR( |
39
|
|
|
|
|
|
|
$NS->_CREATE_ERROR( |
40
|
|
|
|
|
|
|
$type, |
41
|
|
|
|
|
|
|
@args, |
42
|
|
|
|
|
|
|
OS_ERROR => $!, |
43
|
|
|
|
|
|
|
EXTENDED_OS_ERROR => $^E, |
44
|
|
|
|
|
|
|
) |
45
|
|
|
|
|
|
|
); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub __is_a_fh { |
49
|
5
|
|
|
5
|
|
10
|
my ($thing) = @_; |
50
|
|
|
|
|
|
|
|
51
|
5
|
|
|
|
|
6
|
my $is_fh; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
#Every file handle is a GLOB reference. This would be sufficient, except |
54
|
|
|
|
|
|
|
#GLOBs can also be symbol table references. |
55
|
5
|
100
|
|
|
|
28
|
if ( UNIVERSAL::isa( $thing, 'GLOB' ) ) { |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# You can’t tie() a symbol table reference, so if we’re tied(), |
58
|
|
|
|
|
|
|
# then this is a filehandle. |
59
|
|
|
|
|
|
|
# |
60
|
|
|
|
|
|
|
# If we’re not tied(), then we have to check fileno(). |
61
|
2
|
|
33
|
|
|
4
|
$is_fh = ( tied *{$thing} ) || defined( CORE::fileno($thing) ); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
5
|
|
|
|
|
22
|
return $is_fh; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
our $AUTOLOAD; |
70
|
|
|
|
|
|
|
sub AUTOLOAD { |
71
|
11
|
|
|
11
|
|
82399
|
$AUTOLOAD =~ s<.*::><>; |
72
|
|
|
|
|
|
|
|
73
|
11
|
|
|
|
|
57
|
local ($!, $^E); |
74
|
|
|
|
|
|
|
|
75
|
11
|
|
|
|
|
23
|
my $reldir = __PACKAGE__; |
76
|
11
|
|
|
|
|
32
|
$reldir =~ s<::>>g; |
77
|
|
|
|
|
|
|
|
78
|
11
|
|
|
|
|
6092
|
require "$reldir/$AUTOLOAD.pm"; |
79
|
|
|
|
|
|
|
|
80
|
11
|
|
|
|
|
92
|
return __PACKAGE__->can($AUTOLOAD)->(@_); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub import { |
84
|
1
|
|
|
1
|
|
10
|
my ($class, @tags) = @_; |
85
|
|
|
|
|
|
|
|
86
|
1
|
|
|
|
|
3
|
for my $t (@tags) { |
87
|
0
|
0
|
|
|
|
0
|
if ($t eq ':preload') { |
88
|
0
|
|
|
|
|
0
|
$class->_preload(); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
1
|
|
|
|
|
9
|
return; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub _preload { |
96
|
0
|
|
|
0
|
|
|
my ($class) = @_; |
97
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
my $path = __FILE__; |
99
|
0
|
|
|
|
|
|
$path =~ s<\.pm\z><>; |
100
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
my $reldir = __PACKAGE__; |
102
|
0
|
|
|
|
|
|
$reldir =~ s<::>>g; |
103
|
|
|
|
|
|
|
|
104
|
0
|
|
|
|
|
|
$class->opendir( my $dh, $path ); |
105
|
0
|
|
|
|
|
|
local ($!, $^E); |
106
|
0
|
|
|
|
|
|
while ( my $node = readdir $dh ) { |
107
|
0
|
0
|
|
|
|
|
next if substr( $node, -3 ) ne '.pm'; |
108
|
0
|
|
|
|
|
|
require "$reldir/$node"; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
0
|
|
|
|
|
|
return; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
1; |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
__END__ |