-
Notifications
You must be signed in to change notification settings - Fork 60
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
Polyfill for __SUB__ token #46
base: master
Are you sure you want to change the base?
Conversation
lib/Sub/Util.pm
Outdated
@@ -21,6 +21,28 @@ $VERSION = eval $VERSION; | |||
require List::Util; # as it has the XS | |||
List::Util->VERSION( $VERSION ); # Ensure we got the right XS version (RT#100863) | |||
|
|||
use constant CAN_SUB => $^V >= 5.016; |
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.
Should check against
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.
$^V
is not available in 5.6 for example and stands for v5.x
in later version
even if the compare is not incorrect for modern Perl version
you should use $]
as discussed on IRC this PR should probably be held until ROUTINE is made private (I think that is the side we fell to) and some documentation is added. |
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.
view comment about $]
instead of $^V
.
Is it as simple as changing the variable? Do I also have to change the comparison? |
No, it is already comparing against the right decimal number. |
This branch is very stale but locally a rebased version passes tests. Any opposition to me force-pushing the rebased version? |
I would say rebase && force push. The CI will confirm how it stands with the various Perl version |
OK so it fails on 5.6. Is that fixable? Is it allowable? |
@jberger the problem comes from
So I came with a poor man alternate with an additional commit to provide it when missing, and it seems to work... view commit: view CI proof of concept: So cherry picking this commit to your branch should fix your concern. |
That's beyond my power to evaluate. @leonerd thoughts? |
Per the discussion on https://rt.cpan.org/Public/Bug/Display.html?id=111466 this PR implements a polyfill for the
__SUB__
token. The code is mostly lifted from Sub::Current (Rafael Garcia-Suarez). I did the porting and Aaron Crane helped with an issue I ran into.The one remaining question in my mind is if
ROUTINE
should be exported/exportable or not. The case for it is that it would allow a cautious user to always use the polyfill implementation rather than relying on__SUB__
being the polyfill on old perl versions vs being the core token in newer versions. The case against is the added complexity of having two different names doing the ostensibly the same thing. Thoughts?The difference between
__SUB__
andSub::Current::ROUTINE
is the behavior inside the BEGIN/END/etc blocks. As a result this version ofROUTINE
differs slightly from Sub::Current to match the behavior of__SUB__
.