Skip Menu |
 

This queue is for tickets about the autodie CPAN distribution.

Report information
The Basics
Id: 114757
Status: open
Priority: 0/
Queue: autodie

People
Owner: Nobody in particular
Requestors: peter [...] morch.com
Cc:
AdminCc:

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



Subject: autodie does not honor file scope...
Date: Fri, 27 May 2016 07:17:33 +0200
To: bug-autodie [...] rt.cpan.org
From: Peter Valdemar Mørch <peter [...] morch.com>
Download (untitled) / with headers
text/plain 534b
perldoc autodie says: The "autodie" pragma has lexical scope, meaning that functions and Show quoted text
> subroutines altered with "autodie" will only change their behaviour > until > the end of the enclosing block, file, or "eval". >
Therefore I expect A::bad to die below. It doesn't. #!/usr/bin/perl -w use strict; use autodie; package A; sub bad { open(my $i, '<', 'nonexist'); } package main; A::bad; I've created two test cases: file-scope.t (currently fails) and package-scope.t (currently passes) to cover it. Peter
Download file-scope.t
text/x-perl 410b

Message body is not shown because sender requested not to inline it.

Download package-scope.t
text/x-perl 386b

Message body is not shown because sender requested not to inline it.

Subject: Re: [rt.cpan.org #114757] AutoReply: autodie does not honor file scope...
Date: Mon, 30 May 2016 23:49:11 +0200
To: bug-autodie [...] rt.cpan.org
From: Peter Valdemar Mørch <peter [...] morch.com>
Download (untitled) / with headers
text/plain 728b
Another corner case in this area: If I have a module that does not have a "package" declaration, autodie in the .pl file using that module declares a weird error in that module. See attached useModuleWithoutPackage.pl and ModuleWithoutPackage.pm In short autodie in the .pl file and this in the .pm file: sub foo { open I, '/etc/passwd'; close I; } Creates this error message: Can't use string ("I") as a symbol ref while "strict refs" in use at (eval 4) line 8. I believe that to be a bug in autodie, as I don't think there is any problem with the code. Please let me know if you'd like me to file a separate issue for this. But it is related to file scope, so I piggy-backed the new test case to this bug.

Message body is not shown because sender requested not to inline it.

Message body is not shown because sender requested not to inline it.

Subject: Re: [rt.cpan.org #114757] AutoReply: autodie does not honor file scope...
Date: Tue, 31 May 2016 06:23:00 +0000
To: bug-autodie [...] rt.cpan.org
From: Niels Thykier <niels [...] thykier.net>
Subject: Re: [rt.cpan.org #114757] AutoReply: autodie does not honor file scope...
To: bug-autodie [...] rt.cpan.org
From: Niels Thykier <niels [...] thykier.net>
Download (untitled) / with headers
text/plain 1.8k
Peter Valdemar Mørch via RT: Show quoted text
> Queue: autodie > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=114757 > > > Another corner case in this area: > > If I have a module that does not have a "package" declaration, autodie > in the .pl file using that module declares a weird error in that > module. See attached useModuleWithoutPackage.pl and > ModuleWithoutPackage.pm > > In short autodie in the .pl file and this in the .pm file: > > [...] > > I believe that to be a bug in autodie, as I don't think there is any > problem with the code. > > Please let me know if you'd like me to file a separate issue for this. > But it is related to file scope, so I piggy-backed the new test case > to this bug. >
Hi Peter, Thanks for reporting the issue. You have reported two distinct problems (short story): - Package scope: Works as intended (As far as I know) - File scope: Known issue that we cannot fix The longer story for "File scope": What happens is that autodie is still in effect in your new file-scope. The autodie module has code for detecting it "leaked" into a new scope and then "hides" itself as well as it can (e.g. ignores errors). However, as it is still present, its emulated prototype is still in effect and therefore there are certain cases where perl will behave differently. The file-scoped file-handles being one of them (another reason why we recommend the "my $fd" variant). The "Package scope" issue: As far as I know, *all* pragma in perl (incl. strict/warnings) only work in the given Package they are declared. Accordingly, package "A" does not have autodie (nor strict) in effect, which is also why autodie ignores the error. - Admittedly, the documentation for autodie might be a bit misleading for this case. If you have a suggestion for an alternative, I am happy to hear it. Thanks, ~Niels
Download signature.asc
application/pgp-signature 801b

Message body not shown because it is not plain text.

Download (untitled) / with headers
text/plain 1.1k
On Tue May 31 02:24:11 2016, niels@thykier.net wrote: Show quoted text
> The "Package scope" issue: As far as I know, *all* pragma in perl (incl. > strict/warnings) only work in the given Package they are declared. > Accordingly, package "A" does not have autodie (nor strict) in effect,
On the contrary, strict *is* in effect, and is not affected by the package declaration, because lexical and package scopes are orthogonal. The last time I checked, autodie was using package subroutines that check lexical hints to see whether they are in scope and should behave accordingly (or something like that). That it is using package subroutines to implement lexical features results in this bug. I can think of two ways to fix this, both of which requires XS hackery: 1) Hook perl’s ops instead of using subroutines. This would be the more difficult approach, but it would allow system and exec to be overridden without breaking their ‘exotic forms’. 2) Export lexical subroutines. This would only work in 5.18 or higher. For an example of how to do that, see the lexical_import function in ext/XS-APItest/APItest.xs in the perl core, along with ext/XS-APItest/t/lexsub.t, which uses it.
Download (untitled) / with headers
text/plain 1.3k
On Tue May 31 09:28:17 2016, SPROUT wrote: Show quoted text
> On Tue May 31 02:24:11 2016, niels@thykier.net wrote:
> > The "Package scope" issue: As far as I know, *all* pragma in perl > > (incl. > > strict/warnings) only work in the given Package they are declared. > > Accordingly, package "A" does not have autodie (nor strict) in > > effect,
> > On the contrary, strict *is* in effect, and is not affected by the > package declaration, because lexical and package scopes are > orthogonal. > > The last time I checked, autodie was using package subroutines that > check lexical hints to see whether they are in scope and should behave > accordingly (or something like that). That it is using package > subroutines to implement lexical features results in this bug. > > I can think of two ways to fix this, both of which requires XS > hackery: > > 1) Hook perl’s ops instead of using subroutines. This would be the > more difficult approach, but it would allow system and exec to be > overridden without breaking their ‘exotic forms’. > 2) Export lexical subroutines. This would only work in 5.18 or > higher. For an example of how to do that, see the lexical_import > function in ext/XS-APItest/APItest.xs in the perl core, along with > ext/XS-APItest/t/lexsub.t, which uses it.
Also, there is Lexical::Sub, which works back as far as 5.12.
Subject: Re: [rt.cpan.org #114757] autodie does not honor file scope...
Date: Wed, 1 Jun 2016 09:39:26 +0200
To: bug-autodie [...] rt.cpan.org
From: Peter Valdemar Mørch <peter [...] morch.com>
Download (untitled) / with headers
text/plain 1.9k
So there are limitations with the current implementation. Fair enough. At the very least, given there are these limitations with the current implementation, I would like to see a "LIMITATIONS" or "KNOWN BUGS" section in the perldoc, describing exactly what works and what doesn't and what to be aware of, so I'm not surprised - especially by action-at-a-distance bugs like the one presented in useModuleWithoutPackage.t. On Wed, Jun 1, 2016 at 12:50 AM, Father Chrysostomos via RT <bug-autodie@rt.cpan.org> wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=114757 > > > On Tue May 31 09:28:17 2016, SPROUT wrote:
>> On Tue May 31 02:24:11 2016, niels@thykier.net wrote:
>> > The "Package scope" issue: As far as I know, *all* pragma in perl >> > (incl. >> > strict/warnings) only work in the given Package they are declared. >> > Accordingly, package "A" does not have autodie (nor strict) in >> > effect,
>> >> On the contrary, strict *is* in effect, and is not affected by the >> package declaration, because lexical and package scopes are >> orthogonal. >> >> The last time I checked, autodie was using package subroutines that >> check lexical hints to see whether they are in scope and should behave >> accordingly (or something like that). That it is using package >> subroutines to implement lexical features results in this bug. >> >> I can think of two ways to fix this, both of which requires XS >> hackery: >> >> 1) Hook perl’s ops instead of using subroutines. This would be the >> more difficult approach, but it would allow system and exec to be >> overridden without breaking their ‘exotic forms’. >> 2) Export lexical subroutines. This would only work in 5.18 or >> higher. For an example of how to do that, see the lexical_import >> function in ext/XS-APItest/APItest.xs in the perl core, along with >> ext/XS-APItest/t/lexsub.t, which uses it.
> > Also, there is Lexical::Sub, which works back as far as 5.12. >
-- Peter Valdemar Mørch http://www.morch.com


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.