-
Notifications
You must be signed in to change notification settings - Fork 235
Meta::Helper: be more calling-context aware. #91
Conversation
Since we're offering `html_enc` as an alternative to `encode_entities` it should behave in the same way when supplied a scalar and expecting scalar output. Mostly we're concerned about when they want scalar output, so we'll just encode the first element off the supplied array if that's how they've called us. `uri_esc` is similarly updated to provide similar semantics.
An alternative is to concatenate the string in the scalar case. I'm not too bothered going either way. |
@mwmiller I think I'd expect it to concatenate if going from array to scalar context for situations like:
Edit: on reflection, isn't that useless anyway?! It'd be far better to just do |
Based on input from @mintsoft. I can see how this makes more sense, so I'm on-board, too.
@mintsoft I can make arguments both ways. I'm honestly not sure which way provides "less astonishment." I'm mostly worried about the conversion of the single element to scalar case, so I don't have a well-formed opinion. Edit: Also, I went ahead and changed it based on your preedit comment, because I had no strong opinion. |
@mwmiller on reflection this morning I think my original thoughts make the most sense. I'd be weird to pass an array into something and have it appear to randomly lose data by only using the first element of the array. So I think it's now correct |
This was what made me decide to switch it based on your original comment. I figure at least it's obvious what happened with all of the data if you call it "incorrectly." |
This is awesome guys, nicely done. 👍 |
@moollaza very possibly; but I think it probably depends on how they're implemented |
@moollaza I don't know how it might change with Goodie templates, but I'm pretty deeply involved there, so I'll keep myself in the loop.:grin: |
@@ -37,7 +37,7 @@ encodes entities to safely post random data on HTML output. | |||
|
|||
=cut | |||
|
|||
$stash->add_symbol('&html_enc', sub { map { encode_entities($_) } @_ }); | |||
$stash->add_symbol('&html_enc', sub { return (wantarray) ? map { encode_entities($_) } @_ : encode_entities(join '', @_) }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
didn't know wantarray
existed. Very cool
Meta::Helper: be more calling-context aware.
I believe wantarray is often (perhaps always?) astonishing in some context. This is the YAPC talk that convinced me. Its kind of a fun talk actually: http://aaroncrane.co.uk/talks/calamitous_context/ Its really lame of me to make a comment after this has been released and its not really a big deal anyway. I just thought I would throw this idea out to consider for the future. |
@kablamo No, it's actually a very good point! I don't think it's particularly dangerous or horrible in the proximate case, but we should always be wary of context-sensitive code. I think the reason I am more or less ok with it here is because it directly on the provided arguments, not some hidden state which would make it more difficult to reason about what's happening. I might well be wrong about how this is better. 😁 Thanks for the link to the talk. I found it quite interesting. |
@mwmiller you mentioned the goodie templates before, is there a place where that work is being done? Is there anything I can do to assist? |
@mintsoft There's nothing much to see right at the moment. I have a working prototype, but everything interesting happens on the closed-source side of the house at the moment. I expect in the next week or two the changes will appear to leap fully-formed into a repo near you. At the point, I look forward to your help in identifying edges I have missed as we go about converting goodies. 😁 |
@mwmiller cool, just lemme know if I can be of any use 👍 |
Since we're offering
html_enc
as an alternative toencode_entities
it should behave in the same way when supplied a scalar and expecting
scalar output. Mostly we're concerned about when they want scalar
output, so we'll just encode the first element off the supplied array if
that's how they've called us.
uri_esc
is similarly updated to provide similar semantics.cc: @mintsoft