develooper Front page | perl.perl5.changes | Postings from October 2019

[perl.git] branch blead updated. v5.31.4-359-ge4b195720b

From:
James Keenan via perl5-changes
Date:
October 13, 2019 12:11
Subject:
[perl.git] branch blead updated. v5.31.4-359-ge4b195720b
Message ID:
E1iJcia-0004FL-C4@git.dc.perl.space
In perl.git, the branch blead has been updated

<https://perl5.git.perl.org/perl.git/commitdiff/e4b195720bb9ebb04424319463f3dba4c2d7c2ae?hp=cba88c42578001df1a5d328c06ecd0eb0fb4be96>

- Log -----------------------------------------------------------------
commit e4b195720bb9ebb04424319463f3dba4c2d7c2ae
Author: James E Keenan <jkeenan@cpan.org>
Date:   Thu Oct 10 18:49:20 2019 -0400

    Do not use 'exists' on arrays; use 'defined' instead
    
    pod/perlfunc.pod advises us:
    
           WARNING: Calling "exists" on array values is strongly
           discouraged. The notion of deleting or checking the existence of
           Perl array elements is not conceptually coherent, and can lead
           to surprising behavior.
    
    While trying to extend the test coverage of Dumpvalue.pm, two instances
    of 'exists ARRAYREF' were noted.  In the second of these two instances,
    using 'exists ARRAYREF' resulted in the 'if' condition of an if/else
    block always returning true, thereby making the corresponding 'else'
    condition unreachable -- a situation which was confirmed by coverage
    analysis.
    
    We should only use best practices in modules maintained by Perl 5
    Porters; this patch implements that.  When we do so, a different (but
    actually better) error message appears in the second instance; so tests
    are updated as well.
    
    For: RT 134492

-----------------------------------------------------------------------

Summary of changes:
 dist/Dumpvalue/lib/Dumpvalue.pm        | 6 +++---
 dist/Dumpvalue/t/rt-134441-dumpvalue.t | 8 ++++----
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/dist/Dumpvalue/lib/Dumpvalue.pm b/dist/Dumpvalue/lib/Dumpvalue.pm
index 0bec4cb3e9..5a0d58ade7 100644
--- a/dist/Dumpvalue/lib/Dumpvalue.pm
+++ b/dist/Dumpvalue/lib/Dumpvalue.pm
@@ -2,7 +2,7 @@ use 5.006_001;			# for (defined ref) and $#$v and our
 package Dumpvalue;
 use strict;
 use warnings;
-our $VERSION = '1.20';
+our $VERSION = '1.21';
 our(%address, $stab, @stab, %stab, %subs);
 
 sub ASCII { return ord('A') == 65; }
@@ -256,7 +256,7 @@ sub unwrap {
       if ($#$v >= 0) {
 	$short = $sp . "0..$#{$v}  " .
 	  join(" ", 
-	       map {exists $v->[$_] ? $self->stringify($v->[$_]) : "empty"} (0..$tArrayDepth)
+	       map {defined $v->[$_] ? $self->stringify($v->[$_]) : "empty"} (0..$tArrayDepth)
 	      ) . "$shortmore";
       } else {
 	$short = $sp . "empty array";
@@ -266,7 +266,7 @@ sub unwrap {
     for my $num (0 .. $tArrayDepth) {
       return if $DB::signal and $self->{stopDbSignal};
       print "$sp$num  ";
-      if (exists $v->[$num]) {
+      if (defined $v->[$num]) {
         $self->DumpElem($v->[$num], $s);
       } else {
 	print "empty slot\n";
diff --git a/dist/Dumpvalue/t/rt-134441-dumpvalue.t b/dist/Dumpvalue/t/rt-134441-dumpvalue.t
index cc9f270f5a..324845d48d 100644
--- a/dist/Dumpvalue/t/rt-134441-dumpvalue.t
+++ b/dist/Dumpvalue/t/rt-134441-dumpvalue.t
@@ -39,11 +39,11 @@ is( $y, $x,
 @foobar = (undef, 'bar');
 $d->dumpValue([@foobar]);
 $x = $out->read;
-is( $x, "0  undef\n1  'bar'\n",
+is( $x, "0  empty slot\n1  'bar'\n",
     'dumpValue worked on array ref, first element undefined' );
 $d->dumpValues(@foobar);
 $y = $out->read;
-is( $y, "0  undef\n1  'bar'\n",
+is( $y, "0  empty slot\n1  'bar'\n",
     'dumpValues worked on array, first element undefined' );
 is( $y, $x,
     "dumpValues called on array returns same as dumpValue on array ref, first element undefined");
@@ -51,11 +51,11 @@ is( $y, $x,
 @foobar = ('bar', undef);
 $d->dumpValue([@foobar]);
 $x = $out->read;
-is( $x, "0  'bar'\n1  undef\n",
+is( $x, "0  'bar'\n1  empty slot\n",
     'dumpValue worked on array ref, last element undefined' );
 $d->dumpValues(@foobar);
 $y = $out->read;
-is( $y, "0  'bar'\n1  undef\n",
+is( $y, "0  'bar'\n1  empty slot\n",
     'dumpValues worked on array, last element undefined' );
 is( $y, $x,
     "dumpValues called on array returns same as dumpValue on array ref, last element undefined");

-- 
Perl5 Master Repository



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About