Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Perl-Critic CPAN distribution.

Report information
The Basics
Id: 68364
Status: open
Priority: 0/
Queue: Perl-Critic

People
Owner: Nobody in particular
Requestors: user42 [...] zip.com.au
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: RequireLocalizedPunctuationVars exempt $?
Date: Sun, 22 May 2011 09:08:58 +1000
To: bug-Perl-Critic [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
In the current cvs, running perlcritic -s RequireLocalizedPunctuationVars on END { $? = 13; } gives Magic variable "$?" should be assigned as "local" $? = 13; Where I hoped that it would recognise an assignment to $? in an END block is normal and specifically recommended in perlvar.pod. I would go further and exempt $? completely, no matter where assigned. It's an "output" variable, set by backticks etc, and anyone assigning is probably establishing a value in that style for the caller to look at. For example IPC::Run or Capture::Tiny, and even something in Test::Builder finalize() maybe.
Subject: Re: [rt.cpan.org #68364] RequireLocalizedPunctuationVars exempt $?
Date: Sun, 22 May 2011 12:23:06 -0500
To: bug-Perl-Critic [...] rt.cpan.org
From: Elliot Shank <perl [...] galumph.com>
On 5/21/11 6:08 PM, Kevin Ryde via RT wrote: Show quoted text
> I would go further and exempt $? completely, no matter where assigned. > It's an "output" variable, set by backticks etc, and anyone assigning is > probably establishing a value in that style for the caller to look at.
I disagree. Show quoted text
> For example IPC::Run or Capture::Tiny, and even something in > Test::Builder finalize() maybe.
Those sorts of modules are exceptions and not "normal" code. RequireUseStrict is something that should be on for 99% of code, but for something that's sole purpose is to go dancing over the symbol tables, I think that it's perfectly valid for the distribution to entirely turn the policy off. It doesn't mean that the policy shouldn't apply by default.
Subject: Re: [rt.cpan.org #68364] RequireLocalizedPunctuationVars exempt $?
Date: Tue, 24 May 2011 08:14:33 +1000
To: bug-Perl-Critic [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
"Elliot Shank via RT" <bug-Perl-Critic@rt.cpan.org> writes: Show quoted text
>
>> For example IPC::Run or Capture::Tiny, and even something in >> Test::Builder finalize() maybe.
> > Those sorts of modules are exceptions and not "normal" code.
I don't think there's any other reason to assign outside an END block ... which makes those uses the normal ones.
Subject: Re: [rt.cpan.org #68364] RequireLocalizedPunctuationVars exempt $?
Date: Mon, 23 May 2011 16:40:49 -0700
To: bug-Perl-Critic [...] rt.cpan.org
From: Jeffrey Thalhammer <jeff [...] imaginative-software.com>
On May 22, 2011, at 10:23 AM, Elliot Shank via RT wrote: Show quoted text
>> I would go further and exempt $? completely, no matter where assigned. >> It's an "output" variable, set by backticks etc, and anyone assigning is >> probably establishing a value in that style for the caller to look at.
The key word there is "probably." In my humble opinion, part of Perl::Critic's role is to clarify the author's intent in cases where it may be ambiguous or unconventional. If you are coming from the belief that all other punctuation vars should be localized, and then you see that $? isn't localized, you have to stop and wonder why. To some, it may be obvious. But to most, it probably isn't. So if I were to assign to $? without localizing, then I think it should get some kind of comment to explain it. Now, Perl::Critic can't enforce comments, but the next best thing is a "## no critic" annotation. So I tend to agree with Elliot on this one. Jeffrey Thalhammer Imaginative Software Systems vcard: http://www.imaginative-software.com/contact/jeff.vcf
Subject: Re: [rt.cpan.org #68364] RequireLocalizedPunctuationVars exempt $?
Date: Tue, 24 May 2011 10:24:35 +1000
To: bug-Perl-Critic [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
"Jeffrey Thalhammer via RT" <bug-Perl-Critic@rt.cpan.org> writes: Show quoted text
> > all other punctuation vars
I think they're not all the same. They're globals, but when and for how long a given global should be assigned (if at all!) bears some thought. I know the motivation is the input-ish ones like $, but not all quite so simple.
Subject: Re: [rt.cpan.org #68364] RequireLocalizedPunctuationVars exempt $?
Date: Mon, 23 May 2011 18:17:33 -0700
To: bug-Perl-Critic [...] rt.cpan.org
From: Jeffrey Thalhammer <jeff [...] imaginative-software.com>
On May 23, 2011, at 5:24 PM, Kevin Ryde via RT wrote: Show quoted text
> I think they're not all the same.
Ok. I see this Policy allows you to configure your own exemptions: CONFIGURATION You can configure your own exemptions using the "allow" option: [Variables::RequireLocalizedPunctuationVars] allow = @ARGV $ARGV These are added to the default exemptions. So you're free to decide which vars to exempt. But $? will not be exempt by default. At most, I might mention it in the documentation as a possible candidate for exemption, based on the reasoning you've given. Will that do? -Jeff
Subject: Re: [rt.cpan.org #68364] RequireLocalizedPunctuationVars exempt $?
Date: Tue, 24 May 2011 12:03:34 +1000
To: bug-Perl-Critic [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
"Jeffrey Thalhammer via RT" <bug-Perl-Critic@rt.cpan.org> writes: Show quoted text
> > I might mention it in the documentation
Then also for that docs its raw-er friend ${^CHILD_ERROR_NATIVE}. And $@, $! and $^E can be sensibly assigned to return something to the caller. $| quite often for turning on handle flushing (where local occasionally might make sense too). $0 of ticket 65513 looks a reasonable toplevel mangle. And $<, $>, $(, $) for dropping privileges (where a local might not work at all to get back previous privilege). I expect a couple of words about the nature of the many vars could broadly class them as side-effecting stuff like $/ vs mostly outputs like $@ vs aliases to process-wide system features, or somewhere in between. Show quoted text
> as a possible > candidate for exemption,
Do the END block bit at least. If anyone actually obeyed the violation I first reported then their code would not work. It can't be good to report as a violation something perlvar.pod specifically says to do.
Subject: Re: [rt.cpan.org #68364] RequireLocalizedPunctuationVars exempt $?
Date: Mon, 23 May 2011 21:18:50 -0500
To: bug-Perl-Critic [...] rt.cpan.org
From: Elliot Shank <perl [...] galumph.com>
On 5/23/11 9:03 PM, Kevin Ryde via RT wrote: Show quoted text
> Do the END block bit at least. If anyone actually obeyed the violation > I first reported then their code would not work. It can't be good to > report as a violation something perlvar.pod specifically says to do.
I disagree. 1) General issue: This starts down a long road to writing a new book with lots of nit-picky examples. 2) This specific point: a) If you want to set an exit code, use exit(). But what about other END blocks you say? Why the #(*&@%) do you have multiple END blocks in sane code? b) Any code longer than, say, 15-20 lines that has an end block is broken.
Subject: Re: [rt.cpan.org #68364] RequireLocalizedPunctuationVars exempt $?
Date: Mon, 30 May 2011 11:25:31 +1000
To: bug-Perl-Critic [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
"Elliot Shank via RT" <bug-Perl-Critic@rt.cpan.org> writes: Show quoted text
> > a) If you want to set an exit code, use exit(). But what about > other END blocks you say? Why the #(*&@%) do you have > multiple END blocks in sane code?
Separate pieces of shutdown code can set $? non-zero if they strike an error. Each need not know the other exists or which ones are in use.
Subject: Re: [rt.cpan.org #68364] RequireLocalizedPunctuationVars exempt $?
Date: Sun, 29 May 2011 22:51:06 -0500
To: bug-Perl-Critic [...] rt.cpan.org
From: Elliot Shank <perl [...] galumph.com>
On 5/29/11 8:25 PM, Kevin Ryde via RT wrote: Show quoted text
> Separate pieces of shutdown code can set $? non-zero if they strike an > error. Each need not know the other exists or which ones are in use.
Then how do you predict what the exit code is going to be? It depends upon load order. The exit code is thus meaningless (hell, an END block could set the exit code to 0). Not a good situation to be in.
Subject: Re: [rt.cpan.org #68364] RequireLocalizedPunctuationVars exempt $?
Date: Tue, 31 May 2011 10:15:46 +1000
To: bug-Perl-Critic [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
"Elliot Shank via RT" <bug-Perl-Critic@rt.cpan.org> writes: Show quoted text
> > what the exit code is going to be?
What I said, set it to non-zero if an error (and leave it alone if ok). This is command-line oriented of course. For example Test::Builder does it (buried under some method calls) for test scripts.
Subject: Re: [rt.cpan.org #68364] RequireLocalizedPunctuationVars exempt $?
Date: Mon, 30 May 2011 19:30:25 -0500
To: bug-Perl-Critic [...] rt.cpan.org
From: Elliot Shank <perl [...] galumph.com>
On 5/30/11 7:16 PM, Kevin Ryde via RT wrote: Show quoted text
> "Elliot Shank via RT"<bug-Perl-Critic@rt.cpan.org> writes:
>> >> what the exit code is going to be?
> > What I said, set it to non-zero if an error (and leave it alone if ok). > This is command-line oriented of course.
And, again, if there are multiple things mucking with this variable, then it is effectively useless.
Subject: Re: [rt.cpan.org #68364] RequireLocalizedPunctuationVars exempt $?
Date: Tue, 31 May 2011 11:17:22 +1000
To: bug-Perl-Critic [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
"Elliot Shank via RT" <bug-Perl-Critic@rt.cpan.org> writes: Show quoted text
> > multiple things
You seem to misunderstand. Each is effectively END { if (is_bad()) { $? = 1; } } representing an "or" together of the badness. I thought that was both pretty conventional and more or less the designed purpose of that END plus $? combination. No doubt easy to be creative too with incrementing or only increasing $? if an exit code represents a level of badness of some kind. It was probably a bit of a mistake back long ago to have used the same global for child process status and current process exit code, especially as they're subtly different kinds of values.
Subject: Re: [rt.cpan.org #68364] RequireLocalizedPunctuationVars exempt $?
Date: Mon, 30 May 2011 21:56:55 -0500
To: bug-Perl-Critic [...] rt.cpan.org
From: Elliot Shank <perl [...] galumph.com>
On 5/30/11 8:17 PM, Kevin Ryde via RT wrote: Show quoted text
> representing an "or" together of the badness. I thought that was both > pretty conventional and more or less the designed purpose of that END > plus $? combination. No doubt easy to be creative too with incrementing > or only increasing $? if an exit code represents a level of badness of > some kind.
You're making the assumption that all modules are written for a single application. What about an application that uses multiple distributions, mixed and matched? What good is setting $? when the application has an explicit exit(0) call itself? Specific exit values can mean different things, e.g. for grep. Again, if you want a specific exit value, call exit().