line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#+############################################################################## |
2
|
|
|
|
|
|
|
# # |
3
|
|
|
|
|
|
|
# File: No/Worries/Export.pm # |
4
|
|
|
|
|
|
|
# # |
5
|
|
|
|
|
|
|
# Description: symbol exporting without worries # |
6
|
|
|
|
|
|
|
# # |
7
|
|
|
|
|
|
|
#-############################################################################## |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# |
10
|
|
|
|
|
|
|
# module definition |
11
|
|
|
|
|
|
|
# |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
package No::Worries::Export; |
14
|
22
|
|
|
22
|
|
70772
|
use strict; |
|
22
|
|
|
|
|
54
|
|
|
22
|
|
|
|
|
688
|
|
15
|
22
|
|
|
22
|
|
111
|
use warnings; |
|
22
|
|
|
|
|
43
|
|
|
22
|
|
|
|
|
1676
|
|
16
|
|
|
|
|
|
|
our $VERSION = "1.7"; |
17
|
|
|
|
|
|
|
our $REVISION = sprintf("%d.%02d", q$Revision: 1.7 $ =~ /(\d+)\.(\d+)/); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# |
20
|
|
|
|
|
|
|
# used modules |
21
|
|
|
|
|
|
|
# |
22
|
|
|
|
|
|
|
|
23
|
22
|
|
|
22
|
|
12364
|
use Params::Validate qw(validate_with :types); |
|
22
|
|
|
|
|
206640
|
|
|
22
|
|
|
|
|
10712
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# |
26
|
|
|
|
|
|
|
# simple yet powerful export control |
27
|
|
|
|
|
|
|
# |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub export_control ($$$@) { |
30
|
346
|
|
|
346
|
1
|
2730
|
my($callpkg, $pkg, $exported, @names) = @_; |
31
|
346
|
|
|
|
|
551
|
my($name, $regexp, $ref); |
32
|
|
|
|
|
|
|
|
33
|
346
|
|
|
|
|
7231
|
validate_with( |
34
|
|
|
|
|
|
|
params => \@_, |
35
|
|
|
|
|
|
|
spec => [ { type => SCALAR }, { type => SCALAR }, { type => HASHREF } ], |
36
|
|
|
|
|
|
|
allow_extra => 1, |
37
|
|
|
|
|
|
|
); |
38
|
346
|
|
|
|
|
2186
|
while (@names) { |
39
|
563
|
|
|
|
|
1028
|
$name = shift(@names); |
40
|
|
|
|
|
|
|
# special case for * and /.../ and x.y |
41
|
563
|
100
|
|
|
|
2727
|
if ($name eq "*") { |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
42
|
19
|
|
|
|
|
52
|
unshift(@names, grep(!ref($exported->{$_}), keys(%{ $exported }))); |
|
19
|
|
|
|
|
169
|
|
43
|
19
|
|
|
|
|
72
|
next; |
44
|
|
|
|
|
|
|
} elsif ($name =~ /^\/(.*)\/$/) { |
45
|
0
|
|
|
|
|
0
|
$regexp = $1; |
46
|
|
|
|
|
|
|
unshift(@names, grep(/$regexp/, grep(!ref($exported->{$_}), |
47
|
0
|
|
|
|
|
0
|
keys(%{ $exported })))); |
|
0
|
|
|
|
|
0
|
|
48
|
0
|
|
|
|
|
0
|
next; |
49
|
|
|
|
|
|
|
} elsif ($name =~ /^\d/) { |
50
|
|
|
|
|
|
|
# version checking via UNIVERSAL |
51
|
0
|
|
|
|
|
0
|
$pkg->VERSION($name); |
52
|
0
|
|
|
|
|
0
|
next; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
die("\"$name\" is not exported by the $pkg module\n") |
55
|
544
|
50
|
|
|
|
1366
|
unless defined($exported->{$name}); |
56
|
544
|
|
|
|
|
1379
|
$ref = ref($exported->{$name}); |
57
|
544
|
50
|
|
|
|
926
|
if ($ref eq "") { |
|
|
0
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# normal symbol |
59
|
544
|
100
|
|
|
|
2145
|
if ($name =~ /^(\w+)$/) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# function |
61
|
22
|
|
|
22
|
|
190
|
no strict qw(refs); |
|
22
|
|
|
|
|
57
|
|
|
22
|
|
|
|
|
719
|
|
62
|
22
|
|
|
22
|
|
127
|
no warnings qw(once prototype); |
|
22
|
|
|
|
|
34
|
|
|
22
|
|
|
|
|
1986
|
|
63
|
454
|
|
|
|
|
574
|
*{"${callpkg}::${1}"} = \&{"${pkg}::${1}"}; |
|
454
|
|
|
|
|
74487
|
|
|
454
|
|
|
|
|
1770
|
|
64
|
|
|
|
|
|
|
} elsif ($name =~ /^\$(\w+)$/) { |
65
|
|
|
|
|
|
|
# scalar |
66
|
22
|
|
|
22
|
|
149
|
no strict qw(refs); |
|
22
|
|
|
|
|
54
|
|
|
22
|
|
|
|
|
2499
|
|
67
|
88
|
|
|
|
|
147
|
*{"${callpkg}::${1}"} = \${"${pkg}::${1}"}; |
|
88
|
|
|
|
|
4108
|
|
|
88
|
|
|
|
|
375
|
|
68
|
|
|
|
|
|
|
} elsif ($name =~ /^\@(\w+)$/) { |
69
|
|
|
|
|
|
|
# array |
70
|
22
|
|
|
22
|
|
150
|
no strict qw(refs); |
|
22
|
|
|
|
|
56
|
|
|
22
|
|
|
|
|
1674
|
|
71
|
1
|
|
|
|
|
2
|
*{"${callpkg}::${1}"} = \@{"${pkg}::${1}"}; |
|
1
|
|
|
|
|
20
|
|
|
1
|
|
|
|
|
7
|
|
72
|
|
|
|
|
|
|
} elsif ($name =~ /^\%(\w+)$/) { |
73
|
|
|
|
|
|
|
# hash |
74
|
22
|
|
|
22
|
|
144
|
no strict qw(refs); |
|
22
|
|
|
|
|
56
|
|
|
22
|
|
|
|
|
5187
|
|
75
|
1
|
|
|
|
|
3
|
*{"${callpkg}::${1}"} = \%{"${pkg}::${1}"}; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
5
|
|
76
|
|
|
|
|
|
|
} else { |
77
|
0
|
|
|
|
|
0
|
die("unsupported export by the $pkg module: $name\n"); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
} elsif ($ref eq "CODE") { |
80
|
|
|
|
|
|
|
# special symbol |
81
|
0
|
|
|
|
|
0
|
$exported->{$name}->($name); |
82
|
|
|
|
|
|
|
} else { |
83
|
0
|
|
|
|
|
0
|
die("unsupported export by the $pkg module: $name=$ref\n"); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
# |
89
|
|
|
|
|
|
|
# export control |
90
|
|
|
|
|
|
|
# |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub import : method { |
93
|
116
|
|
|
116
|
|
249
|
my($pkg, %exported); |
94
|
|
|
|
|
|
|
|
95
|
116
|
|
|
|
|
274
|
$pkg = shift(@_); |
96
|
116
|
|
|
|
|
459
|
grep($exported{$_}++, qw(export_control)); |
97
|
116
|
|
|
|
|
406
|
export_control(scalar(caller()), $pkg, \%exported, @_); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
1; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
__DATA__ |