line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package define; |
2
|
|
|
|
|
|
|
$define::VERSION = '1.03'; |
3
|
2
|
|
|
2
|
|
52463
|
use 5.006; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
87
|
|
4
|
2
|
|
|
2
|
|
11
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
67
|
|
5
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
13
|
|
|
2
|
|
|
|
|
79
|
|
6
|
2
|
|
|
2
|
|
12
|
use Carp qw/ carp croak /; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
4048
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
my %AllPkgs; |
9
|
|
|
|
|
|
|
my %DefPkgs; |
10
|
|
|
|
|
|
|
my %Vals; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my %Forbidden = map { $_ => 1 } qw{ |
13
|
|
|
|
|
|
|
BEGIN INIT CHECK END DESTROY AUTOLOAD |
14
|
|
|
|
|
|
|
STDIN STDOUT STDERR ARGV ARGVOUT ENV INC SIG |
15
|
|
|
|
|
|
|
}; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub import { |
18
|
11
|
|
|
11
|
|
777
|
my $class = shift; |
19
|
11
|
|
|
|
|
30
|
my $pkg = (caller)[0]; |
20
|
11
|
50
|
|
|
|
32
|
if( @_ ) { |
21
|
11
|
100
|
|
|
|
26
|
if( ref $_[0] eq 'HASH' ) { |
22
|
1
|
|
|
|
|
2
|
while( my( $name, $val ) = each %{$_[0]} ) { |
|
4
|
|
|
|
|
43
|
|
23
|
3
|
|
|
|
|
7
|
do_import( $pkg, $name, $val ); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
else { |
27
|
10
|
|
|
|
|
24
|
do_import( $pkg, @_ ); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
else { |
31
|
0
|
|
|
|
|
0
|
croak "Must call 'use define' with parameters"; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub unimport { |
36
|
8
|
|
|
8
|
|
1235
|
my $class = shift; |
37
|
8
|
|
|
|
|
20
|
my $pkg = (caller)[0]; |
38
|
8
|
100
|
|
|
|
24
|
if( @_ ) { |
39
|
7
|
|
|
|
|
18
|
check_name( my $name = shift ); |
40
|
7
|
|
|
|
|
18
|
$DefPkgs{$name}{$pkg} = 1; |
41
|
7
|
100
|
|
|
|
16
|
if( $Vals{$name} ) { |
42
|
4
|
|
|
|
|
6
|
makedef( $pkg, $name, @{$Vals{$name}} ); |
|
4
|
|
|
|
|
13
|
|
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
else { |
45
|
3
|
|
|
|
|
8
|
makedef( $pkg, $name ); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
else { |
49
|
|
|
|
|
|
|
# export all Declared to pkg |
50
|
1
|
|
|
|
|
2
|
$AllPkgs{$pkg} = 1; |
51
|
1
|
|
|
|
|
6
|
while( my( $name, $val ) = each %Vals ) { |
52
|
|
|
|
|
|
|
# warn "Defining ALL $pkg:$name:$val"; |
53
|
7
|
|
|
|
|
16
|
makedef( $pkg, $name, @$val ); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub check_name { |
59
|
20
|
|
|
20
|
0
|
36
|
my $name = shift; |
60
|
20
|
50
|
33
|
|
|
231
|
if( $name =~ /^__/ |
|
|
|
33
|
|
|
|
|
61
|
|
|
|
|
|
|
or $name !~ /^_?[^\W_0-9]\w*\z/ |
62
|
|
|
|
|
|
|
or $Forbidden{$name} ) { |
63
|
0
|
|
|
|
|
0
|
croak "Define name '$name' is invalid"; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub do_import { |
68
|
13
|
|
|
13
|
0
|
30
|
my( $pkg, $name, @vals ) = @_; |
69
|
13
|
|
|
|
|
25
|
check_name( $name ); |
70
|
13
|
|
|
|
|
40
|
$DefPkgs{$name}{$pkg} = 1; |
71
|
13
|
|
|
|
|
40
|
$Vals{$name} = [ @vals ]; |
72
|
13
|
|
|
|
|
27
|
my %pkgs = ( $pkg => 1, %AllPkgs, %{$DefPkgs{$name}} ); |
|
13
|
|
|
|
|
55
|
|
73
|
13
|
|
|
|
|
34
|
for (keys %pkgs) { |
74
|
15
|
|
|
|
|
30
|
makedef( $_, $name, @vals ); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub makedef { |
79
|
29
|
|
|
29
|
0
|
61
|
my ($pkg, $name, @Vals) = @_; |
80
|
29
|
|
|
|
|
50
|
my $subname = "${pkg}::$name"; |
81
|
|
|
|
|
|
|
|
82
|
2
|
|
|
2
|
|
16
|
no strict 'refs'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
599
|
|
83
|
|
|
|
|
|
|
|
84
|
29
|
100
|
|
|
|
33
|
if (defined *{$subname}{CODE}) { |
|
29
|
|
|
|
|
195
|
|
85
|
2
|
|
|
|
|
498
|
carp "Global constant $subname redefined"; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
29
|
100
|
|
|
|
146
|
if (@Vals > 1) { |
|
|
100
|
|
|
|
|
|
89
|
2
|
|
|
1
|
|
46
|
*$subname = sub () { @Vals }; |
|
1
|
|
|
|
|
6
|
|
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
elsif (@Vals == 1) { |
92
|
24
|
|
|
|
|
34
|
my $val = $Vals[0]; |
93
|
|
|
|
|
|
|
|
94
|
24
|
100
|
|
|
|
110
|
if ($val =~ /^[0-9]+$/) { |
95
|
18
|
|
|
|
|
1038
|
*$subname = eval "sub () { $val }"; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
else { |
98
|
6
|
|
|
0
|
|
565
|
*$subname = sub () { $val }; |
|
0
|
|
|
|
|
0
|
|
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
else { |
102
|
3
|
|
|
2
|
|
164
|
*$subname = sub () { }; |
|
2
|
|
|
|
|
760
|
|
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
1; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
__END__ |