line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package constant::more; |
2
|
1
|
|
|
1
|
|
71381
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
3
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
51
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION="v0.2.1"; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
#use feature qw; |
8
|
1
|
|
|
1
|
|
7
|
no warnings "experimental"; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
125
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our %seen; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub import { |
13
|
|
|
|
|
|
|
|
14
|
4
|
|
|
4
|
|
494
|
my $package =shift; |
15
|
4
|
100
|
|
|
|
20
|
return unless @_; |
16
|
|
|
|
|
|
|
#check if first item is a hash ref. |
17
|
3
|
|
|
|
|
5
|
my $flags; |
18
|
3
|
100
|
|
|
|
11
|
if(ref($_[0]) eq "HASH"){ |
|
|
50
|
|
|
|
|
|
19
|
2
|
|
|
|
|
3
|
$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
|
|
|
|
|
6
|
my $caller=caller; |
31
|
1
|
|
|
1
|
|
7
|
no strict "refs"; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
581
|
|
32
|
3
|
|
|
|
|
5
|
my %table; |
33
|
|
|
|
|
|
|
|
34
|
3
|
|
|
|
|
10
|
for my $name (keys %$flags){ |
35
|
5
|
|
|
|
|
10
|
my $entry; |
36
|
|
|
|
|
|
|
my $value; |
37
|
5
|
|
|
|
|
0
|
my @values; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
40
|
5
|
100
|
|
|
|
12
|
if(ref($flags->{$name}) eq "HASH"){ |
41
|
|
|
|
|
|
|
#Full declaration |
42
|
2
|
|
|
|
|
4
|
$entry=$flags->{$name}; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
else { |
45
|
|
|
|
|
|
|
#assumed a short cut, just name and value |
46
|
3
|
|
|
|
|
10
|
$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
|
|
11
|
$name, $_[1]; |
53
|
5
|
|
50
|
|
|
29
|
}; |
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
|
|
|
|
11
|
return unless @_>=2; |
63
|
|
|
|
|
|
|
|
64
|
5
|
|
|
|
|
9
|
my @results=&$sub; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
#set values in the table |
68
|
5
|
|
|
|
|
9
|
my $i=0; |
69
|
5
|
|
|
|
|
19
|
while($i<@results){ |
70
|
5
|
|
|
|
|
15
|
my $pair =[$results[$i++], $results[$i++]]; |
71
|
5
|
|
|
|
|
7
|
my $value=$pair->[1]; |
72
|
5
|
|
|
|
|
8
|
my $name=$pair->[0]; |
73
|
5
|
50
|
|
|
|
13
|
unless($name=~/::/){ |
74
|
5
|
|
|
|
|
13
|
$name=$caller."::".$name; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
#Only configure contant for addition if it doesn't exist |
77
|
|
|
|
|
|
|
#in target namespace |
78
|
5
|
|
|
|
|
34
|
$table{$name}=$value unless(*{$name}{CODE}) |
79
|
5
|
50
|
|
|
|
6
|
} |
80
|
|
|
|
|
|
|
|
81
|
5
|
|
|
|
|
10
|
$success=1; |
82
|
|
|
|
|
|
|
|
83
|
5
|
|
|
|
|
15
|
}; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
#Select a value |
87
|
5
|
|
|
|
|
14
|
$wrapper->("", $entry->{val}); #default |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
#CMD line argument override |
91
|
5
|
50
|
66
|
|
|
15
|
if($entry->{opt} and @ARGV){ |
92
|
0
|
|
|
|
|
0
|
require Getopt::Long; |
93
|
0
|
0
|
|
|
|
0
|
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
|
0
|
|
|
|
|
0
|
my $parser=Getopt::Long::Parser->new( |
103
|
|
|
|
|
|
|
config=>[ |
104
|
|
|
|
|
|
|
"pass_through" |
105
|
|
|
|
|
|
|
] |
106
|
|
|
|
|
|
|
); |
107
|
0
|
0
|
|
|
|
0
|
$parser->getoptions( $entry->{opt}, $wrapper) or die "Invalid options"; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
5
|
0
|
33
|
|
|
31
|
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
|
|
|
|
|
18
|
while(my($name,$val)=each %table){ |
123
|
5
|
|
|
0
|
|
1420
|
*{$name}=sub (){$val} |
|
0
|
|
|
|
|
|
|
124
|
5
|
|
|
|
|
27
|
} |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
1; |