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
use if - behaviour does not match documentation #16365
Comments
From @sisyphusHi, The documentation states: <quote> But the "use of => above provides necessary quoting of MODULE" only if: For example, on MS Windows with 5.27.7 and 5.26.0: ########################################## C:\>perl -Mstrict -le "use if 1, Digest::SHA => qw(sha1);" C:\>perl -Mstrict -le "use if 1, Non::Existent => qw(crap);" C:\>perl -Mstrict -le "use if 0, Non::Existent => qw(crap);" C:\> But if we quote any MODULE that contains any"::", then all works as ########################################## C:\>perl -Mstrict -le "use if 1, 'Non::Existent' => qw(crap);" C:\>perl -Mstrict -le "use if 0, 'Non::Existent' => qw(crap);" C:\> The problem goes away if we don't load strict.pm. If we don't want to mess with this behaviour of if.pm, then I think these ########################################## Inline Patch--- if.pm_orig 2018-01-17 12:11:48 +1100
+++ if.pm 2018-01-17 12:33:43 +1100
@@ -50,6 +50,10 @@
+NOTE: If strictures are enabled and C<MODULE> contains any use MODULE (); ########################################## Cheers, |
From @jkeenanOn Wed, 17 Jan 2018 02:57:55 GMT, sisyphus wrote:
1. I confirm your findings. 2. There are currently 10 unit tests in dist/if/t/if.t, all of which are run under 'no strict;'. If you duplicate those tests and run them under 'use strict;', 3 of the 10 immediately fail: 3. The problem appears to be specific to 'use strict "subs";'. The following DWIM: So the problem is not specific to use of the fat arrow. Indeed, the use of '=>' in the module's SYNOPSIS and DESCRIPTION is misleading. So if we revise the documentation, we should use commas rather than fat arrows. But perhaps we need more than just doc fixes. Thank you very much. -- |
The RT System itself - Status changed from 'new' to 'open' |
From @sisyphus-----Original Message-----
....
Yes, that's a better appraisal. So maybe the docs could just not mention the fat comma option, and specify
Perhaps - though I'd personally be quite happy with just a doc fix. Cheers, |
From @GrinnzOn Tue, Jan 23, 2018 at 6:38 PM, <sisyphus1@optusnet.com.au> wrote:
I think it would be better to have the docs show the module name in quotes -Dan |
From @jkeenanOn Wed, 24 Jan 2018 00:09:26 GMT, grinnz@gmail.com wrote:
Sounds good. I'll prepare a patch tomorrow. -- |
From @jkeenanOn Wed, 24 Jan 2018 03:39:01 GMT, jkeenan wrote:
This has proven to be trickier than I anticipated -- though not the documentation. I figured it would be a good idea to add tests for every claim made in the documentation. So I started to add tests to dist/if/t/if.t. (Got some advice on #p5p about this from ilmari, haarg and Abigail.) I wrote what I thought were some plausible tests for the 'no if CONDITION, MODULE => ARGUMENTS;' case only to discover that the 'no' did not appear to have any impact. See patch attached. When I run this against blead, I get: ##### ok 1 - "use if" with a false condition, fake pragma Test Summary Report ../dist/if/t/if.t (Wstat: 512 Tests: 16 Failed: 2) Can anyone advise on 'no if'? Thank you very much. -- |
From @jkeenan0001-Clarify-documentation-for-if-module.patchFrom 1bd4c7ee474965c923e3d6bc19c0b08bc6053701 Mon Sep 17 00:00:00 2001
From: James E Keenan <jkeenan@cpan.org>
Date: Tue, 23 Jan 2018 10:46:32 -0500
Subject: [PATCH] Clarify documentation for 'if' module.
Add tests for "strict 'subs'" -- but tests for 'no CONDITION' are not working.
---
dist/if/if.pm | 28 ++++++++++------------
dist/if/t/if.t | 73 ++++++++++++++++++++++++++++++++++++++++------------------
2 files changed, 63 insertions(+), 38 deletions(-)
diff --git a/dist/if/if.pm b/dist/if/if.pm
index d1cbd00..edc5a23 100644
--- a/dist/if/if.pm
+++ b/dist/if/if.pm
@@ -1,6 +1,6 @@
package if;
-$VERSION = '0.0607';
+$VERSION = '0.0608';
sub work {
my $method = shift() ? 'import' : 'unimport';
@@ -29,26 +29,22 @@ if - C<use> a Perl module if a condition holds (also can C<no> a module)
=head1 SYNOPSIS
- use if CONDITION, MODULE => ARGUMENTS;
- no if CONDITION, MODULE => ARGUMENTS;
+ use if CONDITION, "MODULE", ARGUMENTS;
+ no if CONDITION, "MODULE", ARGUMENTS;
=head1 DESCRIPTION
The C<if> module is used to conditionally load or unload another module.
The construct
- use if CONDITION, MODULE => ARGUMENTS;
+ use if CONDITION, "MODULE", ARGUMENTS;
-will load MODULE only if CONDITION evaluates to true.
-The above statement has no effect unless C<CONDITION> is true.
-If the CONDITION does evaluate to true, then the above line has
-the same effect as:
+will load MODULE only if CONDITION evaluates to true. The above statement has
+no effect unless C<CONDITION> is true. (The module name must be quoted when
+C<'use strict "subs";'> is in effect.) If the CONDITION does evaluate to true,
+then the above line has the same effect as:
- use MODULE ARGUMENTS;
-
-The use of C<< => >> above provides necessary quoting of C<MODULE>.
-If you don't use the fat comma (eg you don't have any ARGUMENTS),
-then you'll need to quote the MODULE.
+ use MODULE ARGUMENTS;
If you wanted ARGUMENTS to be an empty list, i.e. have the effect of:
@@ -63,7 +59,7 @@ exactly this effect, at compile time, with:
The following line is taken from the testsuite for L<File::Map>:
- use if $^O ne 'MSWin32', POSIX => qw/setlocale LC_ALL/;
+ use if $^O ne 'MSWin32', POSIX => qw/setlocale LC_ALL/;
If run on any operating system other than Windows,
this will import the functions C<setlocale> and C<LC_ALL> from L<POSIX>.
@@ -71,7 +67,7 @@ On Windows it does nothing.
The following is used to L<deprecate> core modules beyond a certain version of Perl:
- use if $] > 5.016, 'deprecate';
+ use if $] > 5.016, 'deprecate';
This line is taken from L<Text::Soundex> 3.04,
and marks it as deprecated beyond Perl 5.16.
@@ -85,7 +81,7 @@ unless you've installed a more recent version of L<Text::Soundex> from CPAN.
You can also specify to NOT use something:
- no if $] ge 5.021_006, warnings => "locale";
+ no if $] ge 5.021_006, warnings => "locale";
This warning category was added in the specified Perl version (a development
release). Without the C<'if'>, trying to use it in an earlier release would
diff --git a/dist/if/t/if.t b/dist/if/t/if.t
index 4a2b351..4854b7d 100644
--- a/dist/if/t/if.t
+++ b/dist/if/t/if.t
@@ -1,9 +1,9 @@
#!./perl
use strict;
-use Test::More tests => 10;
+use Test::More tests => 16;
-my $v_plus = $] + 1;
+my $v_plus = $] + 1;
my $v_minus = $] - 1;
unless (eval 'use open ":std"; 1') {
@@ -12,29 +12,58 @@ unless (eval 'use open ":std"; 1') {
eval 'sub open::foo{}'; # Just in case...
}
-no strict;
+{
+ no strict;
-is( eval "use if ($v_minus > \$]), strict => 'subs'; \${'f'} = 12", 12,
- '"use if" with a false condition, fake pragma');
-is( eval "use if ($v_minus > \$]), strict => 'refs'; \${'f'} = 12", 12,
- '"use if" with a false condition and a pragma');
+ is( eval "use if ($v_minus > \$]), strict => 'subs'; \${'f'} = 12", 12,
+ '"use if" with a false condition, fake pragma');
+ is( eval "use if ($v_minus > \$]), strict => 'refs'; \${'f'} = 12", 12,
+ '"use if" with a false condition and a pragma');
-is( eval "use if ($v_plus > \$]), strict => 'subs'; \${'f'} = 12", 12,
- '"use if" with a true condition, fake pragma');
+ is( eval "use if ($v_plus > \$]), strict => 'subs'; \${'f'} = 12", 12,
+ '"use if" with a true condition, fake pragma');
-is( eval "use if ($v_plus > \$]), strict => 'refs'; \${'f'} = 12", undef,
- '"use if" with a true condition and a pragma');
-like( $@, qr/while "strict refs" in use/, 'expected error message'),
+ is( eval "use if ($v_plus > \$]), strict => 'refs'; \${'f'} = 12", undef,
+ '"use if" with a true condition and a pragma');
+ like( $@, qr/while "strict refs" in use/, 'expected error message'),
-# Old version had problems with the module name 'open', which is a keyword too
-# Use 'open' =>, since pre-5.6.0 could interpret differently
-is( (eval "use if ($v_plus > \$]), 'open' => IN => ':crlf'; 12" || 0), 12,
- '"use if" with open');
+ # Old version had problems with the module name 'open', which is a keyword too
+ # Use 'open' =>, since pre-5.6.0 could interpret differently
+ is( (eval "use if ($v_plus > \$]), 'open' => IN => ':crlf'; 12" || 0), 12,
+ '"use if" with open');
-is(eval "use if ($v_plus > \$])", undef,
- "Too few args to 'use if' returns <undef>");
-like($@, qr/Too few arguments to 'use if'/, " ... and returns correct error");
+ is(eval "use if ($v_plus > \$])", undef,
+ "Too few args to 'use if' returns <undef>");
+ like($@, qr/Too few arguments to 'use if'/, " ... and returns correct error");
-is(eval "no if ($v_plus > \$])", undef,
- "Too few args to 'no if' returns <undef>");
-like($@, qr/Too few arguments to 'no if'/, " ... and returns correct error");
+ is(eval "no if ($v_plus > \$])", undef,
+ "Too few args to 'no if' returns <undef>");
+ like($@, qr/Too few arguments to 'no if'/, " ... and returns correct error");
+}
+
+{
+ note(q|RT 132732: strict 'subs'|);
+ use strict "subs";
+
+ {
+ eval "use if (0 > 1), q|bigrat|, qw(hex oct);";
+ ok (! bigrat->can('hex'), "Cannot hex");
+ ok (! bigrat->can('oct'), "Cannot oct");
+ print STDERR "AAA: ", hex("0x1234567890123490"),"\n";
+ }
+
+ {
+ eval "no if (1 > 0), q|bigrat|, qw(hex oct);";
+ ok (! bigrat->can('hex'), "Cannot hex");
+ ok (! bigrat->can('oct'), "Cannot oct");
+ print STDERR "BBB: ", hex("0x1234567890123490"),"\n";
+ }
+
+ {
+ eval "use if (1 > 0), q|bigrat|, qw(hex oct);";
+ ok (bigrat->can('hex'), "Can hex");
+ ok (bigrat->can('oct'), "Can oct");
+ print STDERR "CCC: ", hex("0x1234567890123490"),"\n";
+ }
+
+}
--
2.7.4
|
From @GrinnzFrom the source code, 'no if' appears to do the same thing as 'use if' but -Dan On Wed, Jan 24, 2018 at 11:02 AM, James E Keenan via RT <
|
From @jkeenanOn 01/24/2018 12:20 PM, Dan Book wrote:
So, would a proper test then be to import specific functions, then use jimk |
From @GrinnzOn Wed, Jan 24, 2018 at 12:33 PM, James E Keenan <jkeenan@pobox.com> wrote:
That should be reasonable, but note that not many modules implement -Dan |
From @jkeenanOn Wed, 24 Jan 2018 17:38:14 GMT, grinnz@gmail.com wrote:
Well, the reason I used bigrat in the tests is that it does contain a 'sub unimport'. As does 're'. But there I get even stranger results. Try this out (in the patch): ##### Which I read as, "Whether or not the CONDITION evaluates to true or not, the two functions are imported from package 're'." -- |
From @GrinnzOn Wed, Jan 24, 2018 at 1:09 PM, James E Keenan via RT <
This does not look like it's testing imports; it's testing whether the -Dan |
From @jkeenanOn Wed, 24 Jan 2018 18:16:40 GMT, grinnz@gmail.com wrote:
Noted. But please run the attached file. To the best of my understanding of the 'if' documentation, the tests in the third block of the file should pass, i.e., they should catch exceptions and set $@. They are not doing so? What are we missing? Thank you very much. -- |
From @jkeenan#!/usr/bin/env perl eval "use if (1 < 0), q|re|, qw(is_regexp regexp_pattern);"; local $@; eval "use if (0 < 1), q|re|, qw(is_regexp regexp_pattern);"; ($pat,$mods) = regexp_pattern($obj); eval "no if (0 < 1), q|re|, qw(is_regexp regexp_pattern);"; local $@; |
From @GrinnzOn Wed, Jan 24, 2018 at 3:12 PM, James E Keenan via RT <
The 'unimport' method (actually implemented in the 'bits' method) of re.pm -Dan |
From @jkeenanOn Wed, 24 Jan 2018 17:38:14 GMT, grinnz@gmail.com wrote:
There are many instances of the 'no' function in the source code, but very few instances of the string 'no if'. See attachment for output of 'ack '\bno\s+if\b' .'. Almost every instance is testing one of Perl's special variables against some value and, as you say, most are warnings-related. Unfortunately that isn't getting us any close to solving the problem. Is anyone familiar with where/how 'no' is implemented in the source code? Thank you very much. -- |
From @jkeenandist/IO/t/IO.t:52: no if $^V >= 5.17.4, warnings => "deprecated"; |
From @GrinnzOn Wed, Jan 24, 2018 at 4:18 PM, James E Keenan via RT <
'no' is the same as 'use' but it calls unimport instead of import. The -Dan |
From @sisyphus-----Original Message-----
I'm thinking 3 distinct cases: 1) You want to load a module unconditionally ('use MODULE;') 2) You want to load a module conditionally ('use if CONDITION, MODULE, 3) Having loaded a module, you then wish to conditionally remove specific As an example, 'no if' seems to work fine with warnings.pm: ### 1 ### Outputs: Name "main::z" used only once: possible typo at try.pl line 5. If we change the condition to 'no if 1', then the output is the same, except Similarly, with strict.pm, the following works fine, outputting "DONE": use strict; That would blow up at compile time if strict "subs" was enabled - which is But the same doesn't happen with re, as James has discovered. use re; simply outputs "DONE" instead of throwing an error. Is the difference that (wrt re.pm), we're actually explicitly calling a Cheers, |
From @GrinnzOn Wed, Jan 24, 2018 at 8:42 PM, <sisyphus1@optusnet.com.au> wrote:
As I explained before, the difference is that the 'unimport' method for I believe the question was about implementation of 'no' itself, but for use no autovivification; So one could conceive of a case where you'd want to conditionally -Dan |
From @AbigailOn Wed, Jan 24, 2018 at 10:09:56AM -0800, James E Keenan via RT wrote:
That code checks whether the class 're' has a subroutine 'is_regexp' -- To check whether it has been imported, you need to call "can" on the ##### Assuming your code runs in the main package. Abigail |
From @jkeenanOn Thu, 25 Jan 2018 11:29:38 GMT, abigail@abigail.be wrote:
Thanks for the suggestion. I believe I now have better documentation and testing of 'if'. Please review the new patch attached, 132732-0001-if-module-clarify-documentation-and-test-more-thorou.patch. Thank you very much. -- |
From @jkeenan132732-0001-if-module-clarify-documentation-and-test-more-thorou.patchFrom e202bfb954217349f5e61bddbb92ba10021ea242 Mon Sep 17 00:00:00 2001
From: James E Keenan <jkeenan@cpan.org>
Date: Tue, 23 Jan 2018 10:46:32 -0500
Subject: [PATCH] 'if' module: clarify documentation and test more thoroughly.
The documentation for 'if' made certain claims about the need to quote or not
quote a module name preceding a "fat arrow" ('=>') operator. These claims
were shown to be unfounded in most cases when "use strict 'subs'" was in
effect.
In the course of writing better documentation, it was observed that the "no
if" case was very under-tested, poorly documented and hence poorly understood.
Hence, more tests have been added and the documentation has been extensively
revised. However, there have been no changes in source code or functionality.
Make porting/podcheck.t happy. Compensate for functions not available on
older perls.
For: RT # 132732.
---
dist/if/if.pm | 84 ++++++++++++++++++++++--------------------------
dist/if/t/if.t | 100 ++++++++++++++++++++++++++++++++++++++++++++-------------
2 files changed, 117 insertions(+), 67 deletions(-)
diff --git a/dist/if/if.pm b/dist/if/if.pm
index d1cbd00..23ba642 100644
--- a/dist/if/if.pm
+++ b/dist/if/if.pm
@@ -1,6 +1,6 @@
package if;
-$VERSION = '0.0607';
+$VERSION = '0.0608';
sub work {
my $method = shift() ? 'import' : 'unimport';
@@ -25,76 +25,70 @@ __END__
=head1 NAME
-if - C<use> a Perl module if a condition holds (also can C<no> a module)
+if - C<use> a Perl module if a condition holds
=head1 SYNOPSIS
- use if CONDITION, MODULE => ARGUMENTS;
- no if CONDITION, MODULE => ARGUMENTS;
+ use if CONDITION, "MODULE", ARGUMENTS;
+ no if CONDITION, "MODULE", ARGUMENTS;
=head1 DESCRIPTION
-The C<if> module is used to conditionally load or unload another module.
-The construct
+=head2 C<use if>
- use if CONDITION, MODULE => ARGUMENTS;
+The C<if> module is used to conditionally load another module. The construct:
-will load MODULE only if CONDITION evaluates to true.
-The above statement has no effect unless C<CONDITION> is true.
-If the CONDITION does evaluate to true, then the above line has
-the same effect as:
+ use if CONDITION, "MODULE", ARGUMENTS;
- use MODULE ARGUMENTS;
+... will load C<MODULE> only if C<CONDITION> evaluates to true; it has no
+effect if C<CONDITION> evaluates to false. (The module name, assuming it
+contains at least one C<::>, must be quoted when C<'use strict "subs";'> is in
+effect.) If the CONDITION does evaluate to true, then the above line has the
+same effect as:
-The use of C<< => >> above provides necessary quoting of C<MODULE>.
-If you don't use the fat comma (eg you don't have any ARGUMENTS),
-then you'll need to quote the MODULE.
+ use MODULE ARGUMENTS;
-If you wanted ARGUMENTS to be an empty list, i.e. have the effect of:
+For example, the F<Unicode::UCD> module's F<charinfo> function will use two functions from F<Unicode::Normalize> only if a certain condition is met:
+
+ use if defined &DynaLoader::boot_DynaLoader,
+ "Unicode::Normalize" => qw(getCombinClass NFD);
+
+Suppose you wanted C<ARGUMENTS> to be an empty list, I<i.e.>, to have the
+effect of:
use MODULE ();
-you can't do this with the C<if> pragma; however, you can achieve
+You can't do this with the C<if> pragma; however, you can achieve
exactly this effect, at compile time, with:
BEGIN { require MODULE if CONDITION }
-=head2 EXAMPLES
-
-The following line is taken from the testsuite for L<File::Map>:
-
- use if $^O ne 'MSWin32', POSIX => qw/setlocale LC_ALL/;
-
-If run on any operating system other than Windows,
-this will import the functions C<setlocale> and C<LC_ALL> from L<POSIX>.
-On Windows it does nothing.
-
-The following is used to L<deprecate> core modules beyond a certain version of Perl:
+=head2 C<no if>
- use if $] > 5.016, 'deprecate';
+The C<no if> construct is mainly used to deactivate categories of warnings
+when those categories would produce superfluous output under specified
+versions of F<perl>.
-This line is taken from L<Text::Soundex> 3.04,
-and marks it as deprecated beyond Perl 5.16.
-If you C<use Text::Soundex> in Perl 5.18, for example,
-and you have used L<warnings>,
-then you'll get a warning message
-(the deprecate module looks to see whether the
-calling module was C<use>'d from a core library directory,
-and if so, generates a warning),
-unless you've installed a more recent version of L<Text::Soundex> from CPAN.
+For example, the C<redundant> category of warnings was introduced in
+Perl-5.22. This warning flags certain instances of superfluous arguments to
+C<printf> and C<sprintf>. But if your code was running warnings-free on
+earlier versions of F<perl> and you don't care about C<redundant> warnings in
+more recent versions, you can call:
-You can also specify to NOT use something:
+ use warnings;
+ no if $] >= 5.022, q|warnings|, qw(redundant);
- no if $] ge 5.021_006, warnings => "locale";
+ my $test = { fmt => "%s", args => [ qw( x y ) ] };
+ my $result = sprintf $test->{fmt}, @{$test->{args}};
-This warning category was added in the specified Perl version (a development
-release). Without the C<'if'>, trying to use it in an earlier release would
-generate an unknown warning category error.
+The C<no if> construct assumes that a module or pragma has correctly
+implemented an C<unimport()> method -- but most modules and pragmata have not.
+That explains why the C<no if> construct is of limited applicability.
=head1 BUGS
-The current implementation does not allow specification of the
-required version of the module.
+The current implementation does not allow specification of the required
+version of the module.
=head1 SEE ALSO
diff --git a/dist/if/t/if.t b/dist/if/t/if.t
index 4a2b351..827d93c 100644
--- a/dist/if/t/if.t
+++ b/dist/if/t/if.t
@@ -1,9 +1,9 @@
#!./perl
use strict;
-use Test::More tests => 10;
+use Test::More tests => 18;
-my $v_plus = $] + 1;
+my $v_plus = $] + 1;
my $v_minus = $] - 1;
unless (eval 'use open ":std"; 1') {
@@ -12,29 +12,85 @@ unless (eval 'use open ":std"; 1') {
eval 'sub open::foo{}'; # Just in case...
}
-no strict;
+{
+ no strict;
-is( eval "use if ($v_minus > \$]), strict => 'subs'; \${'f'} = 12", 12,
- '"use if" with a false condition, fake pragma');
-is( eval "use if ($v_minus > \$]), strict => 'refs'; \${'f'} = 12", 12,
- '"use if" with a false condition and a pragma');
+ is( eval "use if ($v_minus > \$]), strict => 'subs'; \${'f'} = 12", 12,
+ '"use if" with a false condition, fake pragma');
+ is( eval "use if ($v_minus > \$]), strict => 'refs'; \${'f'} = 12", 12,
+ '"use if" with a false condition and a pragma');
-is( eval "use if ($v_plus > \$]), strict => 'subs'; \${'f'} = 12", 12,
- '"use if" with a true condition, fake pragma');
+ is( eval "use if ($v_plus > \$]), strict => 'subs'; \${'f'} = 12", 12,
+ '"use if" with a true condition, fake pragma');
-is( eval "use if ($v_plus > \$]), strict => 'refs'; \${'f'} = 12", undef,
- '"use if" with a true condition and a pragma');
-like( $@, qr/while "strict refs" in use/, 'expected error message'),
+ is( eval "use if ($v_plus > \$]), strict => 'refs'; \${'f'} = 12", undef,
+ '"use if" with a true condition and a pragma');
+ like( $@, qr/while "strict refs" in use/, 'expected error message'),
-# Old version had problems with the module name 'open', which is a keyword too
-# Use 'open' =>, since pre-5.6.0 could interpret differently
-is( (eval "use if ($v_plus > \$]), 'open' => IN => ':crlf'; 12" || 0), 12,
- '"use if" with open');
+ # Old version had problems with the module name 'open', which is a keyword too
+ # Use 'open' =>, since pre-5.6.0 could interpret differently
+ is( (eval "use if ($v_plus > \$]), 'open' => IN => ':crlf'; 12" || 0), 12,
+ '"use if" with open');
-is(eval "use if ($v_plus > \$])", undef,
- "Too few args to 'use if' returns <undef>");
-like($@, qr/Too few arguments to 'use if'/, " ... and returns correct error");
+ is(eval "use if ($v_plus > \$])", undef,
+ "Too few args to 'use if' returns <undef>");
+ like($@, qr/Too few arguments to 'use if'/, " ... and returns correct error");
-is(eval "no if ($v_plus > \$])", undef,
- "Too few args to 'no if' returns <undef>");
-like($@, qr/Too few arguments to 'no if'/, " ... and returns correct error");
+ is(eval "no if ($v_plus > \$])", undef,
+ "Too few args to 'no if' returns <undef>");
+ like($@, qr/Too few arguments to 'no if'/, " ... and returns correct error");
+}
+
+{
+ note(q|RT 132732: strict 'subs'|);
+ use strict "subs";
+
+ {
+ SKIP: {
+ unless ($] >= 5.018) {
+ skip "bigrat apparently not testable prior to perl-5.18", 4;
+ }
+ note(q|strict "subs" : 'use if' : condition false|);
+ eval "use if (0 > 1), q|bigrat|, qw(hex oct);";
+ ok (! main->can('hex'), "Cannot call bigrat::hex() in importing package");
+ ok (! main->can('oct'), "Cannot call bigrat::oct() in importing package");
+
+ note(q|strict "subs" : 'use if' : condition true|);
+ eval "use if (1 > 0), q|bigrat|, qw(hex oct);";
+ ok ( main->can('hex'), "Can call bigrat::hex() in importing package");
+ ok ( main->can('oct'), "Can call bigrat::oct() in importing package");
+ }
+ }
+
+ {
+ note(q|strict "subs" : 'no if' : condition variable|);
+ note(($] >= 5.022) ? "Recent enough Perl: $]" : "Older Perl: $]");
+ use warnings;
+ SKIP: {
+ unless ($] >= 5.022) {
+ skip "Redundant argument warning not available in pre-5.22 perls", 4;
+ }
+
+ {
+ no if $] >= 5.022, q|warnings|, qw(redundant);
+ my ($test, $result, $warn);
+ local $SIG{__WARN__} = sub { $warn = shift };
+ $test = { fmt => "%s", args => [ qw( x y ) ] };
+ $result = sprintf $test->{fmt}, @{$test->{args}};
+ is($result, $test->{args}->[0], "Got expected string");
+ ok(! $warn, "Redundant argument warning suppressed");
+ }
+
+ {
+ use if $] >= 5.022, q|warnings|, qw(redundant);
+ my ($test, $result, $warn);
+ local $SIG{__WARN__} = sub { $warn = shift };
+ $test = { fmt => "%s", args => [ qw( x y ) ] };
+ $result = sprintf $test->{fmt}, @{$test->{args}};
+ is($result, $test->{args}->[0], "Got expected string");
+ like($warn, qr/Redundant argument in sprintf/,
+ "Redundant argument warning generated and capture");
+ }
+ }
+ }
+}
--
2.7.4
|
From @jkeenanOn Fri, 26 Jan 2018 02:07:55 GMT, jkeenan wrote:
I plan to apply the patch on Thu, Feb 01 unless there is objection. Thank you very much. |
From @sisyphus-----Original Message----- .....
Jim, That all looks pretty good to me, and tests fine. The last paragraph in the "SEE ALSO" section of the POD (which pre-dates provide can be used to select one of several possible modules to load, Probably not so confusing if you know that there's a module named Maybe something like: Also, the end of the sentence ("based on what version of Perl is running") Thanks for being thorough ... and for doing all the work. Cheers, |
From @jkeenanOn Tue, 30 Jan 2018 04:25:40 GMT, sisyphus wrote:
Pushed to blead in 1654584 with some documentation touch-ups as suggested by Rob. Thank you very much. -- |
@jkeenan - Status changed from 'open' to 'pending release' |
From @khwilliamsonThank you for filing this report. You have helped make Perl better. With the release yesterday of Perl 5.28.0, this and 185 other issues have been Perl 5.28.0 may be downloaded via: If you find that the problem persists, feel free to reopen this ticket. |
@khwilliamson - Status changed from 'pending release' to 'resolved' |
Migrated from rt.perl.org#132732 (status was 'resolved')
Searchable as RT132732$
The text was updated successfully, but these errors were encountered: