| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package vars::i; |
|
2
|
5
|
|
|
5
|
|
365251
|
use 5.006001; |
|
|
5
|
|
|
|
|
53
|
|
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
our $VERSION = '1.900000'; # Prerelease leading to v2.0.0 |
|
5
|
|
|
|
|
|
|
|
|
6
|
5
|
|
|
5
|
|
31
|
use strict qw(vars subs); |
|
|
5
|
|
|
|
|
7
|
|
|
|
5
|
|
|
|
|
128
|
|
|
7
|
5
|
|
|
5
|
|
23
|
use warnings; |
|
|
5
|
|
|
|
|
7
|
|
|
|
5
|
|
|
|
|
4130
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# Turn a scalar, arrayref, or hashref into a list |
|
10
|
|
|
|
|
|
|
sub _unpack { |
|
11
|
10
|
100
|
|
10
|
|
35
|
if( ref $_[0] eq 'ARRAY' ){ |
|
|
|
100
|
|
|
|
|
|
|
12
|
6
|
|
|
|
|
6
|
return @{$_[0]}; |
|
|
6
|
|
|
|
|
16
|
|
|
13
|
|
|
|
|
|
|
} |
|
14
|
|
|
|
|
|
|
elsif( ref $_[0] eq 'HASH' ){ |
|
15
|
3
|
|
|
|
|
5
|
return %{$_[0]}; |
|
|
3
|
|
|
|
|
12
|
|
|
16
|
|
|
|
|
|
|
} |
|
17
|
|
|
|
|
|
|
else { |
|
18
|
1
|
|
|
|
|
5
|
return ($_[0]); |
|
19
|
|
|
|
|
|
|
} |
|
20
|
|
|
|
|
|
|
} #_unpack |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub import { |
|
23
|
40
|
100
|
|
40
|
|
44270
|
return if @_ < 2; |
|
24
|
35
|
|
|
|
|
108
|
my( $pack, $first_var, @value ) = @_; |
|
25
|
35
|
|
|
|
|
71
|
my $callpack = caller; |
|
26
|
|
|
|
|
|
|
|
|
27
|
35
|
|
|
|
|
53
|
my %definitions; |
|
28
|
|
|
|
|
|
|
|
|
29
|
35
|
100
|
|
|
|
116
|
if( not @value ){ |
|
|
|
100
|
|
|
|
|
|
|
30
|
9
|
100
|
|
|
|
44
|
if( ref $first_var eq 'ARRAY' ){ # E.g., use vars [ foo=>, bar=>... ]; |
|
|
|
100
|
|
|
|
|
|
|
31
|
6
|
|
|
|
|
23
|
%definitions = @$first_var; |
|
32
|
|
|
|
|
|
|
} |
|
33
|
|
|
|
|
|
|
elsif( ref $first_var eq 'HASH' ){ # E.g., use vars { foo=>, bar=>... }; |
|
34
|
2
|
|
|
|
|
9
|
%definitions = %$first_var; |
|
35
|
|
|
|
|
|
|
} |
|
36
|
|
|
|
|
|
|
else { |
|
37
|
1
|
|
|
|
|
41
|
return; # No value given --- no-op; not an error. |
|
38
|
|
|
|
|
|
|
} |
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
elsif(@value == 1) { # E.g., use vars foo => |
|
41
|
24
|
|
|
|
|
66
|
%definitions = ( $first_var => $value[0] ); |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
else { |
|
44
|
2
|
|
|
|
|
7
|
%definitions = ( $first_var => [@value] ); |
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
#require Data::Dumper; # For debugging |
|
48
|
|
|
|
|
|
|
#print Data::Dumper->Dump([\%definitions], ['definitions']); |
|
49
|
|
|
|
|
|
|
|
|
50
|
34
|
|
|
|
|
139
|
while( my ($var, $val) = each %definitions ){ |
|
51
|
|
|
|
|
|
|
|
|
52
|
40
|
100
|
|
|
|
239
|
if( my( $ch, $sym ) = $var =~ /^([-\$\@\%\*\&])(.+)$/ ){ |
|
53
|
38
|
100
|
100
|
|
|
305
|
if( $ch eq '-' ){ # An option |
|
|
|
100
|
|
|
|
|
|
|
54
|
2
|
|
|
|
|
11
|
require Carp; |
|
55
|
2
|
|
|
|
|
342
|
Carp::croak('vars::i does not yet support any options!'); |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
elsif( $sym !~ /^(\w+(::|'))+\w+$/ && $sym =~ /\W|(^\d+$)/ ){ |
|
58
|
|
|
|
|
|
|
# ^^ Skip fully-qualified names ^^ Check special names |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# A variable name we can't or won't handle |
|
61
|
9
|
|
|
|
|
45
|
require Carp; |
|
62
|
|
|
|
|
|
|
|
|
63
|
9
|
100
|
|
|
|
46
|
if( $sym =~ /^\w+[[{].*[]}]$/ ){ |
|
|
|
100
|
|
|
|
|
|
|
64
|
2
|
|
|
|
|
248
|
Carp::croak("Can't declare individual elements of hash or array"); |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
elsif( $sym =~ /^(\d+|\W|\^[\[\]A-Z\^_\?]|\{\^[a-zA-Z0-9]+\})$/ ){ |
|
67
|
5
|
|
|
|
|
584
|
Carp::croak("Refusing to initialize special variable $ch$sym"); |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
else { |
|
70
|
2
|
|
|
|
|
261
|
Carp::croak("I can't recognize $ch$sym as a variable name"); |
|
71
|
|
|
|
|
|
|
} |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
27
|
100
|
|
|
|
125
|
$sym = "${callpack}::$sym" unless $sym =~ /::/; |
|
75
|
|
|
|
|
|
|
|
|
76
|
27
|
100
|
|
|
|
90
|
if( $ch eq '$' ){ |
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
77
|
13
|
|
|
|
|
71
|
*{$sym} = \$$sym; |
|
|
13
|
|
|
|
|
37
|
|
|
78
|
13
|
|
|
|
|
24
|
${$sym} = $val; |
|
|
13
|
|
|
|
|
262
|
|
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
elsif( $ch eq '@' ){ |
|
81
|
6
|
|
|
|
|
41
|
*{$sym} = \@$sym; |
|
|
6
|
|
|
|
|
20
|
|
|
82
|
6
|
|
|
|
|
18
|
@{$sym} = _unpack $val; |
|
|
6
|
|
|
|
|
572
|
|
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
elsif( $ch eq '%' ){ |
|
85
|
4
|
|
|
|
|
25
|
*{$sym} = \%$sym; |
|
|
4
|
|
|
|
|
60
|
|
|
86
|
4
|
|
|
|
|
19
|
%{$sym} = _unpack $val; |
|
|
4
|
|
|
|
|
122
|
|
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
elsif( $ch eq '*' ){ |
|
89
|
1
|
|
|
|
|
4
|
*{$sym} = \*$sym; |
|
|
1
|
|
|
|
|
3
|
|
|
90
|
1
|
|
|
|
|
2
|
(*{$sym}) = $val; |
|
|
1
|
|
|
|
|
58
|
|
|
91
|
|
|
|
|
|
|
} |
|
92
|
|
|
|
|
|
|
else { # $ch eq '&'; guaranteed by the regex above. |
|
93
|
3
|
|
|
|
|
18
|
my ($param) = $val; |
|
94
|
3
|
100
|
|
|
|
10
|
if(ref $param) { |
|
95
|
|
|
|
|
|
|
# NOTE: for now, permit any ref, since we can't determine |
|
96
|
|
|
|
|
|
|
# refs overload &{}. If necessary, we can later use |
|
97
|
|
|
|
|
|
|
# Scalar::Util 1.25+'s blessed(), and allow CODE refs |
|
98
|
|
|
|
|
|
|
# or blessed refs. |
|
99
|
1
|
|
|
|
|
1
|
*{$sym} = $param; |
|
|
1
|
|
|
|
|
30
|
|
|
100
|
|
|
|
|
|
|
} |
|
101
|
|
|
|
|
|
|
else { |
|
102
|
2
|
|
|
|
|
10
|
require Carp; |
|
103
|
2
|
100
|
|
|
|
256
|
Carp::croak("Can't assign non-reference " . |
|
104
|
|
|
|
|
|
|
(defined($param) ? $param : '') . |
|
105
|
|
|
|
|
|
|
" to $sym"); |
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
} |
|
108
|
|
|
|
|
|
|
# There is no else, because the regex above guarantees |
|
109
|
|
|
|
|
|
|
# that $ch has one of the values we tested. |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
} |
|
112
|
|
|
|
|
|
|
else { # Name didn't match the regex above |
|
113
|
2
|
|
|
|
|
11
|
require Carp; |
|
114
|
2
|
|
|
|
|
370
|
Carp::croak("'$var' is not a valid variable or option name"); |
|
115
|
|
|
|
|
|
|
} |
|
116
|
|
|
|
|
|
|
} |
|
117
|
|
|
|
|
|
|
} #import() |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
1; |
|
120
|
|
|
|
|
|
|
__END__ |