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
|
|
66565
|
use strict; |
|
22
|
|
|
|
|
49
|
|
|
22
|
|
|
|
|
915
|
|
15
|
22
|
|
|
22
|
|
102
|
use warnings; |
|
22
|
|
|
|
|
27
|
|
|
22
|
|
|
|
|
1417
|
|
16
|
|
|
|
|
|
|
our $VERSION = "1.6"; |
17
|
|
|
|
|
|
|
our $REVISION = sprintf("%d.%02d", q$Revision: 1.7 $ =~ /(\d+)\.(\d+)/); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# |
20
|
|
|
|
|
|
|
# used modules |
21
|
|
|
|
|
|
|
# |
22
|
|
|
|
|
|
|
|
23
|
22
|
|
|
22
|
|
17445
|
use Params::Validate qw(validate_with :types); |
|
22
|
|
|
|
|
175931
|
|
|
22
|
|
|
|
|
9094
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# |
26
|
|
|
|
|
|
|
# simple yet powerful export control |
27
|
|
|
|
|
|
|
# |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub export_control ($$$@) { |
30
|
346
|
|
|
346
|
1
|
2500
|
my($callpkg, $pkg, $exported, @names) = @_; |
31
|
346
|
|
|
|
|
526
|
my($name, $regexp, $ref); |
32
|
|
|
|
|
|
|
|
33
|
346
|
|
|
|
|
6268
|
validate_with( |
34
|
|
|
|
|
|
|
params => \@_, |
35
|
|
|
|
|
|
|
spec => [ { type => SCALAR }, { type => SCALAR }, { type => HASHREF } ], |
36
|
|
|
|
|
|
|
allow_extra => 1, |
37
|
|
|
|
|
|
|
); |
38
|
346
|
|
|
|
|
1752
|
while (@names) { |
39
|
563
|
|
|
|
|
919
|
$name = shift(@names); |
40
|
|
|
|
|
|
|
# special case for * and /.../ and x.y |
41
|
563
|
100
|
|
|
|
2389
|
if ($name eq "*") { |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
42
|
19
|
|
|
|
|
48
|
unshift(@names, grep(!ref($exported->{$_}), keys(%{ $exported }))); |
|
19
|
|
|
|
|
142
|
|
43
|
19
|
|
|
|
|
70
|
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
|
|
|
|
1142
|
unless defined($exported->{$name}); |
56
|
544
|
|
|
|
|
798
|
$ref = ref($exported->{$name}); |
57
|
544
|
50
|
|
|
|
813
|
if ($ref eq "") { |
|
|
0
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# normal symbol |
59
|
544
|
100
|
|
|
|
1949
|
if ($name =~ /^(\w+)$/) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# function |
61
|
22
|
|
|
22
|
|
186
|
no strict qw(refs); |
|
22
|
|
|
|
|
41
|
|
|
22
|
|
|
|
|
577
|
|
62
|
22
|
|
|
22
|
|
117
|
no warnings qw(once prototype); |
|
22
|
|
|
|
|
40
|
|
|
22
|
|
|
|
|
1527
|
|
63
|
454
|
|
|
|
|
515
|
*{"${callpkg}::${1}"} = \&{"${pkg}::${1}"}; |
|
454
|
|
|
|
|
63943
|
|
|
454
|
|
|
|
|
1530
|
|
64
|
|
|
|
|
|
|
} elsif ($name =~ /^\$(\w+)$/) { |
65
|
|
|
|
|
|
|
# scalar |
66
|
22
|
|
|
22
|
|
112
|
no strict qw(refs); |
|
22
|
|
|
|
|
40
|
|
|
22
|
|
|
|
|
1842
|
|
67
|
88
|
|
|
|
|
113
|
*{"${callpkg}::${1}"} = \${"${pkg}::${1}"}; |
|
88
|
|
|
|
|
3372
|
|
|
88
|
|
|
|
|
341
|
|
68
|
|
|
|
|
|
|
} elsif ($name =~ /^\@(\w+)$/) { |
69
|
|
|
|
|
|
|
# array |
70
|
22
|
|
|
22
|
|
132
|
no strict qw(refs); |
|
22
|
|
|
|
|
38
|
|
|
22
|
|
|
|
|
1576
|
|
71
|
1
|
|
|
|
|
2
|
*{"${callpkg}::${1}"} = \@{"${pkg}::${1}"}; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
3
|
|
72
|
|
|
|
|
|
|
} elsif ($name =~ /^\%(\w+)$/) { |
73
|
|
|
|
|
|
|
# hash |
74
|
22
|
|
|
22
|
|
138
|
no strict qw(refs); |
|
22
|
|
|
|
|
43
|
|
|
22
|
|
|
|
|
4386
|
|
75
|
1
|
|
|
|
|
2
|
*{"${callpkg}::${1}"} = \%{"${pkg}::${1}"}; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
3
|
|
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
|
|
205
|
my($pkg, %exported); |
94
|
|
|
|
|
|
|
|
95
|
116
|
|
|
|
|
222
|
$pkg = shift(@_); |
96
|
116
|
|
|
|
|
369
|
grep($exported{$_}++, qw(export_control)); |
97
|
116
|
|
|
|
|
328
|
export_control(scalar(caller()), $pkg, \%exported, @_); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
1; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
__DATA__ |