From: Graham Barr Date: Wed, 5 Sep 2001 12:51:35 +0000 (+0000) Subject: Update to Scalar-List-Utils 1.04 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c29e891d32b4c033b2ab469aa98993b4fd539a05;p=p5sagit%2Fp5-mst-13.2.git Update to Scalar-List-Utils 1.04 p4raw-id: //depot/perl@11883 --- diff --git a/ext/List/Util/ChangeLog b/ext/List/Util/ChangeLog index eaad55b..4a4040f 100644 --- a/ext/List/Util/ChangeLog +++ b/ext/List/Util/ChangeLog @@ -1,3 +1,16 @@ +Change 639 on 2001/09/05 by (Graham Barr) + + Fix context type (caused a core on Tru64) + Call pp_rand via *(PL_ppaddr[OP_RAND]) + +Change 638 on 2001/09/05 by (Graham Barr) + + Documentation updates + +Change 637 on 2001/09/03 by (Graham Barr) + + Release 1.03 + Change 636 on 2001/09/03 by (Graham Barr) More changes to help merging with core dist diff --git a/ext/List/Util/Util.xs b/ext/List/Util/Util.xs index 8720d98..86d0e66 100644 --- a/ext/List/Util/Util.xs +++ b/ext/List/Util/Util.xs @@ -268,16 +268,15 @@ CODE: SV *my_pad[2]; SV **old_curpad = PL_curpad; + /* We call pp_rand here so that Drand01 get initialized if rand() + or srand() has not already been called + */ my_pad[1] = sv_newmortal(); memzero((char*)(&dmy_op), sizeof(struct op)); dmy_op.op_targ = 1; PL_op = &dmy_op; PL_curpad = (SV **)&my_pad; - /* Call *(PL_ppaddr[OP_RAND]) so that Drand01 get initialized if rand() - or srand() has not already been called. Can't call pp_rand() - since it's not in the public API (and shouldn't be). - */ - *(PL_ppaddr[OP_RAND]); + *(PL_ppaddr[OP_RAND])(); PL_op = old_op; PL_curpad = old_curpad; for (index = items ; index > 1 ; ) { diff --git a/ext/List/Util/lib/List/Util.pm b/ext/List/Util/lib/List/Util.pm index 818f5d7..70be647 100644 --- a/ext/List/Util/lib/List/Util.pm +++ b/ext/List/Util/lib/List/Util.pm @@ -1,6 +1,6 @@ # List::Util.pm # -# Copyright (c) 1997-2000 Graham Barr . All rights reserved. +# Copyright (c) 1997-2001 Graham Barr . All rights reserved. # This program is free software; you can redistribute it and/or # modify it under the same terms as Perl itself. @@ -11,7 +11,7 @@ require DynaLoader; our @ISA = qw(Exporter DynaLoader); our @EXPORT_OK = qw(first min max minstr maxstr reduce sum shuffle); -our $VERSION = "1.03_00"; +our $VERSION = "1.04_00"; bootstrap List::Util $VERSION; @@ -25,7 +25,7 @@ List::Util - A selection of general-utility list subroutines =head1 SYNOPSIS - use List::Util qw(first sum min max minstr maxstr reduce); + use List::Util qw(first max maxstr min minstr reduce shuffle sum); =head1 DESCRIPTION @@ -49,7 +49,7 @@ C is returned. $foo = first { defined($_) } @list # first defined value in @list $foo = first { $_ > $value } @list # first value in @list which # is greater than $value - + This function could be implemented using C like this $foo = reduce { defined($a) ? $a : wanted($b) ? $b : undef } undef, @list @@ -75,8 +75,8 @@ This function could be implemented using C like this Similar to C, but treats all the entries in the list as strings and returns the highest string as defined by the C operator. If the list is empty then C is returned. - - $foo = maxstr 'A'..'Z' # 'Z' + + $foo = maxstr 'A'..'Z' # 'Z' $foo = maxstr "hello","world" # "world" $foo = maxstr @bar, @baz # whatever @@ -103,9 +103,9 @@ Similar to C, but treats all the entries in the list as strings and returns the lowest string as defined by the C operator. If the list is empty then C is returned. - $foo = maxstr 'A'..'Z' # 'A' - $foo = maxstr "hello","world" # "hello" - $foo = maxstr @bar, @baz # whatever + $foo = minstr 'A'..'Z' # 'A' + $foo = minstr "hello","world" # "hello" + $foo = minstr @bar, @baz # whatever This function could be implemented using C like this @@ -117,7 +117,7 @@ Reduces LIST by calling BLOCK multiple times, setting C<$a> and C<$b> each time. The first call will be with C<$a> and C<$b> set to the first two elements of the list, subsequent calls will be done by setting C<$a> to the result of the previous call and C<$b> to the next -element in the list. +element in the list. Returns the result of the last call to BLOCK. If LIST is empty then C is returned. If LIST only contains one element then that @@ -132,6 +132,8 @@ element is returned and BLOCK is not executed. Returns the elements of LIST in a random order + @cards = shuffle 0..51 # 0..51 in a random order + =item sum LIST Returns the sum of all the elements in LIST. @@ -177,7 +179,7 @@ to add due to them being very simple to implement in perl =head1 COPYRIGHT -Copyright (c) 1997-2000 Graham Barr . All rights reserved. +Copyright (c) 1997-2001 Graham Barr . All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. diff --git a/ext/List/Util/lib/Scalar/Util.pm b/ext/List/Util/lib/Scalar/Util.pm index 8a7a8a3..432361f 100644 --- a/ext/List/Util/lib/Scalar/Util.pm +++ b/ext/List/Util/lib/Scalar/Util.pm @@ -1,6 +1,6 @@ # Scalar::Util.pm # -# Copyright (c) 1997-2000 Graham Barr . All rights reserved. +# Copyright (c) 1997-2001 Graham Barr . All rights reserved. # This program is free software; you can redistribute it and/or # modify it under the same terms as Perl itself. @@ -23,7 +23,7 @@ Scalar::Util - A selection of general-utility scalar subroutines =head1 SYNOPSIS - use Scalar::Util qw(blessed dualvar reftype weaken isweak); + use Scalar::Util qw(blessed dualvar isweak readonly reftype tainted weaken); =head1 DESCRIPTION @@ -42,32 +42,61 @@ subroutines defined are If EXPR evaluates to a blessed reference the name of the package that it is blessed into is returned. Otherwise C is returned. + $scalar = "foo"; + $class = blessed $scalar; # undef + + $ref = []; + $class = blessed $ref; # undef + + $obj = bless [], "Foo"; + $class = blessed $obj; # "Foo" + =item dualvar NUM, STRING Returns a scalar that has the value NUM in a numeric context and the value STRING in a string context. $foo = dualvar 10, "Hello"; - $num = $foo + 2; # 12 - $str = $foo . " world"; # Hello world + $num = $foo + 2; # 12 + $str = $foo . " world"; # Hello world =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 + =item readonly SCALAR Returns true if SCALAR is readonly. + sub foo { readonly($_[0]) } + + $readonly = foo($bar); # false + $readonly = foo(0); # true + =item reftype EXPR If EXPR evaluates to a reference the type of the variable referenced is returned. Otherwise C is returned. + $type = reftype "string"; # undef + $type = reftype \$var; # SCALAR + $type = reftype []; # ARRAY + + $obj = bless {}, "Foo"; + $type = reftype $obj; # HASH + =item tainted EXPR Return true if the result of EXPR is tainted + $taint = tainted("constant"); # false + $taint = tainted($ENV{PWD}); # true if running under -T + =item weaken REF REF will be turned into a weak reference. This means that it will not @@ -77,15 +106,22 @@ count on that object reaches zero, REF will be set to undef. This is useful for keeping copies of references , but you don't want to prevent the object being DESTROY-ed at its usual time. + { + my $var; + $ref = \$var; + weaken($ref); # Make $ref a weak reference + } + # $ref is now undef + =back =head1 COPYRIGHT -Copyright (c) 1997-2000 Graham Barr . All rights reserved. -This program is free software; you can redistribute it and/or modify it +Copyright (c) 1997-2001 Graham Barr . All rights reserved. +This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. -except weaken and isweak which are +Except weaken and isweak which are Copyright (c) 1999 Tuomas J. Lukka . All rights reserved. This program is free software; you can redistribute it and/or modify it