aboutsummaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/perl/perl/fixes/getopt-long-3.diff
blob: 8d14362e8801235fb2e436d611874ac8adf871cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
From f2a5c8b66c83fe4719dee9c50edeb2d6f8925c19 Mon Sep 17 00:00:00 2001
From: Andrew Gregory <andrew.gregory.8@gmail.com>
Date: Sun, 21 May 2017 21:12:21 -0400
Subject: [PATCH] provide a default value for optional arguments

When using gnu_compat, FindOption would return undef as the value for
the options with optional arguments if none was provided.  Subsequent
processing in GetOptionsFromArray is skipped entirely for undef values,
causing the option to be silently discarded.  The following code snippet
demonstrates the issue:

 use Getopt::Long qw(GetOptionsFromArray :config gnu_compat);
 GetOptionsFromArray( ['--foo'], 'foo:s' => sub { print("success") } );

Origin: backport, https://github.com/sciurius/perl-Getopt-Long/commit/2d16f355e25537aa742eb2833a7d52a63051429b
Patch-Name: fixes/getopt-long-3.diff

---
 cpan/Getopt-Long/lib/Getopt/Long.pm | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/cpan/Getopt-Long/lib/Getopt/Long.pm b/cpan/Getopt-Long/lib/Getopt/Long.pm
index 9d38673..e7e033b 100644
--- a/cpan/Getopt-Long/lib/Getopt/Long.pm
+++ b/cpan/Getopt-Long/lib/Getopt/Long.pm
@@ -1120,8 +1120,13 @@ sub FindOption ($$$$$) {
 	    # We do, since not doing so breaks existing scripts.
 	    $optargtype = 3;
 	}
-	return (1, $opt, $ctl, $ctl->[CTL_DEFAULT])
-	  if (($optargtype == 0) && !$mand);
+	if(($optargtype == 0) && !$mand) {
+	    my $val
+	      = defined($ctl->[CTL_DEFAULT]) ? $ctl->[CTL_DEFAULT]
+	      : $type eq 's'                 ? ''
+	      :                                0;
+	    return (1, $opt, $ctl, $val);
+	}
 	return (1, $opt, $ctl, $type eq 's' ? '' : 0)
 	  if $optargtype == 1;  # --foo=  -> return nothing
     }