Permalink
Browse files

SvREADONLY must be applied to the hash, not the hashref. Father C++.

  • Loading branch information...
1 parent e3599b5 commit cbd4469086ceb2b068761b90a5483fe5994b69cc @jkeenan committed Apr 29, 2012
Showing with 5 additions and 6 deletions.
  1. +2 −2 lib/Hash/Util.pm
  2. +3 −4 t/Util.t
View
4 lib/Hash/Util.pm
@@ -372,7 +372,7 @@ Returns true if the hash and its keys are locked.
sub hashref_locked {
my $hash=shift;
- Internals::SvREADONLY($hash);
+ Internals::SvREADONLY(%$hash);
}
sub hash_locked(\%) { hashref_locked(@_) }
@@ -390,7 +390,7 @@ Returns true if the hash and its keys are unlocked.
sub hashref_unlocked {
my $hash=shift;
- !Internals::SvREADONLY($hash);
+ !Internals::SvREADONLY(%$hash);
}
sub hash_unlocked(\%) { hashref_unlocked(@_) }
View
7 t/Util.t
@@ -152,7 +152,7 @@ is( $hash{locked}, 42, 'unlock_value' );
{
my %hash = (foo => 42, bar => 23);
lock_hash( %hash );
- ok( hashref_locked( { %hash } ), 'hashref_locked' );
+ ok( hashref_locked( \%hash ), 'hashref_locked' );
ok( hash_locked( %hash ), 'hash_locked' );
ok( Internals::SvREADONLY(%hash),'Was locked %hash' );
@@ -168,14 +168,13 @@ is( $hash{locked}, 42, 'unlock_value' );
ok( !Internals::SvREADONLY($hash{bar}),'Was unlocked $hash{bar}' );
}
-TODO: {
- local $TODO = 'negated hash(ref)_(un)locked not yet working';
+{
my %hash = (foo => 42, bar => 23);
ok( ! hashref_locked( { %hash } ), 'hashref_locked negated' );
ok( ! hash_locked( %hash ), 'hash_locked negated' );
lock_hash( %hash );
- ok( ! hashref_unlocked( { %hash } ), 'hashref_unlocked negated' );
+ ok( ! hashref_unlocked( \%hash ), 'hashref_unlocked negated' );
ok( ! hash_unlocked( %hash ), 'hash_unlocked negated' );
}

0 comments on commit cbd4469

Please sign in to comment.