Update Scalar-List-Utils to CPAN version 1.31
authorChris 'BinGOs' Williams <chris@bingosnet.co.uk>
Thu, 15 Aug 2013 21:23:48 +0000 (22:23 +0100)
committerChris 'BinGOs' Williams <chris@bingosnet.co.uk>
Thu, 15 Aug 2013 21:23:48 +0000 (22:23 +0100)
  [DELTA]

1.31 -- Wed Aug 14 20:38 UTC 2013

  * Bugfix pairmap to return list length in scalar context
  * Added "Odd number of elements" warnings to all pair* functions

Porting/Maintainers.pl
cpan/List-Util/Changes
cpan/List-Util/ListUtil.xs
cpan/List-Util/lib/List/Util.pm
cpan/List-Util/lib/List/Util/XS.pm
cpan/List-Util/lib/Scalar/Util.pm
cpan/List-Util/t/pair.t

index 94a051f..7d4482c 100755 (executable)
@@ -1556,7 +1556,7 @@ use File::Glob qw(:case);
 
     'Scalar-List-Utils' => {
         'MAINTAINER'   => 'gbarr',
-        'DISTRIBUTION' => 'PEVANS/Scalar-List-Utils-1.30.tar.gz',
+        'DISTRIBUTION' => 'PEVANS/Scalar-List-Utils-1.31.tar.gz',
         'FILES'    => q[cpan/List-Util],
         'EXCLUDED' => [
             qr{^inc/Module/},
index 8de21e2..d7088a1 100644 (file)
@@ -1,4 +1,9 @@
-1.30 -- Mon Aug 05 13:09 UTC 2012
+1.31 -- Wed Aug 14 20:38 UTC 2013
+
+  * Bugfix pairmap to return list length in scalar context
+  * Added "Odd number of elements" warnings to all pair* functions
+
+1.30 -- Mon Aug 05 13:09 UTC 2013
 
   * Added pairfirst
   * Added MULTICALL implementations to pairmap/pairgrep/pairfirst
index 83cf82a..7448a8f 100644 (file)
@@ -353,6 +353,9 @@ PPCODE:
     I32 ret_gimme = GIMME_V;
     int argi = 1; // "shift" the block
 
+    if(!(items % 2) && ckWARN(WARN_MISC))
+       warn("Odd number of elements in pairfirst");
+
     agv = gv_fetchpv("a", GV_ADD, SVt_PV);
     bgv = gv_fetchpv("b", GV_ADD, SVt_PV);
     SAVESPTR(GvSV(agv));
@@ -433,6 +436,9 @@ PPCODE:
     int argi = 1; // "shift" the block
     int reti = 0;
 
+    if(!(items % 2) && ckWARN(WARN_MISC))
+       warn("Odd number of elements in pairgrep");
+
     agv = gv_fetchpv("a", GV_ADD, SVt_PV);
     bgv = gv_fetchpv("b", GV_ADD, SVt_PV);
     SAVESPTR(GvSV(agv));
@@ -516,6 +522,9 @@ PPCODE:
     int argi = 1; // "shift" the block
     int reti = 0;
 
+    if(!(items % 2) && ckWARN(WARN_MISC))
+       warn("Odd number of elements in pairmap");
+
     agv = gv_fetchpv("a", GV_ADD, SVt_PV);
     bgv = gv_fetchpv("b", GV_ADD, SVt_PV);
     SAVESPTR(GvSV(agv));
@@ -586,7 +595,7 @@ PPCODE:
 
            SPAGAIN;
 
-           if(count > 2 && !args_copy) {
+           if(count > 2 && !args_copy && ret_gimme == G_ARRAY) {
                int n_args = items - argi;
                Newx(args_copy, n_args, SV *);
                SAVEFREEPV(args_copy);
@@ -597,14 +606,21 @@ PPCODE:
                items = n_args;
            }
 
-           for(i = 0; i < count; i++)
-               ST(reti++) = sv_mortalcopy(SP[i - count + 1]);
+           if(ret_gimme == G_ARRAY)
+               for(i = 0; i < count; i++)
+                   ST(reti++) = sv_mortalcopy(SP[i - count + 1]);
+           else
+               reti += count;
 
            PUTBACK;
        }
     }
 
-    XSRETURN(reti);
+    if(ret_gimme == G_ARRAY)
+       XSRETURN(reti);
+
+    ST(0) = sv_2mortal(newSViv(reti));
+    XSRETURN(1);
 }
 
 void
