line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package vars::global; |
2
|
|
|
|
|
|
|
{ |
3
|
5
|
|
|
5
|
|
134172
|
use version; $VERSION = qv('0.0.4'); |
|
5
|
|
|
|
|
13602
|
|
|
5
|
|
|
|
|
29
|
|
4
|
|
|
|
|
|
|
|
5
|
5
|
|
|
5
|
|
373
|
use warnings; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
136
|
|
6
|
5
|
|
|
5
|
|
26
|
use strict; |
|
5
|
|
|
|
|
32
|
|
|
5
|
|
|
|
|
128
|
|
7
|
5
|
|
|
5
|
|
27
|
use Carp; |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
1856
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# Module implementation here |
10
|
|
|
|
|
|
|
# Where we keep existing globals |
11
|
|
|
|
|
|
|
my %ref_for; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub import { |
14
|
8
|
|
|
8
|
|
62
|
my $package = shift; |
15
|
8
|
|
|
|
|
17
|
my $caller = caller; |
16
|
8
|
|
|
|
|
49
|
my @import; |
17
|
|
|
|
|
|
|
GRAB_IMPORTS: |
18
|
8
|
|
|
|
|
39
|
while (@_) { |
19
|
8
|
|
|
|
|
12
|
my $param = shift; |
20
|
8
|
100
|
|
|
|
32
|
last GRAB_IMPORTS if lc($param) eq 'create'; |
21
|
|
|
|
|
|
|
|
22
|
5
|
100
|
|
|
|
34
|
if (lc($param) eq ':all') { |
23
|
1
|
|
|
|
|
4
|
@import = keys %ref_for; |
24
|
1
|
|
|
|
|
4
|
while (@_) { |
25
|
0
|
0
|
|
|
|
0
|
last GRAB_IMPORTS if shift eq 'create'; |
26
|
|
|
|
|
|
|
} |
27
|
1
|
|
|
|
|
2
|
last GRAB_IMPORTS; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
4
|
|
|
|
|
14
|
push @import, $param; |
31
|
|
|
|
|
|
|
} |
32
|
8
|
|
|
|
|
29
|
$package->_create($caller, @_); |
33
|
8
|
|
|
|
|
25
|
$package->_import($caller, @import, @_); |
34
|
7
|
|
|
|
|
8240
|
return; |
35
|
|
|
|
|
|
|
} ## end sub import |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub create { |
38
|
5
|
|
|
5
|
1
|
3081
|
my $package = shift; |
39
|
5
|
|
|
|
|
9
|
my $caller = caller; |
40
|
5
|
|
|
|
|
18
|
$package->_create($caller, @_); |
41
|
0
|
|
|
|
|
0
|
$package->_import($caller, @_); |
42
|
0
|
|
|
|
|
0
|
return; |
43
|
|
|
|
|
|
|
} ## end sub create |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub has { |
46
|
16
|
|
|
16
|
1
|
21
|
my $package = shift; |
47
|
16
|
|
|
|
|
21
|
my ($symbol) = @_; |
48
|
16
|
100
|
|
|
|
308
|
return unless exists $ref_for{$symbol}; |
49
|
15
|
|
|
|
|
47
|
return $ref_for{$symbol}; |
50
|
|
|
|
|
|
|
} ## end sub has |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub _create { |
53
|
13
|
|
|
13
|
|
18
|
my $package = shift; |
54
|
13
|
|
|
|
|
20
|
my $caller = shift; |
55
|
13
|
|
|
|
|
28
|
my @symbols = @_; |
56
|
5
|
|
|
5
|
|
30
|
no strict 'refs'; |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
141
|
|
57
|
5
|
|
|
5
|
|
24
|
no warnings 'once'; |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
1486
|
|
58
|
13
|
|
|
|
|
28
|
foreach my $symbol (@symbols) { |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# Some checks |
61
|
19
|
100
|
|
|
|
188
|
croak "undefined symbol" unless defined $symbol; |
62
|
18
|
100
|
|
|
|
154
|
croak "empty symbol" unless length $symbol; |
63
|
17
|
|
|
|
|
35
|
my $identifier = substr $symbol, 1; |
64
|
17
|
100
|
|
|
|
426
|
croak "invalid identifier '$identifier'" |
65
|
|
|
|
|
|
|
unless $identifier =~ /\A \w+ \z/mxs; |
66
|
|
|
|
|
|
|
|
67
|
15
|
|
|
|
|
31
|
my $fqn = $package . '::' . $identifier; |
68
|
15
|
|
|
|
|
25
|
my $sigil = substr $symbol, 0, 1; |
69
|
4
|
|
|
|
|
29
|
$ref_for{$symbol} = |
70
|
6
|
|
|
|
|
35
|
$sigil eq '$' ? \${$fqn} |
71
|
4
|
|
|
|
|
27
|
: $sigil eq '@' ? \@{$fqn} |
72
|
15
|
100
|
|
|
|
223
|
: $sigil eq '%' ? \%{$fqn} |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
73
|
|
|
|
|
|
|
: croak "invalid sigil: '$sigil'"; |
74
|
|
|
|
|
|
|
} ## end foreach my $symbol (@symbols) |
75
|
8
|
|
|
|
|
21
|
return; |
76
|
|
|
|
|
|
|
} ## end sub _create |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub _import { |
79
|
8
|
|
|
8
|
|
14
|
my $package = shift; |
80
|
8
|
|
|
|
|
13
|
my $caller = shift; |
81
|
5
|
|
|
5
|
|
23
|
no strict 'refs'; |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
541
|
|
82
|
8
|
|
|
|
|
14
|
foreach my $symbol (@_) { |
83
|
16
|
100
|
|
|
|
37
|
my $ref = $package->has($symbol) |
84
|
|
|
|
|
|
|
or croak "non existent global: '$symbol'"; |
85
|
15
|
|
|
|
|
20
|
*{$caller . '::' . substr $symbol, 1} = $ref; |
|
15
|
|
|
|
|
71
|
|
86
|
|
|
|
|
|
|
} |
87
|
7
|
|
|
|
|
19
|
return; |
88
|
|
|
|
|
|
|
} ## end sub _import |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
1; # Magic true value required at end of module |
92
|
|
|
|
|
|
|
__END__ |