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