| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package constant::more; |
|
2
|
1
|
|
|
1
|
|
70768
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
29
|
|
|
3
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
54
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION="v0.3.0"; |
|
6
|
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
7
|
no warnings "experimental"; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
229
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our %seen; |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub import { |
|
12
|
|
|
|
|
|
|
|
|
13
|
7
|
|
|
7
|
|
607
|
my $package =shift; |
|
14
|
7
|
100
|
|
|
|
25
|
return unless @_; |
|
15
|
|
|
|
|
|
|
|
|
16
|
6
|
|
|
|
|
11
|
my $flags; |
|
17
|
6
|
100
|
|
|
|
14
|
if(ref($_[0]) eq "HASH"){ |
|
18
|
|
|
|
|
|
|
# Hash ref of keys and values |
|
19
|
2
|
|
|
|
|
4
|
$flags=shift; |
|
20
|
|
|
|
|
|
|
} |
|
21
|
|
|
|
|
|
|
else{ |
|
22
|
|
|
|
|
|
|
# Flat list |
|
23
|
4
|
100
|
|
|
|
13
|
if($_[0] =~/=/){ |
|
24
|
|
|
|
|
|
|
# Enumerations. |
|
25
|
2
|
|
|
|
|
4
|
my $c=0; |
|
26
|
2
|
|
|
|
|
3
|
my @out; |
|
27
|
|
|
|
|
|
|
|
|
28
|
2
|
|
|
|
|
4
|
for(@_){ |
|
29
|
5
|
|
|
|
|
12
|
my @f=split /=/; |
|
30
|
5
|
100
|
|
|
|
12
|
if(@f == 2){ |
|
31
|
|
|
|
|
|
|
#update c to desired value |
|
32
|
3
|
|
|
|
|
4
|
$c=$f[1]; |
|
33
|
|
|
|
|
|
|
} |
|
34
|
5
|
|
|
|
|
15
|
push @out, $f[0], $c++; |
|
35
|
|
|
|
|
|
|
} |
|
36
|
2
|
|
|
|
|
18
|
$flags={@out}; |
|
37
|
|
|
|
|
|
|
} |
|
38
|
|
|
|
|
|
|
else { |
|
39
|
|
|
|
|
|
|
# Normal |
|
40
|
2
|
50
|
|
|
|
9
|
die "constant::more note enough items" if @_ % 2; |
|
41
|
2
|
|
|
|
|
6
|
$flags={@_}; |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
} |
|
44
|
|
|
|
|
|
|
|
|
45
|
6
|
|
|
|
|
12
|
my $caller=caller; |
|
46
|
1
|
|
|
1
|
|
9
|
no strict "refs"; |
|
|
1
|
|
|
|
|
5
|
|
|
|
1
|
|
|
|
|
573
|
|
|
47
|
6
|
|
|
|
|
8
|
my %table; |
|
48
|
|
|
|
|
|
|
|
|
49
|
6
|
|
|
|
|
18
|
for my $name (keys %$flags){ |
|
50
|
12
|
|
|
|
|
25
|
my $entry; |
|
51
|
|
|
|
|
|
|
my $value; |
|
52
|
12
|
|
|
|
|
0
|
my @values; |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
|
55
|
12
|
100
|
|
|
|
30
|
if(ref($flags->{$name}) eq "HASH"){ |
|
56
|
|
|
|
|
|
|
#Full declaration |
|
57
|
2
|
|
|
|
|
4
|
$entry=$flags->{$name}; |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
else { |
|
60
|
|
|
|
|
|
|
#assumed a short cut, just name and value |
|
61
|
10
|
|
|
|
|
29
|
$entry={val=>$flags->{$name}, keep=>undef, opt=>undef, env=>undef}; |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
#Default sub is to return the key value pair |
|
65
|
|
|
|
|
|
|
my $sub=$entry->{sub}//= sub { |
|
66
|
|
|
|
|
|
|
#return name value pair |
|
67
|
12
|
|
|
12
|
|
40
|
$name, $_[1]; |
|
68
|
12
|
|
50
|
|
|
59
|
}; |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
#Set the entry by name |
|
71
|
12
|
|
|
|
|
24
|
$flags->{$name}=$entry; |
|
72
|
|
|
|
|
|
|
|
|
73
|
12
|
|
|
|
|
13
|
my $success; |
|
74
|
|
|
|
|
|
|
my $wrapper= sub { |
|
75
|
12
|
|
|
12
|
|
22
|
my ($opt_name, $opt_value)=@_; |
|
76
|
|
|
|
|
|
|
|
|
77
|
12
|
50
|
|
|
|
26
|
return unless @_>=2; |
|
78
|
|
|
|
|
|
|
|
|
79
|
12
|
|
|
|
|
20
|
my @results=&$sub; |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
#set values in the table |
|
83
|
12
|
|
|
|
|
17
|
my $i=0; |
|
84
|
12
|
|
|
|
|
22
|
while($i<@results){ |
|
85
|
12
|
|
|
|
|
27
|
my $pair =[$results[$i++], $results[$i++]]; |
|
86
|
12
|
|
|
|
|
20
|
my $value=$pair->[1]; |
|
87
|
12
|
|
|
|
|
14
|
my $name=$pair->[0]; |
|
88
|
12
|
50
|
|
|
|
32
|
unless($name=~/::/){ |
|
89
|
12
|
|
|
|
|
27
|
$name=$caller."::".$name; |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
#Only configure contant for addition if it doesn't exist |
|
92
|
|
|
|
|
|
|
#in target namespace |
|
93
|
12
|
|
|
|
|
95
|
$table{$name}=$value unless(*{$name}{CODE}) |
|
94
|
12
|
50
|
|
|
|
16
|
} |
|
95
|
|
|
|
|
|
|
|
|
96
|
12
|
|
|
|
|
25
|
$success=1; |
|
97
|
|
|
|
|
|
|
|
|
98
|
12
|
|
|
|
|
46
|
}; |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
#Select a value |
|
102
|
12
|
|
|
|
|
46
|
$wrapper->("", $entry->{val}); #default |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
#CMD line argument override |
|
106
|
|
|
|
|
|
|
|
|
107
|
12
|
50
|
66
|
|
|
31
|
if($entry->{opt} and @ARGV){ |
|
108
|
0
|
|
|
|
|
0
|
require Getopt::Long; |
|
109
|
0
|
0
|
|
|
|
0
|
if($entry->{keep}){ |
|
110
|
0
|
|
|
|
|
0
|
my $parser=Getopt::Long::Parser->new(); |
|
111
|
|
|
|
|
|
|
|
|
112
|
0
|
|
|
|
|
0
|
my @array=@ARGV; #copy |
|
113
|
0
|
0
|
|
|
|
0
|
$parser->getoptionsfromarray(\@array, $entry->{opt}, $wrapper) or die "Invalid options"; |
|
114
|
|
|
|
|
|
|
} |
|
115
|
|
|
|
|
|
|
else{ |
|
116
|
0
|
|
|
|
|
0
|
my $parser=Getopt::Long::Parser->new( |
|
117
|
|
|
|
|
|
|
config=>[ |
|
118
|
|
|
|
|
|
|
"pass_through" |
|
119
|
|
|
|
|
|
|
] |
|
120
|
|
|
|
|
|
|
); |
|
121
|
0
|
0
|
|
|
|
0
|
$parser->getoptions( $entry->{opt}, $wrapper) or die "Invalid options"; |
|
122
|
|
|
|
|
|
|
} |
|
123
|
|
|
|
|
|
|
} |
|
124
|
|
|
|
|
|
|
|
|
125
|
12
|
0
|
33
|
|
|
58
|
if(!$success and $entry->{env}){ |
|
126
|
|
|
|
|
|
|
#Env override |
|
127
|
0
|
0
|
|
|
|
0
|
if(defined $ENV{$entry->{env}}){ |
|
128
|
0
|
|
|
|
|
0
|
$wrapper->($ENV{$entry->{env}}); |
|
129
|
|
|
|
|
|
|
} |
|
130
|
|
|
|
|
|
|
} |
|
131
|
|
|
|
|
|
|
} |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
#Actually |
|
134
|
|
|
|
|
|
|
#Create the constants |
|
135
|
6
|
|
|
|
|
21
|
while(my($name,$val)=each %table){ |
|
136
|
12
|
|
|
0
|
|
1833
|
*{$name}=sub (){$val} |
|
|
0
|
|
|
|
|
|
|
|
137
|
12
|
|
|
|
|
55
|
} |
|
138
|
|
|
|
|
|
|
} |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
1; |