line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
require 5.003_96; # Time-stamp: "2004-12-29 19:27:33 AST" |
3
|
|
|
|
|
|
|
# same minimal version required as constant.pm |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Getopt::constant; |
6
|
|
|
|
|
|
|
$VERSION = '1.03'; |
7
|
2
|
|
|
2
|
|
17663
|
use strict; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
1672
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub import { |
10
|
1
|
|
|
1
|
|
8
|
shift(@_); # We don't care about our own package name |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
|
|
9
|
my(%h) = (@_); # Get default values from there. |
13
|
1
|
|
|
|
|
4
|
my $pkg = caller; |
14
|
1
|
|
50
|
|
|
9
|
my $pref = delete( $h{':prefix'} ) || ''; |
15
|
1
|
|
|
|
|
2
|
my $usage = delete( $h{':usage' } ); # a usage message to throw at people |
16
|
1
|
|
|
|
|
2
|
my $retain = delete( $h{':retain'} ); # if we should not change @ARGV |
17
|
1
|
|
|
|
|
2
|
my $permissive = delete( $h{':permissive'} ); |
18
|
|
|
|
|
|
|
# if we should just skip weird things |
19
|
1
|
|
|
|
|
2
|
my($x, @unknowns, @orig_ARGV); |
20
|
1
|
50
|
|
|
|
3
|
@orig_ARGV = @ARGV if $retain; |
21
|
|
|
|
|
|
|
|
22
|
1
|
|
|
|
|
6
|
while(@ARGV) { |
23
|
3
|
|
|
|
|
6
|
$x = $ARGV[0]; |
24
|
|
|
|
|
|
|
#print "Considering \"$x\"\n"; |
25
|
3
|
50
|
0
|
|
|
24
|
if($x eq '-') { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# Deceptively not part of the options list, so bail. |
27
|
0
|
|
|
|
|
0
|
last; |
28
|
|
|
|
|
|
|
} elsif($x eq '--') { |
29
|
|
|
|
|
|
|
# End of options list. |
30
|
1
|
|
|
|
|
2
|
shift @ARGV; |
31
|
1
|
|
|
|
|
3
|
last; |
32
|
|
|
|
|
|
|
} elsif($x =~ m<--?([^=]+)=([^=]*)>s ) { # like -foo=123 or --foo=123 |
33
|
1
|
50
|
50
|
|
|
9
|
if(!exists $h{$1}) { |
|
|
50
|
|
|
|
|
|
34
|
0
|
0
|
|
|
|
0
|
push @unknowns, $1 unless $permissive; |
35
|
|
|
|
|
|
|
} elsif(ref($h{$1} || '') eq 'ARRAY') { |
36
|
1
|
|
|
|
|
5
|
my($name) = $1; |
37
|
1
|
|
|
|
|
6
|
@{$h{$name}} = split(",", $2, -1); |
|
1
|
|
|
|
|
12
|
|
38
|
|
|
|
|
|
|
} else { |
39
|
0
|
|
|
|
|
0
|
$h{$1} = $2; |
40
|
|
|
|
|
|
|
} |
41
|
1
|
|
|
|
|
4
|
shift @ARGV; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
} elsif($x =~ m<--?([^=]+)>s ) { # like -foo or --foo |
44
|
1
|
50
|
50
|
|
|
12
|
if(!exists $h{$1}) { |
|
|
50
|
|
|
|
|
|
45
|
0
|
0
|
|
|
|
0
|
push @unknowns, $1 unless $permissive; |
46
|
|
|
|
|
|
|
} elsif(ref($h{$1} || '') eq 'ARRAY') { |
47
|
0
|
|
|
|
|
0
|
@{$h{$1}} = (1); # guh, I guess that's right. |
|
0
|
|
|
|
|
0
|
|
48
|
|
|
|
|
|
|
} else { |
49
|
1
|
|
|
|
|
2
|
$h{$1} = 1; |
50
|
|
|
|
|
|
|
} |
51
|
1
|
|
|
|
|
3
|
shift @ARGV; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
} elsif(length $x and substr($x,0,1) eq '-') { |
54
|
0
|
0
|
|
|
|
0
|
push @unknowns, "\"$x\"" unless $permissive; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
} else { |
57
|
0
|
|
|
|
|
0
|
last; # First non-option in @ARGV |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
1
|
50
|
|
|
|
4
|
@ARGV = @orig_ARGV if $retain; |
62
|
|
|
|
|
|
|
|
63
|
1
|
50
|
|
|
|
5
|
if(@unknowns) { |
64
|
0
|
0
|
0
|
|
|
0
|
if(ref($usage || '') eq 'CODE') { |
65
|
0
|
|
|
|
|
0
|
$usage->(\@unknowns, [sort grep !m/^:/s, keys %h], \%h); |
66
|
|
|
|
|
|
|
} else { |
67
|
0
|
0
|
|
|
|
0
|
printf STDERR "Unknown option%s: %s\n", |
68
|
|
|
|
|
|
|
(@unknowns == 1) ? '' : 's', join(' ', @unknowns); |
69
|
0
|
0
|
|
|
|
0
|
if(defined $usage) { |
70
|
0
|
|
|
|
|
0
|
print STDERR $usage |
71
|
|
|
|
|
|
|
} else { |
72
|
0
|
|
|
|
|
0
|
my(@x) = sort grep !m/^:/s, keys %h; |
73
|
0
|
0
|
|
|
|
0
|
print STDERR |
74
|
|
|
|
|
|
|
(@x == 1) ? |
75
|
|
|
|
|
|
|
'(The only known option is: ' : '(The known options are: ', |
76
|
|
|
|
|
|
|
join(', ', @x), ")\n"; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
0
|
0
|
|
|
|
0
|
if($] <= 5.00599) { |
81
|
0
|
|
|
|
|
0
|
exit; |
82
|
|
|
|
|
|
|
# Because if we put a 1 there, those versions of Perl will emit |
83
|
|
|
|
|
|
|
# a nasty "Callback called exit" message. Ah well. |
84
|
|
|
|
|
|
|
} else { |
85
|
0
|
|
|
|
|
0
|
exit 1; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
1
|
|
|
|
|
186
|
while( my($name,$value) = each %h) { |
90
|
3
|
50
|
33
|
|
|
19
|
next unless length($name) and substr($name,0,1) ne ':'; |
91
|
2
|
|
|
2
|
|
13
|
no strict 'refs'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
353
|
|
92
|
3
|
100
|
50
|
|
|
12
|
if(ref($value || '') eq 'ARRAY') { |
93
|
|
|
|
|
|
|
#print "Setting ${pkg}::$pref$name to the list (@$value)\n"; |
94
|
1
|
|
|
1
|
|
3
|
*{"${pkg}::$pref$name"} = sub () { @$value }; |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
116
|
|
95
|
|
|
|
|
|
|
} else { |
96
|
|
|
|
|
|
|
#print "Setting ${pkg}::$pref$name to $value\n"; |
97
|
2
|
|
|
0
|
|
17
|
*{"${pkg}::$pref$name"} = sub () { $value }; |
|
2
|
|
|
|
|
18
|
|
|
0
|
|
|
|
|
0
|
|
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
1
|
|
|
|
|
2124
|
return; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
# Yup, that's it. |
104
|
|
|
|
|
|
|
########################################################################### |
105
|
|
|
|
|
|
|
1; |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
__END__ |