line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Lisp::Localize; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
44
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
4
|
use vars qw($DEBUG); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
53
|
|
6
|
1
|
|
|
1
|
|
5
|
use Lisp::Symbol qw(symbolp); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
430
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub new |
9
|
|
|
|
|
|
|
{ |
10
|
2
|
|
|
2
|
0
|
3
|
my $class = shift; |
11
|
2
|
|
|
|
|
5
|
my $self = bless {}, $class; |
12
|
2
|
50
|
|
|
|
6
|
print "new $self\n" if $DEBUG; |
13
|
2
|
|
|
|
|
4
|
$self; |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub save_and_set |
17
|
|
|
|
|
|
|
{ |
18
|
4
|
|
|
4
|
0
|
8
|
my($self, $symbol, $newval) = @_; |
19
|
4
|
50
|
|
|
|
11
|
die "Not a symbol $self->local($symbol, $newval)" unless symbolp($symbol); |
20
|
4
|
50
|
|
|
|
10
|
print "Localize $symbol->{'name'}\n" if $DEBUG; |
21
|
4
|
50
|
|
|
|
18
|
die "Can't localized the same symbol twice" if exists $self->{$symbol}; |
22
|
4
|
50
|
|
|
|
10
|
unless (exists $symbol->{'value'}) { |
23
|
4
|
|
|
|
|
12
|
$self->{$symbol} = [$symbol]; |
24
|
|
|
|
|
|
|
} else { |
25
|
0
|
|
|
|
|
0
|
$self->{$symbol} = [$symbol, $symbol->{'value'}]; |
26
|
|
|
|
|
|
|
} |
27
|
4
|
|
|
|
|
15
|
$symbol->value($newval); |
28
|
4
|
|
|
|
|
9
|
$self; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub DESTROY |
32
|
|
|
|
|
|
|
{ |
33
|
2
|
|
|
2
|
|
2
|
my $self = shift; |
34
|
|
|
|
|
|
|
# restore all values |
35
|
2
|
|
|
|
|
8
|
for (values %$self) { |
36
|
4
|
|
|
|
|
5
|
my $sym = shift @$_; |
37
|
4
|
50
|
|
|
|
9
|
print "Restoring $sym->{'name'}\n" if $DEBUG; |
38
|
4
|
50
|
|
|
|
13
|
if (@$_) { |
39
|
0
|
|
|
|
|
0
|
$sym->{'value'} = shift @$_; |
40
|
|
|
|
|
|
|
} else { |
41
|
4
|
|
|
|
|
18
|
delete $sym->{'value'}; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
1; |