line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# I basically took vars.pm, and turned it into vars/i.pm
|
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Acme::CXW::vars::i;
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '1.03'; # TRIAL
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# yuck
|
8
|
|
|
|
|
|
|
=for IT DOESN'T WORK nor is it important (try perl -Mstrict -Mwarnings=all -We"use vars q[$a];")
|
9
|
|
|
|
|
|
|
BEGIN {
|
10
|
|
|
|
|
|
|
eval q{
|
11
|
|
|
|
|
|
|
use warnings::register;
|
12
|
|
|
|
|
|
|
};
|
13
|
|
|
|
|
|
|
eval q{
|
14
|
|
|
|
|
|
|
sub warnings::enabled { return $^W; }
|
15
|
|
|
|
|
|
|
} if $@;
|
16
|
|
|
|
|
|
|
}
|
17
|
|
|
|
|
|
|
=cut
|
18
|
|
|
|
|
|
|
|
19
|
3
|
|
|
3
|
|
201893
|
use strict qw(vars subs);
|
|
3
|
|
|
|
|
27
|
|
|
3
|
|
|
|
|
2091
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub import {
|
22
|
23
|
100
|
|
23
|
|
13008
|
return if @_ < 2;
|
23
|
20
|
|
|
|
|
61
|
my( $pack, $var, @value ) = @_;
|
24
|
20
|
|
|
|
|
47
|
my $callpack = caller;
|
25
|
|
|
|
|
|
|
|
26
|
20
|
|
|
|
|
31
|
my %stuff;
|
27
|
|
|
|
|
|
|
|
28
|
20
|
100
|
|
|
|
51
|
if( not @value ){
|
29
|
4
|
100
|
|
|
|
14
|
if( ref $var ){
|
30
|
3
|
|
|
|
|
11
|
%stuff = @$var;
|
31
|
|
|
|
|
|
|
} else {
|
32
|
1
|
|
|
|
|
35
|
return; # No value given --- no-op; not an error.
|
33
|
|
|
|
|
|
|
}
|
34
|
|
|
|
|
|
|
} else {
|
35
|
16
|
|
|
|
|
50
|
%stuff = ( $var, [@value] );
|
36
|
|
|
|
|
|
|
}
|
37
|
|
|
|
|
|
|
|
38
|
19
|
|
|
|
|
61
|
for my $k( keys %stuff ){
|
39
|
20
|
|
|
|
|
37
|
$var = $k;
|
40
|
20
|
100
|
|
|
|
58
|
if( ref $stuff{$k} eq 'ARRAY' ){
|
|
|
100
|
|
|
|
|
|
41
|
17
|
|
|
|
|
26
|
@value = @{ $stuff{$k} };
|
|
17
|
|
|
|
|
39
|
|
42
|
|
|
|
|
|
|
}
|
43
|
|
|
|
|
|
|
elsif( ref $stuff{$k} eq 'HASH' ){
|
44
|
1
|
|
|
|
|
2
|
@value = %{ $stuff{$k} };
|
|
1
|
|
|
|
|
5
|
|
45
|
|
|
|
|
|
|
}
|
46
|
|
|
|
|
|
|
else {
|
47
|
2
|
|
|
|
|
5
|
@value = $stuff{$k};
|
48
|
|
|
|
|
|
|
}
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
51
|
20
|
100
|
|
|
|
122
|
if( my( $ch, $sym ) = $var =~ /^([\$\@\%\*\&])(.+)$/ ){
|
52
|
18
|
100
|
100
|
|
|
141
|
if( $sym !~ /^(\w+(::|'))+\w+$/ && $sym =~ /\W|(^\d+$)/ ){
|
53
|
|
|
|
|
|
|
# ^^ Skip fully-qualified names ^^ Check special names
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# A variable name we can't or won't handle
|
56
|
8
|
|
|
|
|
37
|
require Carp;
|
57
|
|
|
|
|
|
|
|
58
|
8
|
100
|
|
|
|
34
|
if( $sym =~ /^\w+[[{].*[]}]$/ ){
|
|
|
100
|
|
|
|
|
|
59
|
2
|
|
|
|
|
233
|
Carp::croak("Can't declare individual elements of hash or array");
|
60
|
|
|
|
|
|
|
}
|
61
|
|
|
|
|
|
|
elsif( $sym =~ /^(\d+|\W|\^[\[\]A-Z\^_\?]|\{\^[a-zA-Z0-9]+\})$/ ){
|
62
|
5
|
|
|
|
|
500
|
Carp::croak("Refusing to initialize special variable $ch$sym");
|
63
|
|
|
|
|
|
|
}
|
64
|
|
|
|
|
|
|
else {
|
65
|
1
|
|
|
|
|
112
|
Carp::croak("I can't recognize $ch$sym as a variable name");
|
66
|
|
|
|
|
|
|
}
|
67
|
|
|
|
|
|
|
}
|
68
|
|
|
|
|
|
|
|
69
|
10
|
100
|
|
|
|
50
|
$sym = "${callpack}::$sym" unless $sym =~ /::/;
|
70
|
|
|
|
|
|
|
|
71
|
10
|
100
|
|
|
|
33
|
if( $ch eq '$' ){
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
72
|
4
|
|
|
|
|
18
|
*{$sym} = \$$sym;
|
|
4
|
|
|
|
|
21
|
|
73
|
4
|
|
|
|
|
10
|
(${$sym}) = @value;
|
|
4
|
|
|
|
|
270
|
|
74
|
|
|
|
|
|
|
}
|
75
|
|
|
|
|
|
|
elsif( $ch eq '@' ){
|
76
|
2
|
|
|
|
|
9
|
*{$sym} = \@$sym;
|
|
2
|
|
|
|
|
7
|
|
77
|
2
|
|
|
|
|
4
|
(@{$sym}) = @value;
|
|
2
|
|
|
|
|
63
|
|
78
|
|
|
|
|
|
|
}
|
79
|
|
|
|
|
|
|
elsif( $ch eq '%' ){
|
80
|
2
|
|
|
|
|
10
|
*{$sym} = \%$sym;
|
|
2
|
|
|
|
|
7
|
|
81
|
2
|
|
|
|
|
5
|
(%{$sym}) = @value;
|
|
2
|
|
|
|
|
104
|
|
82
|
|
|
|
|
|
|
}
|
83
|
|
|
|
|
|
|
elsif( $ch eq '*' ){
|
84
|
1
|
|
|
|
|
3
|
*{$sym} = \*$sym;
|
|
1
|
|
|
|
|
4
|
|
85
|
1
|
|
|
|
|
3
|
(*{$sym}) = shift @value;
|
|
1
|
|
|
|
|
77
|
|
86
|
|
|
|
|
|
|
}
|
87
|
|
|
|
|
|
|
else { # $ch eq '&'; guaranteed by the regex above.
|
88
|
1
|
|
|
|
|
2
|
*{$sym} = shift @value;
|
|
1
|
|
|
|
|
30
|
|
89
|
|
|
|
|
|
|
}
|
90
|
|
|
|
|
|
|
# There is no else, because the regex above guarantees
|
91
|
|
|
|
|
|
|
# that $ch has one of the values we tested.
|
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
} else { # Name didn't match the regex above
|
94
|
2
|
|
|
|
|
9
|
require Carp;
|
95
|
2
|
|
|
|
|
317
|
Carp::croak("'$var' is not a valid variable name");
|
96
|
|
|
|
|
|
|
}
|
97
|
|
|
|
|
|
|
}
|
98
|
|
|
|
|
|
|
};
|
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
1;
|
101
|
|
|
|
|
|
|
__END__
|