line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: Short.pm,v 1.6 2007/07/13 00:00:14 ask Exp $ |
2
|
|
|
|
|
|
|
# $Source: /opt/CVS/Getopt-LL/lib/Getopt/LL/Short.pm,v $ |
3
|
|
|
|
|
|
|
# $Author: ask $ |
4
|
|
|
|
|
|
|
# $HeadURL$ |
5
|
|
|
|
|
|
|
# $Revision: 1.6 $ |
6
|
|
|
|
|
|
|
# $Date: 2007/07/13 00:00:14 $ |
7
|
|
|
|
|
|
|
package Getopt::LL::Short; |
8
|
4
|
|
|
4
|
|
26457
|
use strict; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
118
|
|
9
|
4
|
|
|
4
|
|
19
|
use warnings; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
103
|
|
10
|
4
|
|
|
4
|
|
23
|
use base 'Getopt::LL'; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
2183
|
|
11
|
4
|
|
|
4
|
|
30
|
use version; our $VERSION = qv('1.0.0'); |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
20
|
|
12
|
4
|
|
|
4
|
|
380
|
use 5.006_001; |
|
4
|
|
|
|
|
15
|
|
|
4
|
|
|
|
|
176
|
|
13
|
|
|
|
|
|
|
{ |
14
|
|
|
|
|
|
|
|
15
|
4
|
|
|
4
|
|
21
|
use Getopt::LL::SimpleExporter qw(getoptions); |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
20
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my %RULE_ABBREVATION = ( |
18
|
|
|
|
|
|
|
's' => 'string', |
19
|
|
|
|
|
|
|
'd' => 'digit', |
20
|
|
|
|
|
|
|
'f' => 'flag', |
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub parse_short_rule { |
24
|
16
|
|
|
16
|
1
|
20
|
my ($rule) = @_; |
25
|
|
|
|
|
|
|
|
26
|
16
|
100
|
|
|
|
43
|
if (index ($rule, q{=}) != -1) { |
27
|
9
|
|
|
|
|
28
|
my ($arg_name, $rule_type) = split m/=/xms, $rule, 2; |
28
|
9
|
|
|
|
|
28
|
return ($arg_name, $RULE_ABBREVATION{$rule_type}); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# Default rule is flag. |
32
|
7
|
|
|
|
|
15
|
return ($rule, 'flag'); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub getoptions { |
36
|
5
|
|
|
5
|
1
|
4673
|
my ($rules_ref, $options_ref, $argv_ref) = @_; |
37
|
5
|
|
100
|
|
|
27
|
$rules_ref ||= [ ]; |
38
|
|
|
|
|
|
|
|
39
|
5
|
|
|
|
|
10
|
my %converted_rules; |
40
|
5
|
|
|
|
|
6
|
for my $rule (@{$rules_ref}) { |
|
5
|
|
|
|
|
15
|
|
41
|
16
|
|
|
|
|
34
|
my ($arg_name, $rule_ref) = parse_short_rule($rule); |
42
|
16
|
|
|
|
|
45
|
$converted_rules{$arg_name} = $rule_ref; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
5
|
|
|
|
|
26
|
return Getopt::LL::getoptions( |
46
|
|
|
|
|
|
|
\%converted_rules, $options_ref, $argv_ref |
47
|
|
|
|
|
|
|
); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
1; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
__END__ |