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

Smartmatch is deprecated #35

Open
johannessen opened this issue Feb 27, 2023 · 1 comment
Open

Smartmatch is deprecated #35

johannessen opened this issue Feb 27, 2023 · 1 comment

Comments

@johannessen
Copy link
Collaborator

I’m not sure if you’re aware of the long-standing efforts to remove the smartmatch feature from Perl. Perl v5.37.10 will finally start to issue deprecation warnings for it. Testing Neo4p in Perl blead today yields the following:

given is deprecated at lib/REST/Neo4p/Agent.pm line 214.
when is deprecated at lib/REST/Neo4p/Agent.pm line 215.
when is deprecated at lib/REST/Neo4p/Agent.pm line 239.
given is deprecated at lib/REST/Neo4p/Agent.pm line 276.
when is deprecated at lib/REST/Neo4p/Agent.pm line 277.
when is deprecated at lib/REST/Neo4p/Agent.pm line 280.
given is deprecated at lib/REST/Neo4p/ParseStream.pm line 32.
when is deprecated at lib/REST/Neo4p/ParseStream.pm line 33.
when is deprecated at lib/REST/Neo4p/ParseStream.pm line 36.
given is deprecated at lib/REST/Neo4p/ParseStream.pm line 152.
when is deprecated at lib/REST/Neo4p/ParseStream.pm line 153.
when is deprecated at lib/REST/Neo4p/ParseStream.pm line 160.
when is deprecated at lib/REST/Neo4p/ParseStream.pm line 165.
when is deprecated at lib/REST/Neo4p/ParseStream.pm line 172.
when is deprecated at lib/REST/Neo4p/ParseStream.pm line 181.
when is deprecated at lib/REST/Neo4p/ParseStream.pm line 195.
when is deprecated at lib/REST/Neo4p/ParseStream.pm line 205.
when is deprecated at lib/REST/Neo4p/ParseStream.pm line 227.
given is deprecated at lib/REST/Neo4p/Batch.pm line 46.
when is deprecated at lib/REST/Neo4p/Batch.pm line 47.
when is deprecated at lib/REST/Neo4p/Batch.pm line 67.
when is deprecated at lib/REST/Neo4p/Batch.pm line 71.

The test suite still seems to pass though. So, no immediate action is required. But the current plan is to remove the feature entirely with Perl v5.42 in 2025.

Good old if/elsif/else chains are a possible replacement. for blocks can sometimes be useful as a direct replacement for given, although next will behave differently inside of them. There are also a number of CPAN modules that offer C-style switch/case syntax, of which Syntax::Keyword::Match might be one of the more interesting, in spite of it currently being experimental.

@johannessen
Copy link
Collaborator Author

I actually have a working patch ready that would remove the use of smartmatch from REST::Neo4p, replacing it with Switch::Back. It’s really simple, basically just does this in a handful of files:

-  use experimental 'smartmatch';
+  use if $^V lt v5.41, experimental => 'smartmatch';
+  use if $^V ge v5.41, 'Switch::Back';

However, P5P are currently working to revert the smartmatch deprecation altogether. So it doesn’t look like we’ll be needing that patch.

There are still the warnings on Perl v5.38 and v5.40 to address though.

johannessen added a commit to johannessen/rest-neo4p that referenced this issue Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant