summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris 'BinGOs' Williams <chris@bingosnet.co.uk>2012-12-17 09:35:15 +0000
committerChris 'BinGOs' Williams <chris@bingosnet.co.uk>2012-12-17 09:44:32 +0000
commit8b1989690cb5c8e76b281f6f8b7829d8081649fc (patch)
treed7b4c0a579cf38b2aebde3f523259d00f43a0182
parent93b74b47eb5e224de232c87de1cafcd5a43fd945 (diff)
downloadperl-8b1989690cb5c8e76b281f6f8b7829d8081649fc.tar.gz
Update Scalar-List-Utils to CPAN version 1.26
[DELTA] 1.26 -- Sun Dec 16 19:39 * Merge patch from JDHEDDEN - Add Scalar::Util::isdual() RT#76150 1.25_01 -- Wed Nov 21 09:47 * Fix a hash order dependency bug t/tainted.t (Currently this is a core only version to fix perl5 smokes)
-rw-r--r--MANIFEST2
-rwxr-xr-xPorting/Maintainers.pl2
-rw-r--r--cpan/List-Util/Changes4
-rw-r--r--cpan/List-Util/ListUtil.xs10
-rw-r--r--cpan/List-Util/Makefile.PL2
-rw-r--r--cpan/List-Util/lib/List/Util.pm15
-rw-r--r--cpan/List-Util/lib/List/Util/XS.pm2
-rw-r--r--cpan/List-Util/lib/Scalar/Util.pm88
-rw-r--r--cpan/List-Util/t/dualvar.t65
-rw-r--r--cpan/List-Util/t/multicall-refcount.t21
-rw-r--r--cpan/List-Util/t/sum0.t15
11 files changed, 193 insertions, 33 deletions
diff --git a/MANIFEST b/MANIFEST
index d142795e64..527d585a11 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -1509,6 +1509,7 @@ cpan/List-Util/t/maxstr.t List::Util
cpan/List-Util/t/max.t List::Util
cpan/List-Util/t/minstr.t List::Util
cpan/List-Util/t/min.t List::Util
+cpan/List-Util/t/multicall-refcount.t
cpan/List-Util/t/openhan.t Scalar::Util
cpan/List-Util/t/proto.t Scalar::Util
cpan/List-Util/t/readonly.t Scalar::Util
@@ -1517,6 +1518,7 @@ cpan/List-Util/t/refaddr.t Scalar::Util
cpan/List-Util/t/reftype.t Scalar::Util
cpan/List-Util/t/shuffle.t List::Util
cpan/List-Util/t/stack-corruption.t List::Util
+cpan/List-Util/t/sum0.t
cpan/List-Util/t/sum.t List::Util
cpan/List-Util/t/tainted.t Scalar::Util
cpan/List-Util/t/weak.t Scalar::Util
diff --git a/Porting/Maintainers.pl b/Porting/Maintainers.pl
index 4f1fb55108..3699eceff3 100755
--- a/Porting/Maintainers.pl
+++ b/Porting/Maintainers.pl
@@ -1595,7 +1595,7 @@ use File::Glob qw(:case);
'Scalar-List-Utils' => {
'MAINTAINER' => 'gbarr',
- 'DISTRIBUTION' => 'PEVANS/Scalar-List-Utils-1.25.tar.gz',
+ 'DISTRIBUTION' => 'PEVANS/Scalar-List-Utils-1.26.tar.gz',
# Note that perl uses its own version of Makefile.PL
'FILES' => q[cpan/List-Util],
diff --git a/cpan/List-Util/Changes b/cpan/List-Util/Changes
index 1fcd9f6102..d390576fb4 100644
--- a/cpan/List-Util/Changes
+++ b/cpan/List-Util/Changes
@@ -1,3 +1,7 @@
+1.26 -- Sun Dec 16 19:39
+
+ * Merge patch from JDHEDDEN - Add Scalar::Util::isdual() RT#76150
+
1.25_01 -- Wed Nov 21 09:47
* Fix a hash order dependency bug t/tainted.t
diff --git a/cpan/List-Util/ListUtil.xs b/cpan/List-Util/ListUtil.xs
index be4b68c2cb..93e415c180 100644
--- a/cpan/List-Util/ListUtil.xs
+++ b/cpan/List-Util/ListUtil.xs
@@ -397,6 +397,16 @@ CODE:
XSRETURN(1);
}
+void
+isdual(sv)
+ SV *sv
+PROTOTYPE: $
+CODE:
+ if (SvMAGICAL(sv))
+ mg_get(sv);
+ ST(0) = boolSV((SvPOK(sv) || SvPOKp(sv)) && (SvNIOK(sv) || SvNIOKp(sv)));
+ XSRETURN(1);
+
char *
blessed(sv)
SV * sv
diff --git a/cpan/List-Util/Makefile.PL b/cpan/List-Util/Makefile.PL
index 40f91670e5..5068e34598 100644
--- a/cpan/List-Util/Makefile.PL
+++ b/cpan/List-Util/Makefile.PL
@@ -28,7 +28,7 @@ WriteMakefile(
( $PERL_CORE
? ()
: (
- INSTALLDIRS => q[perl],
+ INSTALLDIRS => ($] < 5.011 ? q[perl] : q[site]),
PREREQ_PM => {'Test::More' => 0,},
(eval { ExtUtils::MakeMaker->VERSION(6.31) } ? (LICENSE => 'perl') : ()),
( eval { ExtUtils::MakeMaker->VERSION(6.46) } ? (
diff --git a/cpan/List-Util/lib/List/Util.pm b/cpan/List-Util/lib/List/Util.pm
index c07e2d8ab0..39c4e7e903 100644
--- a/cpan/List-Util/lib/List/Util.pm
+++ b/cpan/List-Util/lib/List/Util.pm
@@ -12,14 +12,20 @@ use strict;
require Exporter;
our @ISA = qw(Exporter);
-our @EXPORT_OK = qw(first min max minstr maxstr reduce sum shuffle);
-our $VERSION = "1.25_01";
+our @EXPORT_OK = qw(first min max minstr maxstr reduce sum sum0 shuffle);
+our $VERSION = "1.26";
our $XS_VERSION = $VERSION;
$VERSION = eval $VERSION;
require XSLoader;
XSLoader::load('List::Util', $XS_VERSION);
+sub sum0
+{
+ return 0 unless @_;
+ goto &sum;
+}
+
1;
__END__
@@ -164,6 +170,11 @@ C<undef> being returned
$foo = sum 0, @values;
+=item sum0 LIST
+
+Similar to C<sum>, except this returns 0 when given an empty list, rather
+than C<undef>.
+
=back
=head1 KNOWN BUGS
diff --git a/cpan/List-Util/lib/List/Util/XS.pm b/cpan/List-Util/lib/List/Util/XS.pm
index b196e7dbb5..1fca3e4576 100644
--- a/cpan/List-Util/lib/List/Util/XS.pm
+++ b/cpan/List-Util/lib/List/Util/XS.pm
@@ -2,7 +2,7 @@ package List::Util::XS;
use strict;
use List::Util;
-our $VERSION = "1.25_01"; # FIXUP
+our $VERSION = "1.26"; # FIXUP
$VERSION = eval $VERSION; # FIXUP
1;
diff --git a/cpan/List-Util/lib/Scalar/Util.pm b/cpan/List-Util/lib/Scalar/Util.pm
index 4d034fcb24..b73f1e64f7 100644
--- a/cpan/List-Util/lib/Scalar/Util.pm
+++ b/cpan/List-Util/lib/Scalar/Util.pm
@@ -11,8 +11,22 @@ require Exporter;
require List::Util; # List::Util loads the XS
our @ISA = qw(Exporter);
-our @EXPORT_OK = qw(blessed dualvar reftype weaken isweak tainted readonly openhandle refaddr isvstring looks_like_number set_prototype);
-our $VERSION = "1.25_01";
+our @EXPORT_OK = qw(
+ blessed
+ dualvar
+ isdual
+ isvstring
+ isweak
+ looks_like_number
+ openhandle
+ readonly
+ refaddr
+ reftype
+ set_prototype
+ tainted
+ weaken
+);
+our $VERSION = "1.26";
$VERSION = eval $VERSION;
our @EXPORT_FAIL;
@@ -51,8 +65,9 @@ Scalar::Util - A selection of general-utility scalar subroutines
=head1 SYNOPSIS
- use Scalar::Util qw(blessed dualvar isweak readonly refaddr reftype tainted
- weaken isvstring looks_like_number set_prototype);
+ use Scalar::Util qw(blessed dualvar isdual readonly refaddr reftype
+ tainted weaken isweak isvstring looks_like_number
+ set_prototype);
# and other useful utils appearing below
=head1 DESCRIPTION
@@ -90,27 +105,40 @@ value STRING in a string context.
$num = $foo + 2; # 12
$str = $foo . " world"; # Hello world
-=item isvstring EXPR
+=item isdual EXPR
-If EXPR is a scalar which was coded as a vstring the result is true.
+If EXPR is a scalar that is a dualvar, the result is true.
- $vs = v49.46.48;
- $fmt = isvstring($vs) ? "%vd" : "%s"; #true
- printf($fmt,$vs);
+ $foo = dualvar 86, "Nix";
+ $dual = isdual($foo); # true
-=item isweak EXPR
+Note that a scalar can be made to have both string and numeric content
+through numeric operations:
-If EXPR is a scalar which is a weak reference the result is true.
+ $foo = "10";
+ $dual = isdual($foo); # false
+ $bar = $foo + 0;
+ $dual = isdual($foo); # true
- $ref = \$foo;
- $weak = isweak($ref); # false
- weaken($ref);
- $weak = isweak($ref); # true
+Note that although C<$!> appears to be dual-valued variable, it is
+actually implemented using a tied scalar:
-B<NOTE>: Copying a weak reference creates a normal, strong, reference.
+ $! = 1;
+ print("$!\n"); # "Operation not permitted"
+ $dual = isdual($!); # false
- $copy = $ref;
- $weak = isweak($copy); # false
+You can capture its numeric and string content using:
+
+ $err = dualvar $!, $!;
+ $dual = isdual($err); # true
+
+=item isvstring EXPR
+
+If EXPR is a scalar which was coded as a vstring the result is true.
+
+ $vs = v49.46.48;
+ $fmt = isvstring($vs) ? "%vd" : "%s"; #true
+ printf($fmt,$vs);
=item looks_like_number EXPR
@@ -122,11 +150,11 @@ L<perlapi/looks_like_number>.
Returns FH if FH may be used as a filehandle and is open, or FH is a tied
handle. Otherwise C<undef> is returned.
- $fh = openhandle(*STDIN); # \*STDIN
- $fh = openhandle(\*STDIN); # \*STDIN
- $fh = openhandle(*NOTOPEN); # undef
- $fh = openhandle("scalar"); # undef
-
+ $fh = openhandle(*STDIN); # \*STDIN
+ $fh = openhandle(\*STDIN); # \*STDIN
+ $fh = openhandle(*NOTOPEN); # undef
+ $fh = openhandle("scalar"); # undef
+
=item readonly SCALAR
Returns true if SCALAR is readonly.
@@ -209,6 +237,20 @@ references to objects will be strong, causing the remaining objects to never
be destroyed because there is now always a strong reference to them in the
@object array.
+=item isweak EXPR
+
+If EXPR is a scalar which is a weak reference the result is true.
+
+ $ref = \$foo;
+ $weak = isweak($ref); # false
+ weaken($ref);
+ $weak = isweak($ref); # true
+
+B<NOTE>: Copying a weak reference creates a normal, strong, reference.
+
+ $copy = $ref;
+ $weak = isweak($copy); # false
+
=back
=head1 DIAGNOSTICS
diff --git a/cpan/List-Util/t/dualvar.t b/cpan/List-Util/t/dualvar.t
index 5c0fe2140b..abd6479001 100644
--- a/cpan/List-Util/t/dualvar.t
+++ b/cpan/List-Util/t/dualvar.t
@@ -16,22 +16,27 @@ BEGIN {
use Scalar::Util ();
use Test::More (grep { /dualvar/ } @Scalar::Util::EXPORT_FAIL)
? (skip_all => 'dualvar requires XS version')
- : (tests => 13);
+ : (tests => 41);
+use Config;
Scalar::Util->import('dualvar');
+Scalar::Util->import('isdual');
$var = dualvar( 2.2,"string");
+ok( isdual($var), 'Is a dualvar');
ok( $var == 2.2, 'Numeric value');
ok( $var eq "string", 'String value');
$var2 = $var;
+ok( isdual($var2), 'Is a dualvar');
ok( $var2 == 2.2, 'copy Numeric value');
ok( $var2 eq "string", 'copy String value');
$var++;
+ok( ! isdual($var), 'No longer dualvar');
ok( $var == 3.2, 'inc Numeric value');
ok( $var ne "string", 'inc String value');
@@ -40,15 +45,23 @@ my $numtmp = int($numstr); # use $numstr as an int
$var = dualvar($numstr, "");
+ok( isdual($var), 'Is a dualvar');
ok( $var == $numstr, 'NV');
SKIP: {
skip("dualvar with UV value known to fail with $]",2) if $] < 5.006_001;
- $var = dualvar(1<<31, "");
- ok( $var == (1<<31), 'UV 1');
- ok( $var > 0, 'UV 2');
+ my $bits = ($Config{'use64bitint'}) ? 63 : 31;
+ $var = dualvar(1<<$bits, "");
+ ok( isdual($var), 'Is a dualvar');
+ ok( $var == (1<<$bits), 'UV 1');
+ ok( $var > 0, 'UV 2');
}
+# Create a dualvar "the old fashioned way"
+$var = "10";
+ok( ! isdual($var), 'Not a dualvar');
+my $foo = $var + 0;
+ok( isdual($var), 'Is a dualvar');
{
package Tied;
@@ -59,12 +72,54 @@ SKIP: {
tie my $tied, 'Tied';
$var = dualvar($tied, "ok");
+ok(isdual($var), 'Is a dualvar');
ok($var == 7.5, 'Tied num');
ok($var eq 'ok', 'Tied str');
SKIP: {
- skip("need utf8::is_utf8",2) unless defined &utf8::is_utf8;
+ skip("need utf8::is_utf8",3) unless defined &utf8::is_utf8;
ok(!!utf8::is_utf8(dualvar(1,chr(400))), 'utf8');
ok( !utf8::is_utf8(dualvar(1,"abc")), 'not utf8');
}
+
+
+SKIP: {
+ skip("Perl not compiled with 'useithreads'",20) unless ($Config{'useithreads'});
+ require threads; import threads;
+ require threads::shared; import threads::shared;
+ skip("Requires threads::shared v1.42 or later",20) unless ($threads::shared::VERSION >= 1.42);
+
+ my $siv :shared = dualvar(42, 'Fourty-Two');
+ my $snv :shared = dualvar(3.14, 'PI');
+ my $bits = ($Config{'use64bitint'}) ? 63 : 31;
+ my $suv :shared = dualvar(1<<$bits, 'Large unsigned int');
+
+ ok($siv == 42, 'Shared IV number preserved');
+ ok($siv eq 'Fourty-Two', 'Shared string preserved');
+ ok(isdual($siv), 'Is a dualvar');
+ ok($snv == 3.14, 'Shared NV number preserved');
+ ok($snv eq 'PI', 'Shared string preserved');
+ ok(isdual($snv), 'Is a dualvar');
+ ok($suv == (1<<$bits), 'Shared UV number preserved');
+ ok($suv > 0, 'Shared UV number preserved');
+ ok($suv eq 'Large unsigned int', 'Shared string preserved');
+ ok(isdual($suv), 'Is a dualvar');
+
+ my @ary :shared;
+ $ary[0] = $siv;
+ $ary[1] = $snv;
+ $ary[2] = $suv;
+
+ ok($ary[0] == 42, 'Shared IV number preserved');
+ ok($ary[0] eq 'Fourty-Two', 'Shared string preserved');
+ ok(isdual($ary[0]), 'Is a dualvar');
+ ok($ary[1] == 3.14, 'Shared NV number preserved');
+ ok($ary[1] eq 'PI', 'Shared string preserved');
+ ok(isdual($ary[1]), 'Is a dualvar');
+ ok($ary[2] == (1<<$bits), 'Shared UV number preserved');
+ ok($ary[2] > 0, 'Shared UV number preserved');
+ ok($ary[2] eq 'Large unsigned int', 'Shared string preserved');
+ ok(isdual($ary[2]), 'Is a dualvar');
+}
+
diff --git a/cpan/List-Util/t/multicall-refcount.t b/cpan/List-Util/t/multicall-refcount.t
new file mode 100644
index 0000000000..1d6fb59808
--- /dev/null
+++ b/cpan/List-Util/t/multicall-refcount.t
@@ -0,0 +1,21 @@
+use Test::More tests => 1;
+
+use List::Util 'first';
+
+our $comparison;
+
+sub foo {
+ if( $comparison ) {
+ return 1;
+ }
+ else {
+ local $comparison = 1;
+ first \&foo, 1,2,3;
+ }
+}
+
+for(1,2){
+ foo();
+}
+
+ok( "Didn't crash calling recursively" );
diff --git a/cpan/List-Util/t/sum0.t b/cpan/List-Util/t/sum0.t
new file mode 100644
index 0000000000..e76f8a79d3
--- /dev/null
+++ b/cpan/List-Util/t/sum0.t
@@ -0,0 +1,15 @@
+use strict;
+use warnings;
+
+use Test::More tests => 3;
+
+use List::Util qw( sum0 );
+
+my $v = sum0;
+is( $v, 0, 'no args' );
+
+$v = sum0(9);
+is( $v, 9, 'one arg' );
+
+$v = sum0(1,2,3,4);
+is( $v, 10, '4 args');