Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

jberger
Copy link

@jberger jberger commented Jun 6, 2016

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__ and Sub::Current::ROUTINE is the behavior inside the BEGIN/END/etc blocks. As a result this version of ROUTINE differs slightly from Sub::Current to match the behavior of __SUB__.

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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should check against $], not $^V.

Copy link
Member

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 $]

@jberger
Copy link
Author

jberger commented Jun 6, 2016

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.

Copy link
Member

@atoomic atoomic left a 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.

@jberger
Copy link
Author

jberger commented Aug 11, 2020

Is it as simple as changing the variable? Do I also have to change the comparison?

@Grinnz
Copy link
Contributor

Grinnz commented Aug 11, 2020

No, it is already comparing against the right decimal number.

@jberger
Copy link
Author

jberger commented Aug 11, 2020

This branch is very stale but locally a rebased version passes tests. Any opposition to me force-pushing the rebased version?

@atoomic
Copy link
Member

atoomic commented Aug 11, 2020

I would say rebase && force push. The CI will confirm how it stands with the various Perl version
Note: we are currently using Travis CI, but I've provided a quick and fast alternate addition using GH CI as #110

@jberger
Copy link
Author

jberger commented Aug 12, 2020

OK so it fails on 5.6. Is that fixable? Is it allowable?

@atoomic
Copy link
Member

atoomic commented Aug 12, 2020

@jberger the problem comes from Perl_find_runcv, when running ppport.h
we can see that this is not portable before 5.8.1

*** WARNING: Uses find_runcv, which may not be portable below perl 5.8.1, even with 'ppport.h'

So I came with a poor man alternate with an additional commit to provide it when missing, and it seems to work...
the alternate is to drop the support below 5.6

view commit:
atoomic@c74c017

view CI proof of concept:
https://github.com/atoomic/Scalar-List-Utils/actions/runs/205763453

So cherry picking this commit to your branch should fix your concern.

@jberger
Copy link
Author

jberger commented Aug 12, 2020

@jberger the problem comes from Perl_find_runcv, when running ppport.h
we can see that this is not portable before 5.8.1
[SNIP]
So I came with a poor man alternate with an additional commit to provide it when missing, and it seems to work...
the alternate is to drop the support below 5.6
[SNIP]
So cherry picking this commit to your branch should fix your concern.

That's beyond my power to evaluate. @leonerd thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants