-
Notifications
You must be signed in to change notification settings - Fork 559
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow can()
to take a list of methods
#22405
Conversation
Great idea and work, thanks a lot! My minor feedback: Can format Also, can remove the |
can()
to take a list of methods
can()
to take a list of methodscan()
to take a list of methods
@rwp0 Thank you. Done! |
As I recall, we discussed something like this 30 years ago. :) |
I don't like this code for two reasons:
|
What do you mean a non-empty list on failure? I don't get that. It returns undef on failure. In list context undef is I wonder if it's possible to enable boolean tracking for lists, such that. my @foo = undef Instead of constructing Other than that, it seems that by requesting that Other options may be to make -
Agreed. This puts the whole project at risk. |
That would additionally be context sensitivity, which has led to many high profile bugs due to list context occurring unintentionally such as when constructing hashes or passing arguments to functions, thus my earlier objection to such on the list.
Unfortunately, while this seems reasonable to me for informational purposes, it makes it very annoying to check the results for success. |
The only return value that would make sense to me for this would be a list of subrefs the same length as its input. But that isn't useful as a boolean check as either an any or an all check. I don't think this is a good idea. |
universal.c
Outdated
} | ||
|
||
EXTEND(SP, items - 1); |
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.
You moved the writes to the stack before the EXTEND(), which may write beyond the end of the stack, the EXTEND should be moved above the loop.
The main problem I see is can() is overrideable, and perlobj even suggests overriding can() if you're using AUTOLOAD for methods. Such existing overrides are unlikely to implement this new signature. |
I think this might be the way to go about it |
I think there's enough objection to this that it's OK to close. It was more an experiment with XS, anyway. Thanks for the feedback, all! |
Not very familiar with core hacking, so feedback needed to see if this is sane at all.
Based on this discussion on P5P, this draft PR attempts to extend
can()
to accept a list of methods. If all of the methods are available, returns a list of coderefs matching those methods, in order. If any of the methods is not available, it returnsundef
.Notes
universal.c
t/universal.t
I wasn't sure how we felt about checking context in the core, so I punted on the last issue, but returning a coderef feels wrong.