'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/},
-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
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));
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));
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));
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);
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
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);
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);
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;
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;
use strict;
use List::Util;
-our $VERSION = "1.30"; # FIXUP
+our $VERSION = "1.31"; # FIXUP
$VERSION = eval $VERSION; # FIXUP
1;
tainted
weaken
);
-our $VERSION = "1.30";
+our $VERSION = "1.31";
$VERSION = eval $VERSION;
our @EXPORT_FAIL;
#!./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' );
'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' );
[ 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' );