diff options
author | Father Chrysostomos <sprout@cpan.org> | 2011-04-18 21:29:11 -0700 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2011-04-18 21:29:32 -0700 |
commit | d806590792484020987549ec4683b175c90d6263 (patch) | |
tree | a86f5ad78f320212167e68200755801e977bf194 /t | |
parent | 006671a67d63718163a0f4771c9dc358db053aad (diff) | |
download | perl-d806590792484020987549ec4683b175c90d6263.tar.gz |
Make keys $scalar an lvalue
This does a run-time check to see whether $scalar is a hash ref, and
dies if it is not.
This is to keep keys \@_ consistent with keys @_.
I cannot simply use OPf_MOD, since that indicates *potential* lvalue
context (including subroutine args).
So, instead, I take advantage of the fact that OPf_SPECIAL is always
set on the LHS of an assignment (usually to indicate that local()
should not erase the value).
Diffstat (limited to 't')
-rw-r--r-- | t/op/smartkve.t | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/t/op/smartkve.t b/t/op/smartkve.t index 7c57e7bba4..ad56e6a9c4 100644 --- a/t/op/smartkve.t +++ b/t/op/smartkve.t @@ -131,6 +131,14 @@ ok(defined $empty, 'Vivify: $empty (after keys $empty->{hash}) is HASHREF'); ok(!defined $empty->{hash} , 'Vivify: $empty->{hash} is undef'); +# Keys -- lvalue +$_{foo} = "bar"; +keys \%_ = 65; +is scalar %_, '1/128', 'keys $hashref as lvalue'; +eval 'keys \@_ = 65'; +like $@, qr/Can't modify keys on reference in scalar assignment/, + 'keys $arrayref as lvalue dies'; + # Keys -- errors $errpat = qr/ (?-x:Type of argument to keys on reference must be unblessed hashref or) |