line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package vars::i; |
2
|
3
|
|
|
3
|
|
201927
|
use 5.006; |
|
3
|
|
|
|
|
30
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
our $VERSION = '1.10'; # TRIAL |
5
|
|
|
|
|
|
|
|
6
|
3
|
|
|
3
|
|
19
|
use strict qw(vars subs); |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
96
|
|
7
|
3
|
|
|
3
|
|
16
|
use warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
2194
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub import { |
10
|
27
|
100
|
|
27
|
|
13423
|
return if @_ < 2; |
11
|
24
|
|
|
|
|
63
|
my( $pack, $var, @value ) = @_; |
12
|
24
|
|
|
|
|
51
|
my $callpack = caller; |
13
|
|
|
|
|
|
|
|
14
|
24
|
|
|
|
|
34
|
my %definitions; |
15
|
|
|
|
|
|
|
|
16
|
24
|
100
|
100
|
|
|
116
|
if( not @value ){ |
|
|
100
|
|
|
|
|
|
17
|
5
|
100
|
|
|
|
14
|
if( ref $var ){ # E.g., use vars [ foo=>, bar=>... ]; |
18
|
4
|
|
|
|
|
13
|
%definitions = @$var; |
19
|
|
|
|
|
|
|
} else { |
20
|
1
|
|
|
|
|
37
|
return; # No value given --- no-op; not an error. |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
} elsif(@value == 1 && ref $value[0]) { # E.g., use vars foo=>{} |
23
|
3
|
|
|
|
|
8
|
%definitions = ( $var => $value[0] ); |
24
|
|
|
|
|
|
|
} else { |
25
|
16
|
|
|
|
|
55
|
%definitions = ( $var => [@value] ); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
23
|
|
|
|
|
69
|
for my $k( keys %definitions ){ |
29
|
25
|
|
|
|
|
40
|
$var = $k; |
30
|
25
|
100
|
|
|
|
68
|
if( ref $definitions{$k} eq 'ARRAY' ){ |
|
|
100
|
|
|
|
|
|
31
|
19
|
|
|
|
|
26
|
@value = @{ $definitions{$k} }; |
|
19
|
|
|
|
|
40
|
|
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
elsif( ref $definitions{$k} eq 'HASH' ){ |
34
|
3
|
|
|
|
|
12
|
@value = %{ $definitions{$k} }; |
|
3
|
|
|
|
|
10
|
|
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
else { |
37
|
3
|
|
|
|
|
7
|
@value = $definitions{$k}; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
|
41
|
25
|
100
|
|
|
|
149
|
if( my( $ch, $sym ) = $var =~ /^([\$\@\%\*\&])(.+)$/ ){ |
42
|
23
|
100
|
100
|
|
|
170
|
if( $sym !~ /^(\w+(::|'))+\w+$/ && $sym =~ /\W|(^\d+$)/ ){ |
43
|
|
|
|
|
|
|
# ^^ Skip fully-qualified names ^^ Check special names |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# A variable name we can't or won't handle |
46
|
9
|
|
|
|
|
46
|
require Carp; |
47
|
|
|
|
|
|
|
|
48
|
9
|
100
|
|
|
|
41
|
if( $sym =~ /^\w+[[{].*[]}]$/ ){ |
|
|
100
|
|
|
|
|
|
49
|
2
|
|
|
|
|
214
|
Carp::croak("Can't declare individual elements of hash or array"); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
elsif( $sym =~ /^(\d+|\W|\^[\[\]A-Z\^_\?]|\{\^[a-zA-Z0-9]+\})$/ ){ |
52
|
5
|
|
|
|
|
525
|
Carp::croak("Refusing to initialize special variable $ch$sym"); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
else { |
55
|
2
|
|
|
|
|
194
|
Carp::croak("I can't recognize $ch$sym as a variable name"); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
14
|
100
|
|
|
|
43
|
$sym = "${callpack}::$sym" unless $sym =~ /::/; |
60
|
|
|
|
|
|
|
|
61
|
14
|
100
|
|
|
|
40
|
if( $ch eq '$' ){ |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
62
|
4
|
|
|
|
|
16
|
*{$sym} = \$$sym; |
|
4
|
|
|
|
|
10
|
|
63
|
4
|
|
|
|
|
9
|
(${$sym}) = @value; |
|
4
|
|
|
|
|
102
|
|
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
elsif( $ch eq '@' ){ |
66
|
4
|
|
|
|
|
17
|
*{$sym} = \@$sym; |
|
4
|
|
|
|
|
33
|
|
67
|
4
|
|
|
|
|
7
|
(@{$sym}) = @value; |
|
4
|
|
|
|
|
117
|
|
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
elsif( $ch eq '%' ){ |
70
|
4
|
|
|
|
|
18
|
*{$sym} = \%$sym; |
|
4
|
|
|
|
|
11
|
|
71
|
4
|
|
|
|
|
7
|
(%{$sym}) = @value; |
|
4
|
|
|
|
|
461
|
|
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
elsif( $ch eq '*' ){ |
74
|
1
|
|
|
|
|
4
|
*{$sym} = \*$sym; |
|
1
|
|
|
|
|
2
|
|
75
|
1
|
|
|
|
|
2
|
(*{$sym}) = shift @value; |
|
1
|
|
|
|
|
59
|
|
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
else { # $ch eq '&'; guaranteed by the regex above. |
78
|
1
|
|
|
|
|
2
|
*{$sym} = shift @value; |
|
1
|
|
|
|
|
29
|
|
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
# There is no else, because the regex above guarantees |
81
|
|
|
|
|
|
|
# that $ch has one of the values we tested. |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
} else { # Name didn't match the regex above |
84
|
2
|
|
|
|
|
9
|
require Carp; |
85
|
2
|
|
|
|
|
311
|
Carp::croak("'$var' is not a valid variable name"); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
}; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
1; |
91
|
|
|
|
|
|
|
__END__ |