tobyink / p5-match-simple

Perl 5 distribution match-simple; see homepage for downloads and documentation.
https://metacpan.org/release/match-simple
4 stars 3 forks source link

sugar "when" conflicts with feature "switch" #5

Open damil opened 8 months ago

damil commented 8 months ago

Hi Toby,

I 've been using match::simple for quite a while, but I just discovered the ::sugar addition, which is a very nice idea.

However, it stops working as soon as we add a "use v5.30.0" (or other Perl versions) , because this implicitly activates the feature "switch" , resulting in compile-time errors because of the keyword 'when' :

when is experimental at d:/temp/foo.pl line 16
..
syntax error at d:/temp/foo.pl line 16, near "when numeric "

The workaround is to say "no feature 'switch'" ... but if possible, ::sugar should do it automatically.

Thanks for your very useful modules.

tobyink commented 6 months ago

The when and then functions are intended as a replacement for Perl's deprecated given/when, so the idea is you wouldn't want them both in the same scope.

Yes, match::simple::sugar could disable given/when for you, but I'd rather end users consciously did it themselves so it's obvious what's happening.

use v5.42 should automatically disable given/when, except that Perl 5.42 isn't quite out yet.

n1vux commented 2 months ago

right. But if either running older Perl versions that know of the deprecation, or even with running perl v5.40 with use v5.34; or lower, it is true that one must

no feature 'switch';  # or use v5.36; or greater 

or it will complain that use of match::simple::sugar's when is deprecated, and since syntax isn't exactly the same, it will then fail to compile the script using the sugary when expr, then{…};.

when is deprecated at lib/MyGed/GrampsGedReader.pm line 171.
syntax error at lib/MyGed/GrampsGedReader.pm line 171, near "when 'none'"
Execution of lib/MyGed/GrampsGedReader.pm aborted due to compilation errors.
Compilation failed in require.
BEGIN failed--compilation aborted.

This is at a minimum a useful lesson-learned for Documentation ,

But if $^V < v5.36, it would be sugary DWIM for the sugar module to do the no features 'switch'; .