develooper Front page | perl.perl5.porters | Postings from January 2018

[perl #132732] use if - behaviour does not match documentation

Thread Next
From:
James E Keenan via RT
Date:
January 23, 2018 15:45
Subject:
[perl #132732] use if - behaviour does not match documentation
Message ID:
rt-4.0.24-7040-1516722340-432.132732-15-0@perl.org
On Wed, 17 Jan 2018 02:57:55 GMT, sisyphus wrote:
> Hi,
> 
> The documentation states:
> 
> <quote>
> The use of => above provides necessary quoting of MODULE . If you don't use 
> the fat comma (eg you don't have any ARGUMENTS), then you'll need to quote 
> the MODULE.
> </quote>
> 
> But the "use of => above provides necessary quoting of MODULE" only if:
> 1) strictures are not enabled
> &&
> 2) MODULE does not contain any occurrences of "::".
> 
> For example, on MS Windows with 5.27.7 and 5.26.0:
> 
> ##########################################
> C:\>perl -Mstrict -le "use if 1, POSIX => qw(DBL_MAX);"
> 
> C:\>perl -Mstrict -le "use if 1, Digest::SHA => qw(sha1);"
> Bareword "Digest::SHA" not allowed while "strict subs" in use at -e line 1.
> Execution of -e aborted due to compilation errors.
> 
> C:\>perl -Mstrict -le "use if 1, Non::Existent => qw(crap);"
> Bareword "Non::Existent" not allowed while "strict subs" in use at -e line 
> 1.
> Execution of -e aborted due to compilation errors.
> 
> C:\>perl -Mstrict -le "use if 0, Non::Existent => qw(crap);"
> Bareword "Non::Existent" not allowed while "strict subs" in use at -e line 
> 1.
> Execution of -e aborted due to compilation errors.
> 
> C:\>
> ##########################################
> 
> But if we quote any MODULE that contains any"::", then all works as 
> expected:
> 
> ##########################################
> C:\>perl -Mstrict -le "use if 1, 'Digest::SHA' => qw(sha1);"
> 
> C:\>perl -Mstrict -le "use if 1, 'Non::Existent' => qw(crap);"
> Can't locate Non/Existent.pm in @INC (you may need to install the 
> Non::Existent
> module) (@INC contains: C:/_64/blead-5.27.7/site/lib 
> C:/_64/blead-5.27.7/lib) at
> C:/_64/blead-5.27.7/lib/if.pm line 15.
> BEGIN failed--compilation aborted at -e line 1.
> 
> C:\>perl -Mstrict -le "use if 0, 'Non::Existent' => qw(crap);"
> 
> C:\>
> ##########################################
> 
> The problem goes away if we don't load strict.pm.
> Also, deferring the loading od strict.pm until after *all* "use if ..." 
> statements have been made removes the problem.
> 
> If we don't want to mess with this behaviour of if.pm, then I think these 
> caveats involving if.pm should be documented eg:
> 
> ##########################################
> --- if.pm_orig  2018-01-17 12:11:48 +1100
> +++ if.pm       2018-01-17 12:33:43 +1100
> @@ -50,6 +50,10 @@
> If you don't use the fat comma (eg you don't have any ARGUMENTS),
> then you'll need to quote the MODULE.
> 
> +NOTE: If strictures are enabled and  C<MODULE> contains any
> +occurrences of C<< :: >> then you'll need to quote the MODULE, even
> +if you have used the fat comma.
> +
> If you wanted ARGUMENTS to be an empty list, i.e. have the effect of:
> 
>      use MODULE ();
> 
> ##########################################
> 
> Cheers,
> Rob 

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:
#####
not ok 11 - "use if" with a false condition, fake pragma
#   Failed test '"use if" with a false condition, fake pragma'
#   at t/if.t line 47.
#          got: undef
#     expected: '12'
not ok 12 - "use if" with a false condition and a pragma
#   Failed test '"use if" with a false condition and a pragma'
#   at t/if.t line 49.
#          got: undef
#     expected: '12'
not ok 13 - "use if" with a true condition, fake pragma
#   Failed test '"use if" with a true condition, fake pragma'
#   at t/if.t line 52.
#          got: undef
#     expected: '12'
#####

3. The problem appears to be specific to 'use strict "subs";'.  The following DWIM:
#####
use strict;
no strict "subs";
use if 1, POSIX => qw(:errno_h :fcntl_h);
use if 1, Digest::SHA => qw(sha1);
use if 1, Non::Existent, qw(foo);
#####
use strict;
no strict "subs";
use if 1, POSIX, qw(:errno_h :fcntl_h);
use if 1, Digest::SHA, qw(sha1);
use if 1, Non::Existent, qw(foo);
#####

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.

-- 
James E Keenan (jkeenan@cpan.org)

---
via perlbug:  queue: perl5 status: new
https://rt.perl.org/Ticket/Display.html?id=132732

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About