File: | Dpkg/Getopt.pm |
Coverage: | 97.5% |
line | stmt | bran | cond | sub | pod | time | code |
---|---|---|---|---|---|---|---|
1 | # Copyright © 2014 Guillem Jover <guillem@debian.org> | ||||||
2 | # | ||||||
3 | # This program is free software; you can redistribute it and/or modify | ||||||
4 | # it under the terms of the GNU General Public License as published by | ||||||
5 | # the Free Software Foundation; either version 2 of the License, or | ||||||
6 | # (at your option) any later version. | ||||||
7 | # | ||||||
8 | # This program is distributed in the hope that it will be useful, | ||||||
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||||
11 | # GNU General Public License for more details. | ||||||
12 | # | ||||||
13 | # You should have received a copy of the GNU General Public License | ||||||
14 | # along with this program. If not, see <https://www.gnu.org/licenses/>. | ||||||
15 | |||||||
16 | =encoding utf8 | ||||||
17 | |||||||
18 - 29 | =head1 NAME Dpkg::Getopt - option parsing handling =head1 DESCRIPTION This module provides helper functions for option parsing, and complements the system Getopt::Long module. B<Note>: This is a private module, its API can change at any time. =cut | ||||||
30 | |||||||
31 | package Dpkg::Getopt 0.02; | ||||||
32 | |||||||
33 | 6 6 6 | 17 5 103 | use strict; | ||||
34 | 6 6 6 | 10 3 260 | use warnings; | ||||
35 | |||||||
36 | our @EXPORT = qw( | ||||||
37 | normalize_options | ||||||
38 | ); | ||||||
39 | |||||||
40 | 6 6 6 | 15 3 943 | use Exporter qw(import); | ||||
41 | |||||||
42 | sub normalize_options | ||||||
43 | { | ||||||
44 | 12 | 0 | 28 | my (%opts) = @_; | |||
45 | 12 | 13 | my $norm = 1; | ||||
46 | 12 | 9 | my @args; | ||||
47 | |||||||
48 | @args = map { | ||||||
49 | 45 | 195 | if ($norm and m/^(-[A-Za-z])(.+)$/) { | ||||
50 | 9 | 15 | ($1, $2) | ||||
51 | } elsif ($norm and m/^(--[A-Za-z-]+)=(.*)$/) { | ||||||
52 | 6 | 16 | ($1, $2) | ||||
53 | } else { | ||||||
54 | 30 | 73 | $norm = 0 if defined $opts{delim} and $_ eq $opts{delim}; | ||||
55 | 30 | 39 | $_; | ||||
56 | } | ||||||
57 | 12 12 | 11 17 | } @{$opts{args}}; | ||||
58 | |||||||
59 | 12 | 39 | return @args; | ||||
60 | } | ||||||
61 | |||||||
62 - 68 | =head1 CHANGES =head2 Version 0.xx This is a private module. =cut | ||||||
69 | |||||||
70 | 1; |