Subject: | Bug Report: IPC::Lite version 0.4.37 |
Date: | Sun, 4 Dec 2011 01:23:01 -0600 |
To: | bug-IPC-Lite [...] rt.cpan.org |
From: | LearnedBy Error <learnedbyerror [...] gmail.com> |
There is a bug in the logic of the SPLICE subroutine. I discovered it when
trying to add a SPLICE subroutine.
The following code, will demostrate the problem.
#!/usr/bin/perl
use strict;
use warnings;
use IPC::Lite;
use Data::Dumper;
my %opt;
$opt{'sym'} = 'SYMBOL';
tie my @a, 'IPC::Lite', %opt;
my @b;
@a = ( 1, 2, 3 );
@b = ( 1, 2, 3 );
testit(\@a);
print "\n";
testit(\@b);
sub testit {
my $a = shift(@_);
foreach (@{ $a }) { print "\t$_" }
print "\n";
print q/scalar @{ $a } = /, scalar @{ $a }, "\n";
print q/splice(@{ $a }, 0, 1) = /, splice( @{ $a }, 0, 1 ), "\n";
foreach (@{ $a }) { print "\t$_" }
print "\n";
print q/scalar @{ $a } = /, scalar @{ $a }, "\n";
}
The following results are generated:
1 2 3
scalar @{ $a } = 3
splice(@{ $a }, 0, 1) = 1
Use of uninitialized value $_ in concatenation (.) or string at test13 line
27.
2 3
scalar @{ $a } = 3
1 2 3
scalar @{ $a } = 3
splice(@{ $a }, 0, 1) = 1
2 3
scalar @{ $a } = 2
Notice the undefined value and that scalar still shows a 3.
The logic error is in line 402 which currently reads:
for ( my $i = $offset ; $i < ( $offset + $length ) ; ++$i ) {
I made a change to the following code:
for ( my $i = $offset + 1; $i <= $self->FETCHSIZE; ++$i ) {
Rerunning the code from above now provided results consistent with working
on a native perl array.
1 2 3
scalar @{ $a } = 3
splice(@{ $a }, 0, 1) = 1
2 3
scalar @{ $a } = 2
1 2 3
scalar @{ $a } = 3
splice(@{ $a }, 0, 1) = 1
2 3
Note consistent results.
I also added the additional SHIFT subroutine to support shift on the tied
array.
sub SHIFT {
my ($self) = @_;
my @val = $self->SPLICE( 0, 1 );
return $val[0];
}
There is also a typo error on line 450. "store" should be "STORE".
I think that's about it. Sorry for not entering this straight into RT,
but I couldn't get logged in tonight for some reason.
lbe