@@ -615,6 +631,9 @@ PPCODE:
     int argi = 0;
     int reti = 0;
 
+    if(items % 2 && ckWARN(WARN_MISC))
+       warn("Odd number of elements in pairs");
+
     {
        for(; argi < items; argi += 2) {
            SV *a = ST(argi);
@@ -639,6 +658,9 @@ PPCODE:
     int argi = 0;
     int reti = 0;
 
+    if(items % 2 && ckWARN(WARN_MISC))
+       warn("Odd number of elements in pairkeys");
+
     {
        for(; argi < items; argi += 2) {
            SV *a = ST(argi);
@@ -658,6 +680,9 @@ PPCODE:
     int argi = 0;
     int reti = 0;
 
+    if(items % 2 && ckWARN(WARN_MISC))
+       warn("Odd number of elements in pairvalues");
+
     {
        for(; argi < items; argi += 2) {
            SV *b = argi < items-1 ? ST(argi+1) : &PL_sv_undef;
index d8a838f..f01bff2 100644 (file)
@@ -13,7 +13,7 @@ require Exporter;
 
 our @ISA        = qw(Exporter);
 our @EXPORT_OK  = qw(first min max minstr maxstr reduce sum sum0 shuffle pairmap pairgrep pairfirst pairs pairkeys pairvalues);
-our $VERSION    = "1.30";
+our $VERSION    = "1.31";
 our $XS_VERSION = $VERSION;
 $VERSION    = eval $VERSION;
 
index efd084e..bb38ab2 100644 (file)
@@ -2,7 +2,7 @@ package List::Util::XS;
 use strict;
 use List::Util;
 
-our $VERSION = "1.30";       # FIXUP
+our $VERSION = "1.31";       # FIXUP
 $VERSION = eval $VERSION;    # FIXUP
 
 1;
index 75c03fa..d10bbaa 100644 (file)
@@ -26,7 +26,7 @@ our @EXPORT_OK = qw(
   tainted
   weaken
 );
-our $VERSION    = "1.30";
+our $VERSION    = "1.31";
 $VERSION   = eval $VERSION;
 
 our @EXPORT_FAIL;
index 59282b1..46e0534 100644 (file)
@@ -1,9 +1,11 @@
 #!./perl
 
 use strict;
-use Test::More tests => 17;
+use Test::More tests => 20;
 use List::Util qw(pairgrep pairfirst pairmap pairs pairkeys pairvalues);
 
+no warnings 'misc'; # avoid "Odd number of elements" warnings most of the time
+
 is_deeply( [ pairgrep { $b % 2 } one => 1, two => 2, three => 3 ],
            [ one => 1, three => 3 ],
            'pairgrep list' );
@@ -17,6 +19,19 @@ is_deeply( [ pairgrep { $a } 0 => "zero", 1 => "one", 2 ],
            'pairgrep pads with undef' );
 
 {
+  use warnings 'misc';
+  my $warnings = "";
+  local $SIG{__WARN__} = sub { $warnings .= $_[0] };
+
+  pairgrep { } one => 1, two => 2;
+  is( $warnings, "", 'even-sized list yields no warnings from pairgrep' );
+
+  pairgrep { } one => 1, two =>;
+  like( $warnings, qr/^Odd number of elements in pairgrep at /,
+        'odd-sized list yields warning from pairgrep' );
+}
+
+{
   my @kvlist = ( one => 1, two => 2 );
   pairgrep { $b++ } @kvlist;
   is_deeply( \@kvlist, [ one => 2, two => 3 ], 'pairgrep aliases elements' );
@@ -41,6 +56,10 @@ is_deeply( [ pairmap { uc $a => $b } one => 1, two => 2, three => 3 ],
            [ ONE => 1, TWO => 2, THREE => 3 ],
            'pairmap list' );
 
+is( scalar( pairmap { qw( a b c ) } one => 1, two => 2 ),
+    6,
+    'pairmap scalar' );
+
 is_deeply( [ pairmap { $a => @$b } one => [1,1,1], two => [2,2,2], three => [3,3,3] ],
            [ one => 1, 1, 1, two => 2, 2, 2, three => 3, 3, 3 ],
            'pairmap list returning >2 items' );