Front page | perl.perl5.porters |
Postings from January 2018
[perl #132732] use if - behaviour does not match documentation
Thread Previous
|
Thread Next
From:
James E Keenan via RT
Date:
January 24, 2018 16:02
Subject:
[perl #132732] use if - behaviour does not match documentation
Message ID:
rt-4.0.24-22716-1516809729-1356.132732-15-0@perl.org
On Wed, 24 Jan 2018 03:39:01 GMT, jkeenan wrote:
> On Wed, 24 Jan 2018 00:09:26 GMT, grinnz@gmail.com wrote:
> > On Tue, Jan 23, 2018 at 6:38 PM, <sisyphus1@optusnet.com.au> wrote:
> >
> > >
> > >
> > > -----Original Message----- From: James E Keenan via RT
> > > Sent: Wednesday, January 24, 2018 2:45 AM
> > > To: OtherRecipients of perl Ticket #132732:
> > > Cc: perl5-porters@perl.org
> > > Subject: [perl #132732] use if - behaviour does not match
> > > documentation
> > >
> > > 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 "::".
> > >>>
> > >>
> > > ....
> > >
> > > 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.
> > >>
> > >
> > > Yes, that's a better appraisal.
> > > It seems the only time the fat arrow helps is when strict "subs" is
> > > enabled - as it then allows 'use if 1, POSIX => qw(:errno_h
> > > :fcntl_h);' to
> > > work.
> > >
> > > So maybe the docs could just not mention the fat comma option, and
> > > specify
> > > that the module name needs to be placed in quotes if strict "subs" is
> > > enabled.
> > > And then we just wait for someone to point out that you don't
> > > actually need
> > > to quote the module name when strict subs are enabled, so long as you
> > > use
> > > the fat comma && the module name doesn't contain "::" ;-)
> > >
> > > But perhaps we need more than just doc fixes.
> > >>
> > >
> > > Perhaps - though I'd personally be quite happy with just a doc fix.
> > >
> > > Cheers,
> > > Rob
> >
> >
> > I think it would be better to have the docs show the module name in
> > quotes
> > every time. Use of the fat comma vs a regular comma is then just a
> > stylistic choice, and we are showing strict-safe examples as we
> > should.
> >
> > -Dan
>
> Sounds good. I'll prepare a patch tomorrow.
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:
#####
$ cd t;./perl harness -v ../dist/if/t/if.t; cd -
ok 1 - "use if" with a false condition, fake pragma
ok 2 - "use if" with a false condition and a pragma
ok 3 - "use if" with a true condition, fake pragma
ok 4 - "use if" with a true condition and a pragma
ok 5 - expected error message
ok 6 - "use if" with open
ok 7 - Too few args to 'use if' returns <undef>
ok 8 - ... and returns correct error
ok 9 - Too few args to 'no if' returns <undef>
ok 10 - ... and returns correct error
AAA: 1311768467284833424
ok 11 - Cannot hex
ok 12 - Cannot oct
not ok 13 - Cannot hex
# Failed test 'Cannot hex'
# at t/if.t line 57.
not ok 14 - Cannot oct
# Failed test 'Cannot oct'
# at t/if.t line 58.
BBB: 1311768467284833424
CCC: 1311768467284833424
ok 15 - Can hex
# Looks like you failed 2 tests of 16.
ok 16 - Can oct
Dubious, test returned 2 (wstat 512, 0x200)
Failed 2/16 subtests
Test Summary Report
-------------------
../dist/if/t/if.t (Wstat: 512 Tests: 16 Failed: 2)
Failed tests: 13-14
Non-zero exit status: 2
Files=1, Tests=16, 0 wallclock secs ( 0.01 usr 0.00 sys + 0.08 cusr 0.00 csys = 0.09 CPU)
Result: FAIL
#####
Can anyone advise on 'no if'?
Thank you very much.
--
James E Keenan (jkeenan@cpan.org)
---
via perlbug: queue: perl5 status: open
https://rt.perl.org/Ticket/Display.html?id=132732
Thread Previous
|
Thread Next