line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Alarm::_TieSIG; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
$VERSION = 1.0; |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
Alarm::_TieSIG - Module handling tying of %SIG for alarm extensions. |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 DESCRIPTION |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
This is an internal utility module for use with the Alarm::* |
12
|
|
|
|
|
|
|
alarm extensions, that handles tying of the Perl built-in |
13
|
|
|
|
|
|
|
variable C<%SIG>. This is deep magic and you use this module |
14
|
|
|
|
|
|
|
at your own risk. |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
To use this class, simply C |
17
|
|
|
|
|
|
|
C function. This replaces C<%SIG> with a dummy tied |
18
|
|
|
|
|
|
|
hash. |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
Whenever the new C<%SIG> is accessed, this class checks to see |
21
|
|
|
|
|
|
|
if the requested key is ALRM. If so, it calls C |
22
|
|
|
|
|
|
|
for STORE's, and C for FETCHes. You must provide |
23
|
|
|
|
|
|
|
both of these methods in your package. |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
All other operations are passed on to the original, magic C<%SIG>. |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
Note: Do I call C more than once. Doing so |
28
|
|
|
|
|
|
|
produces a warning and no other effects. |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head1 EXAMPLE |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
The following code will disable, with warnings, attempts to |
33
|
|
|
|
|
|
|
set SIGALRM handlers in your program (although it's not |
34
|
|
|
|
|
|
|
impossible to get past if someone really wanted to): |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
use Alarm::_TieSIG; |
37
|
|
|
|
|
|
|
Alarm::_TieSIG::tiesig(); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub sethandler { |
40
|
|
|
|
|
|
|
warn "\$SIG{ALRM} has been disabled.\n"; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub gethandler { |
44
|
|
|
|
|
|
|
warn "\$SIG{ALRM} has been disabled.\n"; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 DISCLAIMER |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
This module is not guaranteed to work. In fact, it will probably |
50
|
|
|
|
|
|
|
break at the most inconvient time. If this module breaks your |
51
|
|
|
|
|
|
|
program, destroys your computer, ruins your life, or otherwise |
52
|
|
|
|
|
|
|
makes you unhappy, do I complain (especially not to me). |
53
|
|
|
|
|
|
|
It's your own fault. |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 AUTHOR |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
Written by Cory Johns (c) 2001. |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=cut |
60
|
|
|
|
|
|
|
|
61
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
27
|
|
62
|
1
|
|
|
1
|
|
14
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
77
|
|
63
|
|
|
|
|
|
|
|
64
|
1
|
|
|
1
|
|
5
|
use vars qw($realSig); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
197
|
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub tiesig { |
67
|
0
|
0
|
|
0
|
0
|
|
if($realSig) { |
68
|
0
|
|
|
|
|
|
carp "Attempt to re-tie %SIG"; |
69
|
0
|
|
|
|
|
|
return; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
$realSig = \%SIG; # Save old %SIG. |
73
|
0
|
|
|
|
|
|
*SIG = {}; # Replace %SIG with a dummy. |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
my $userPkg = caller; |
76
|
0
|
|
|
|
|
|
return tie %SIG, __PACKAGE__, $userPkg, @_; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub _setAlrm { |
80
|
0
|
|
|
0
|
|
|
$realSig->{ALRM} = shift; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub TIEHASH { |
84
|
0
|
|
|
0
|
|
|
return bless {'userPkg'=>$_[1]}, shift; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub STORE { |
88
|
0
|
|
|
0
|
|
|
my ($self, $key, $value) = @_; |
89
|
|
|
|
|
|
|
|
90
|
0
|
0
|
|
|
|
|
if($key eq 'ALRM') { |
91
|
1
|
|
|
1
|
|
4
|
no strict 'refs'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
79
|
|
92
|
0
|
|
|
|
|
|
&{"$self->{userPkg}::sethandler"}($value); |
|
0
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
} else { |
94
|
0
|
|
|
|
|
|
$realSig->{$key} = $value; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub FETCH { |
99
|
0
|
|
|
0
|
|
|
my ($self, $key) = @_; |
100
|
|
|
|
|
|
|
|
101
|
0
|
0
|
|
|
|
|
if($key eq 'ALRM') { |
102
|
1
|
|
|
1
|
|
4
|
no strict 'refs'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
153
|
|
103
|
0
|
|
|
|
|
|
&{"$self->{userPkg}::gethandler"}(); |
|
0
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
} else { |
105
|
0
|
|
|
|
|
|
return $realSig->{$key}; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub EXISTS { |
110
|
0
|
|
|
0
|
|
|
return exists $realSig->{$_[1]}; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub DELETE { |
114
|
0
|
|
|
0
|
|
|
return delete $realSig->{$_[1]}; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub CLEAR { |
118
|
0
|
|
|
0
|
|
|
return %$realSig = (); |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub FIRSTKEY { |
122
|
0
|
|
|
0
|
|
|
return each %$realSig; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub NEXTKEY { |
126
|
0
|
|
|
0
|
|
|
return each %$realSig; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
0
|
|
|
0
|
|
|
sub DESTROY { |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
1; |