| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package constant::our; |
|
2
|
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
86726
|
use warnings; |
|
|
4
|
|
|
|
|
9
|
|
|
|
4
|
|
|
|
|
151
|
|
|
4
|
4
|
|
|
4
|
|
21
|
use strict; |
|
|
4
|
|
|
|
|
9
|
|
|
|
4
|
|
|
|
|
216
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 NAME |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
constant::our - Perl pragma to declare constants like our vars |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 VERSION |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Version 0.07 |
|
13
|
|
|
|
|
|
|
=cut |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $VERSION = '0.07'; |
|
16
|
|
|
|
|
|
|
|
|
17
|
4
|
|
|
4
|
|
21
|
use constant; |
|
|
4
|
|
|
|
|
154
|
|
|
|
4
|
|
|
|
|
104
|
|
|
18
|
4
|
|
|
4
|
|
21
|
use Exporter; |
|
|
4
|
|
|
|
|
9
|
|
|
|
4
|
|
|
|
|
4224
|
|
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our @EXPORT_OK; |
|
21
|
|
|
|
|
|
|
our %values; |
|
22
|
|
|
|
|
|
|
our %package_use; # TODO tests |
|
23
|
|
|
|
|
|
|
our %package_set; |
|
24
|
|
|
|
|
|
|
our %package_set_implicitly; |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
my $reserved_text = "Reserved for " . __PACKAGE__; |
|
27
|
|
|
|
|
|
|
our %reserved_constant = ( |
|
28
|
|
|
|
|
|
|
import => $reserved_text, |
|
29
|
|
|
|
|
|
|
_constant_our_set => $reserved_text, |
|
30
|
|
|
|
|
|
|
_constant_our_check_reserved => $reserved_text, |
|
31
|
|
|
|
|
|
|
); |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
################################################################################ |
|
34
|
|
|
|
|
|
|
sub import |
|
35
|
|
|
|
|
|
|
{ |
|
36
|
14
|
|
|
14
|
|
6245
|
my ( $class, @args ) = @_; |
|
37
|
14
|
100
|
|
|
|
51
|
unless (@args) |
|
38
|
|
|
|
|
|
|
{ |
|
39
|
1
|
|
|
|
|
10
|
return; |
|
40
|
|
|
|
|
|
|
} |
|
41
|
13
|
|
|
|
|
40
|
my ($caller_package) = caller; |
|
42
|
13
|
|
|
|
|
22
|
my $set_hash; |
|
43
|
|
|
|
|
|
|
|
|
44
|
13
|
100
|
|
|
|
38
|
if ( ref $args[0] ) |
|
45
|
|
|
|
|
|
|
{ |
|
46
|
10
|
|
|
|
|
19
|
$set_hash = shift @args; |
|
47
|
10
|
50
|
33
|
|
|
81
|
unless ( ref $set_hash eq 'HASH' && @args == 0 ) |
|
48
|
|
|
|
|
|
|
{ |
|
49
|
0
|
|
|
|
|
0
|
die __PACKAGE__ . " must call with one hash ref"; |
|
50
|
|
|
|
|
|
|
} |
|
51
|
10
|
|
|
|
|
46
|
@_ = ( $class, keys %$set_hash ); |
|
52
|
10
|
|
|
|
|
18
|
push @{ $package_set{$caller_package} }, keys %$set_hash; |
|
|
10
|
|
|
|
|
35
|
|
|
53
|
|
|
|
|
|
|
} |
|
54
|
|
|
|
|
|
|
else |
|
55
|
|
|
|
|
|
|
{ |
|
56
|
3
|
|
|
|
|
5
|
push @{ $package_use{$caller_package} }, @args; |
|
|
3
|
|
|
|
|
22
|
|
|
57
|
3
|
|
|
|
|
7
|
foreach (@args) |
|
58
|
|
|
|
|
|
|
{ |
|
59
|
7
|
100
|
|
|
|
20
|
if ( !exists $values{$_} ) |
|
60
|
|
|
|
|
|
|
{ |
|
61
|
3
|
|
|
|
|
6
|
push @{ $package_set_implicitly{$caller_package} }, $_; |
|
|
3
|
|
|
|
|
10
|
|
|
62
|
3
|
100
|
|
|
|
14
|
if ( exists $ENV{"CONSTANT_OUR_$_"} ) |
|
63
|
|
|
|
|
|
|
{ |
|
64
|
2
|
|
|
|
|
11
|
$set_hash->{$_} = $ENV{"CONSTANT_OUR_$_"}; |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
else |
|
67
|
|
|
|
|
|
|
{ |
|
68
|
1
|
|
|
|
|
6
|
$set_hash->{$_} = undef; |
|
69
|
|
|
|
|
|
|
} |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
} |
|
72
|
|
|
|
|
|
|
} |
|
73
|
13
|
100
|
66
|
|
|
108
|
if ( $set_hash && %$set_hash ) |
|
74
|
|
|
|
|
|
|
{ |
|
75
|
12
|
|
|
|
|
172
|
__PACKAGE__->_constant_our_set($set_hash); |
|
76
|
|
|
|
|
|
|
} |
|
77
|
11
|
|
|
|
|
6001
|
goto &Exporter::import; |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
################################################################################ |
|
80
|
|
|
|
|
|
|
sub _constant_our_set |
|
81
|
|
|
|
|
|
|
{ |
|
82
|
12
|
|
|
12
|
|
24
|
my $class = shift; |
|
83
|
12
|
|
|
|
|
21
|
my %set; |
|
84
|
12
|
50
|
|
|
|
29
|
if ( ref $_[0] ) |
|
85
|
|
|
|
|
|
|
{ |
|
86
|
12
|
|
|
|
|
15
|
%set = %{ $_[0] }; |
|
|
12
|
|
|
|
|
196
|
|
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
else |
|
89
|
|
|
|
|
|
|
{ |
|
90
|
0
|
|
|
|
|
0
|
%set = @_; |
|
91
|
|
|
|
|
|
|
} |
|
92
|
|
|
|
|
|
|
|
|
93
|
12
|
|
|
|
|
41
|
_constant_our_check_reserved( keys %set ); |
|
94
|
11
|
|
|
|
|
26
|
foreach ( keys %set ) |
|
95
|
|
|
|
|
|
|
{ |
|
96
|
14
|
100
|
|
|
|
33
|
if ( exists $values{$_} ) |
|
97
|
|
|
|
|
|
|
{ |
|
98
|
2
|
|
|
|
|
13
|
my ( $package, $filename, $line ) = caller(1); |
|
99
|
2
|
|
|
|
|
9
|
my $error_place = "$package [$filename:$line]"; |
|
100
|
2
|
100
|
33
|
|
|
29
|
if ( defined $values{$_} && defined $set{$_} && $values{$_} eq $set{$_} ) |
|
|
|
50
|
66
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
101
|
|
|
|
|
|
|
{ |
|
102
|
1
|
|
|
|
|
3
|
delete $set{$_}; |
|
103
|
|
|
|
|
|
|
} |
|
104
|
|
|
|
|
|
|
elsif ( !defined $values{$_} && !defined $set{$_} ) |
|
105
|
|
|
|
|
|
|
{ |
|
106
|
0
|
|
|
|
|
0
|
delete $set{$_}; |
|
107
|
|
|
|
|
|
|
} |
|
108
|
|
|
|
|
|
|
else |
|
109
|
|
|
|
|
|
|
{ |
|
110
|
1
|
50
|
|
|
|
5
|
my $c1 = defined $values{$_} ? $values{$_} : "undef"; |
|
111
|
1
|
50
|
|
|
|
6
|
my $c2 = defined $set{$_} ? $set{$_} : "undef"; |
|
112
|
1
|
|
|
|
|
17
|
die "Declare a constant [$_] in 2 unmatched value: [$c1] and [$c2] at $error_place"; |
|
113
|
|
|
|
|
|
|
} |
|
114
|
1
|
|
|
|
|
16
|
warn "Declare a constant [$_] again at $error_place. It's very BAD practice"; |
|
115
|
|
|
|
|
|
|
} |
|
116
|
|
|
|
|
|
|
else |
|
117
|
|
|
|
|
|
|
{ |
|
118
|
12
|
|
|
|
|
28
|
$values{$_} = $set{$_}; |
|
119
|
12
|
|
|
|
|
35
|
push @EXPORT_OK, $_; |
|
120
|
|
|
|
|
|
|
} |
|
121
|
|
|
|
|
|
|
} |
|
122
|
|
|
|
|
|
|
|
|
123
|
10
|
100
|
|
|
|
36
|
if (%set) |
|
124
|
|
|
|
|
|
|
{ |
|
125
|
9
|
|
|
|
|
904
|
__PACKAGE__->constant::import( \%set ); |
|
126
|
|
|
|
|
|
|
} |
|
127
|
|
|
|
|
|
|
} |
|
128
|
|
|
|
|
|
|
################################################################################ |
|
129
|
|
|
|
|
|
|
sub _constant_our_check_reserved |
|
130
|
|
|
|
|
|
|
{ |
|
131
|
12
|
|
|
12
|
|
30
|
foreach (@_) |
|
132
|
|
|
|
|
|
|
{ |
|
133
|
15
|
100
|
|
|
|
62
|
if ( exists $reserved_constant{$_} ) |
|
134
|
|
|
|
|
|
|
{ |
|
135
|
1
|
|
|
|
|
10
|
die "You can't use reserved constant[$_]: $reserved_constant{$_}"; |
|
136
|
|
|
|
|
|
|
} |
|
137
|
|
|
|
|
|
|
} |
|
138
|
|
|
|
|
|
|
} |
|
139
|
|
|
|
|
|
|
################################################################################ |
|
140
|
|
|
|
|
|
|
1; # End of constant::our |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
__END__ |