line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Cant; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
require 5.005_62; |
4
|
1
|
|
|
1
|
|
2296
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
87
|
|
5
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
42
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
6
|
use Carp; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
2810
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
require Exporter; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# Items to export into callers namespace by default. Note: do not export |
14
|
|
|
|
|
|
|
# names by default without a very good reason. Use EXPORT_OK instead. |
15
|
|
|
|
|
|
|
# Do not simply export all your public functions/methods/constants. |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# This allows declaration use Cant ':all'; |
18
|
|
|
|
|
|
|
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK |
19
|
|
|
|
|
|
|
# will save memory. |
20
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw( |
21
|
|
|
|
|
|
|
cant |
22
|
|
|
|
|
|
|
wcant |
23
|
|
|
|
|
|
|
) ] ); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
our @EXPORT = qw( |
28
|
|
|
|
|
|
|
cant |
29
|
|
|
|
|
|
|
wcant |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
our $VERSION = '1.01'; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# |
34
|
|
|
|
|
|
|
# cant and wcant -- print an error message and optionally die when a |
35
|
|
|
|
|
|
|
# system or library call fails. |
36
|
|
|
|
|
|
|
# |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub _cant_fmt { |
39
|
6
|
|
|
6
|
|
8
|
my(@pre, @post, $first); |
40
|
6
|
|
|
|
|
20
|
@pre = "$0: Unable to "; |
41
|
6
|
|
|
|
|
8
|
$first = shift; |
42
|
6
|
50
|
|
|
|
16
|
if ($first =~ s:^\n::) { |
43
|
0
|
|
|
|
|
0
|
unshift @pre, "\n"; |
44
|
|
|
|
|
|
|
} |
45
|
6
|
|
|
|
|
11
|
unshift @_, $first; |
46
|
6
|
50
|
|
|
|
14
|
if (substr($_[-1], -1, 1) eq "\n") { |
47
|
|
|
|
|
|
|
# Strip the newline |
48
|
0
|
|
|
|
|
0
|
@post = ( substr( pop @_, 0, -1) ); |
49
|
|
|
|
|
|
|
} else { |
50
|
6
|
50
|
|
|
|
23
|
if ($!) { |
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# Stick the errno message on the end |
52
|
0
|
|
|
|
|
0
|
@post = ( ": $!" ); |
53
|
|
|
|
|
|
|
} elsif ($?>>8 == 0) { |
54
|
|
|
|
|
|
|
# Do nothing. No errno, no last program return code -- |
55
|
|
|
|
|
|
|
# it's kind of ambiguous |
56
|
|
|
|
|
|
|
} elsif (($? & 0377) == 0) { |
57
|
|
|
|
|
|
|
# Error return from program |
58
|
0
|
|
|
|
|
0
|
@post = ( ": program returned ", $? >> 8 ); |
59
|
|
|
|
|
|
|
} elsif (($? & 0377) == 0177) { |
60
|
|
|
|
|
|
|
# 'stopped' return from program |
61
|
0
|
|
|
|
|
0
|
@post = ( ": program stopped with signal ", $? >> 8 ); |
62
|
|
|
|
|
|
|
} else { |
63
|
|
|
|
|
|
|
# Death by signal |
64
|
0
|
|
|
|
|
0
|
@post = ( ": program died with signal ", $? & 0177 ); |
65
|
0
|
0
|
|
|
|
0
|
push @post, ", coredumped" if $? & 0200; |
66
|
|
|
|
|
|
|
} |
67
|
6
|
|
|
|
|
9
|
my($temp) = $_[0]; |
68
|
6
|
50
|
|
|
|
16
|
if ($temp =~ s:\n: join("", @post, "\n") :e) { |
|
0
|
|
|
|
|
0
|
|
69
|
0
|
|
|
|
|
0
|
shift @_; |
70
|
0
|
|
|
|
|
0
|
@post = (); |
71
|
0
|
|
|
|
|
0
|
push @pre, $temp; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
} |
74
|
6
|
|
|
|
|
22
|
(@pre, @_, @post) |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub cant { |
78
|
3
|
|
|
3
|
0
|
23
|
my($package, $file, $line) = caller; |
79
|
3
|
|
|
|
|
9
|
@_ = &_cant_fmt; |
80
|
3
|
100
|
66
|
|
|
62
|
if (!defined $package || $package eq "main" || $package eq "") { |
|
|
|
66
|
|
|
|
|
81
|
1
|
|
|
|
|
12
|
die @_, " at $file line $line\n" |
82
|
|
|
|
|
|
|
} else { |
83
|
2
|
|
|
|
|
145
|
goto &croak |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub wcant { |
88
|
3
|
|
|
3
|
0
|
91
|
my($package, $file, $line) = caller; |
89
|
3
|
|
|
|
|
8
|
@_ = &_cant_fmt; |
90
|
3
|
100
|
66
|
|
|
52
|
if (!defined $package || $package eq "main" || $package eq "") { |
|
|
|
66
|
|
|
|
|
91
|
1
|
|
|
|
|
47
|
warn @_, " at $file line $line\n" |
92
|
|
|
|
|
|
|
} else { |
93
|
2
|
|
|
|
|
271
|
goto &carp |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
1 |
98
|
|
|
|
|
|
|
__END__ |