Subject: | New scalar overwrites previous constant. |
When you assign a variable, as done in the test code:
tie my $s, 'ex::constant::vars', 100;
And later assign a new variable:
tie my $p, 'ex::constant::vars', 200;
The first variable $s also changes to 200.
This failing scenario is not covered by any testcase.
Two patches are attached to this bug report that:
1) Detects the above failing scenario in the test.pl testcode:
test.pl.patch.
2) Fixes the bug in vars.pm: vars.pm.patch
This is not platform related as far as i can see, but for completeness I
will give your the environment details where it was reproduced:
Perl versions: 5.6.1, 5.8.4
Platform: Solaris 5.8 or 5.10
Subject: | test.pl.patch |
*** ex-constant-vars-0.01_SunOS/test.pl Wed Nov 29 22:04:13 2000
--- test.pl Tue Nov 17 13:01:56 2009
***************
*** 6,12 ****
# change 'tests => 1' to 'tests => last_test_to_print';
use Test;
! BEGIN { plan tests => 20 };
use ex::constant::vars;
ok(1); # If we made it this far, we're ok.
--- 6,12 ----
# change 'tests => 1' to 'tests => last_test_to_print';
use Test;
! BEGIN { plan tests => 23 };
use ex::constant::vars;
ok(1); # If we made it this far, we're ok.
***************
*** 28,33 ****
--- 28,40 ----
eval { chop $s };
ok( $@ );
+ # Check if other vars do not change with new tie
+ ok( tie my $p, 'ex::constant::vars', 200 );
+ ok( $p == 200 );
+ # Is the other changed?
+ ok( $s == 100 );
+
+
# Arrays
use ex::constant::vars 'const';
Subject: | vars.pm.patch |
*** ex-constant-vars-0.01_SunOS/vars.pm Wed Nov 29 22:13:53 2000
--- vars.pm Tue Nov 17 12:51:52 2009
***************
*** 14,20 ****
ex::constant::vars::hash
);
our @EXPORT_OK = qw( const SCALAR ARRAY HASH );
! our $VERSION = '0.01';
sub const {
my $type = shift;
--- 14,20 ----
ex::constant::vars::hash
);
our @EXPORT_OK = qw( const SCALAR ARRAY HASH );
! our $VERSION = '0.011';
sub const {
my $type = shift;
***************
*** 67,73 ****
package ex::constant::vars::scalar;
use Carp;
$Carp::CarpLevel = 1;
! sub TIESCALAR { bless \($_=pop), __PACKAGE__ }
sub FETCH { ${$_[0]} }
sub STORE { croak "Modification of a read-only value attempted" }
--- 67,73 ----
package ex::constant::vars::scalar;
use Carp;
$Carp::CarpLevel = 1;
! sub TIESCALAR { bless \(my $x=pop), __PACKAGE__ }
sub FETCH { ${$_[0]} }
sub STORE { croak "Modification of a read-only value attempted" }