line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package variable; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
require 5.006; |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
553
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
6
|
1
|
|
|
1
|
|
5
|
use warnings::register; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
183
|
|
7
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
31
|
|
8
|
1
|
|
|
1
|
|
4
|
no warnings 'syntax'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
1366
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '2009110702'; |
12
|
|
|
|
|
|
|
our %declared; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub croak { |
15
|
0
|
|
|
0
|
0
|
0
|
require Carp; |
16
|
0
|
|
|
|
|
0
|
goto &Carp::croak (@_); |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my %keywords = map {$_ => 1} qw /BEGIN INIT CHECK END DESTROY AUTOLOAD/; |
20
|
|
|
|
|
|
|
my %forced_into_main = map {$_ => 1} qw /STDIN STDOUT STDERR ARGV ARGVOUT |
21
|
|
|
|
|
|
|
ENV INC SIG/; |
22
|
|
|
|
|
|
|
my %forbidden = (%keywords, %forced_into_main); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub import { |
25
|
4
|
|
|
4
|
|
19
|
my $package = shift; |
26
|
4
|
100
|
|
|
|
44
|
return unless @_; # Ignore 'use variable;'. |
27
|
3
|
|
|
|
|
5
|
my $caller = caller; |
28
|
3
|
|
|
|
|
4
|
my $name = shift; |
29
|
|
|
|
|
|
|
|
30
|
3
|
50
|
|
|
|
4
|
croak "Can't use undef as variable name" unless defined $name; |
31
|
|
|
|
|
|
|
|
32
|
3
|
50
|
33
|
|
|
46
|
if ($name =~ /^_?[^\W_\d]\w*\z/ && !$forbidden {$name}) { |
|
|
0
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# Ok. |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
elsif ($forced_into_main {$name} and $caller ne 'main') { |
36
|
0
|
|
|
|
|
0
|
croak "Variable name '$name' is forced into main::"; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
elsif ($name =~ /^__/) { |
39
|
0
|
|
|
|
|
0
|
croak "Variable name '$name' begins with '__'"; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
elsif ($name =~ /^[A-Za-z_]\w*\z/) { |
42
|
|
|
|
|
|
|
# Perhaps give a warning. |
43
|
0
|
0
|
|
|
|
0
|
if (warnings::enabled ()) { |
44
|
0
|
0
|
|
|
|
0
|
if ($keywords {$name}) { |
|
|
0
|
|
|
|
|
|
45
|
0
|
|
|
|
|
0
|
warnings::warn ("Variable name '$name' is a Perl keyword"); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
elsif ($forced_into_main {$name}) { |
48
|
0
|
|
|
|
|
0
|
warnings::warn ("Variable name '$name' is forced into " . |
49
|
|
|
|
|
|
|
"package main::"); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
else { |
52
|
0
|
|
|
|
|
0
|
warnings::warn ("Variable name '$name' has unknown problems"); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
elsif ($name =~ /^[01]?\z/) { |
57
|
0
|
0
|
|
|
|
0
|
if (@_) { |
58
|
0
|
|
|
|
|
0
|
croak "Variable name '$name' is invalid"; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
else { |
61
|
0
|
|
|
|
|
0
|
croak "Variable name looks like a boolean value"; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
else { |
66
|
|
|
|
|
|
|
# Must have bad characters. |
67
|
0
|
|
|
|
|
0
|
croak "Variable name '$name' has invalid characters"; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
3
|
50
|
|
|
|
5
|
if (@_ > 1) { |
71
|
0
|
|
|
|
|
0
|
croak "Variables have to be scalar"; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
{ |
75
|
1
|
|
|
1
|
|
5
|
no strict 'refs'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
122
|
|
|
3
|
|
|
|
|
4
|
|
76
|
3
|
|
|
|
|
4
|
my $value = shift; # Might be undef, which is ok. |
77
|
3
|
|
|
|
|
7
|
my $full = "${caller}::$name"; |
78
|
3
|
|
|
|
|
5
|
$declared {$full} ++; |
79
|
3
|
|
|
35
|
|
1772
|
*$full = sub () : lvalue {$value}; |
|
35
|
|
|
|
|
117
|
|
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
1; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
__END__ |