| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# -*- perl -*- |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# |
|
4
|
|
|
|
|
|
|
# $Id: savevars.pm,v 1.13 2002/02/11 00:20:12 eserte Exp $ |
|
5
|
|
|
|
|
|
|
# Author: Slaven Rezic |
|
6
|
|
|
|
|
|
|
# |
|
7
|
|
|
|
|
|
|
# Copyright (C) 1998-2001 Slaven Rezic. All rights reserved. |
|
8
|
|
|
|
|
|
|
# This package is free software; you can redistribute it and/or |
|
9
|
|
|
|
|
|
|
# modify it under the same terms as Perl itself. |
|
10
|
|
|
|
|
|
|
# |
|
11
|
|
|
|
|
|
|
# Mail: eserte@cs.tu-berlin.de |
|
12
|
|
|
|
|
|
|
# WWW: http://user.cs.tu-berlin.de/~eserte/ |
|
13
|
|
|
|
|
|
|
# |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
package savevars; |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
$VERSION = "0.07"; |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# parts stolen from "vars.pm" |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
my $has_data_dumper = 0; |
|
22
|
|
|
|
|
|
|
eval { |
|
23
|
|
|
|
|
|
|
require Data::Dumper; |
|
24
|
|
|
|
|
|
|
$has_data_dumper = 1; |
|
25
|
|
|
|
|
|
|
}; |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my @imports; |
|
28
|
|
|
|
|
|
|
my $callpack; |
|
29
|
|
|
|
|
|
|
my $dont_write_cfgfile = 0; |
|
30
|
|
|
|
|
|
|
my $cfgfile; |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub import { |
|
33
|
5
|
|
|
5
|
|
360956
|
$callpack = caller; |
|
34
|
5
|
|
|
|
|
85
|
my $pack = shift; |
|
35
|
5
|
|
|
|
|
81
|
@imports = @_; |
|
36
|
5
|
|
|
|
|
33
|
my($sym, $ch); |
|
37
|
5
|
|
|
|
|
61
|
foreach my $s (@imports) { |
|
38
|
12
|
50
|
|
|
|
138
|
if ($s =~ /::/) { |
|
39
|
0
|
|
|
|
|
0
|
require Carp; |
|
40
|
0
|
|
|
|
|
0
|
Carp::croak("Can't declare another package's variables"); |
|
41
|
|
|
|
|
|
|
} |
|
42
|
12
|
|
|
|
|
158
|
($ch, $sym) = unpack('a1a*', $s); |
|
43
|
12
|
|
|
|
|
87
|
*{"${callpack}::$sym"} = |
|
|
4
|
|
|
|
|
109
|
|
|
44
|
4
|
|
|
|
|
13
|
( $ch eq "\$" ? \$ {"${callpack}::$sym"} |
|
45
|
4
|
|
|
|
|
22
|
: ($ch eq "\@" and $has_data_dumper) ? \@ {"${callpack}::$sym"} |
|
46
|
|
|
|
|
|
|
: ($ch eq "\%" and $has_data_dumper) ? \% {"${callpack}::$sym"} |
|
47
|
12
|
50
|
66
|
|
|
244
|
: do { |
|
|
|
100
|
33
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
0
|
require Carp; |
|
49
|
0
|
0
|
|
|
|
0
|
if (!$has_data_dumper) { |
|
50
|
0
|
|
|
|
|
0
|
Carp::croak("Can't handle variable '$ch$sym' without module Data::Dumper.\n"); |
|
51
|
|
|
|
|
|
|
} else { |
|
52
|
0
|
|
|
|
|
0
|
Carp::croak("Can't handle variable '$ch$sym'.\n"); |
|
53
|
|
|
|
|
|
|
} |
|
54
|
|
|
|
|
|
|
}); |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
|
|
57
|
5
|
|
|
|
|
37
|
my $cfgfile = cfgfile(); |
|
58
|
5
|
100
|
|
|
|
1687
|
if (-r $cfgfile) { |
|
59
|
4
|
|
|
|
|
118847
|
require Safe; |
|
60
|
4
|
|
|
|
|
215266
|
my $cpt = new Safe; |
|
61
|
4
|
|
|
|
|
4219
|
$cpt->permit(qw(:base_core)); |
|
62
|
4
|
|
|
|
|
45
|
$cpt->share_from($callpack, \@imports); |
|
63
|
4
|
|
|
|
|
264
|
$cpt->rdo($cfgfile); |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub cfgfile { |
|
68
|
12
|
100
|
|
12
|
1
|
105
|
if (!defined $cfgfile) { |
|
69
|
5
|
50
|
|
|
|
235
|
my $basename = ($0 =~ m|([^/\\]+)$| ? $1 : $0); |
|
70
|
5
|
|
50
|
|
|
54
|
$cfgfile = eval { (getpwuid($<))[7] } || $ENV{'HOME'} || ''; |
|
71
|
5
|
50
|
33
|
|
|
35
|
if ($cfgfile eq '' && $^O eq 'MSWin32') { |
|
72
|
0
|
|
|
|
|
0
|
$cfgfile = 'C:'; |
|
73
|
|
|
|
|
|
|
} |
|
74
|
5
|
|
|
|
|
39
|
$cfgfile .= "/.${basename}rc"; |
|
75
|
|
|
|
|
|
|
} |
|
76
|
12
|
|
|
|
|
46
|
$cfgfile; |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub writecfg { |
|
80
|
6
|
|
|
6
|
1
|
868
|
my $cfgfile = cfgfile(); |
|
81
|
6
|
50
|
|
|
|
75660
|
if (open(CFG, ">$cfgfile")) { |
|
82
|
6
|
|
|
|
|
25
|
foreach my $_sym (@imports) { |
|
83
|
18
|
|
|
|
|
1328
|
my($ch, $sym) = unpack('a1a*', $_sym); |
|
84
|
18
|
50
|
|
|
|
53
|
if ($has_data_dumper) { |
|
85
|
18
|
|
|
|
|
27
|
my($ref, $varname); |
|
86
|
18
|
100
|
|
|
|
59
|
if ($ch eq "\$") { |
|
87
|
6
|
|
|
|
|
467
|
$ref = eval "$ch${callpack}::$sym"; |
|
88
|
6
|
|
|
|
|
28
|
$varname = "${callpack}::$sym"; |
|
89
|
|
|
|
|
|
|
} else { |
|
90
|
12
|
|
|
|
|
614
|
$ref = eval "\\" . "$ch${callpack}::$sym"; |
|
91
|
12
|
|
|
|
|
44
|
$varname = "*${callpack}::$sym"; |
|
92
|
|
|
|
|
|
|
} |
|
93
|
18
|
|
|
|
|
154
|
print CFG Data::Dumper->Dump([$ref], [$varname]); |
|
94
|
|
|
|
|
|
|
} else { |
|
95
|
0
|
0
|
|
|
|
0
|
if ($ch eq "\$") { |
|
96
|
0
|
|
|
|
|
0
|
my $var = "${callpack}::$sym"; |
|
97
|
0
|
|
|
|
|
0
|
my $val = eval '$$var'; |
|
98
|
0
|
0
|
|
|
|
0
|
next if !defined $val; |
|
99
|
0
|
|
|
|
|
0
|
$val =~ s/([\'\\])/\\$1/g; |
|
100
|
0
|
|
|
|
|
0
|
print CFG "\$" . $callpack . "::" . $sym . " = '$val';\n"; |
|
101
|
|
|
|
|
|
|
} else { |
|
102
|
0
|
|
|
|
|
0
|
die; |
|
103
|
|
|
|
|
|
|
} |
|
104
|
|
|
|
|
|
|
} |
|
105
|
|
|
|
|
|
|
} |
|
106
|
6
|
|
|
|
|
27610
|
close CFG; |
|
107
|
6
|
|
|
|
|
60
|
1; |
|
108
|
|
|
|
|
|
|
} else { |
|
109
|
0
|
|
|
|
|
0
|
warn "Can't write configuration file $cfgfile"; |
|
110
|
0
|
|
|
|
|
0
|
0; |
|
111
|
|
|
|
|
|
|
} |
|
112
|
|
|
|
|
|
|
} |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub dont_write_cfgfile { |
|
115
|
1
|
|
|
1
|
1
|
740
|
$dont_write_cfgfile = 1; |
|
116
|
|
|
|
|
|
|
} |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
END { |
|
119
|
5
|
100
|
|
5
|
|
4015
|
writecfg() unless $dont_write_cfgfile; |
|
120
|
|
|
|
|
|
|
} |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
1; |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
__END__ |