Closed schwern closed 11 years ago
OIC it thinks its a block. Patch on the way.
Hrm. I can special case an empty hash, but what about hashes in general? I don't think there will be much call for checking for anything but an empty hash, so I'm inclined to just special case it. Anything more complicated can be done as a full block.
Hashes in general are already supported.
PPI uses the usual perlish guesswork to determine whether a pair of curlies are a hash or a block.
Empty curlies are arguably a useless special case as an empty hash will never smartmatch anything.
Of course, treating {} as an empty block would be equally useless, so special casing them as empty hash is probably for the best (i.e. least surprising).
Well, we should probably special-case it as whatever-doesn't-generate-a-syntax-error. :-D
This fix will go into the next dev release. Just waiting now for CPANTesters to throw up some reports for me to look at ...
@thoughtstream PPI might have that guesswork, but inject_for_sig() isn't using it. It's using a regex. I'll look at switching it to PPI, but this fix to the existing regex should go in.
And an empty hash ref smart matches, surprise, an empty hash ref.
perl -wle '$h = {}; print $h ~~ {} ? "Match" : "No Match" '
Match
perl -wle '$h = { foo => 23 }; print $h ~~ {} ? "Match" : "No Match" '
No Match
This is handy for providing a default if the user passes in an empty hash ref, similar to using when ""
for a string parameter.
Very good point re empty hashref matching empty hashes. This definitely should be special-cased.
Fixed in version 20121201.
This works fine.
This is a messy parse error.
Something's gone wrong with the injection.