You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
perldoc autodie says:
The "autodie" pragma has lexical scope, meaning that functions and
> 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
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.
Peter Valdemar Mørch via RT:
> 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
From $_ = 'spro^^%^6ut#@&$�>#!^!#&!pan.org'; y/a-z.@//cd; print on 2016-05-31 13:28:17
:
From $_ = 'spro^^%^6ut#@&$�>#!^!#&!pan.org'; y/a-z.@//cd; print on 2016-05-31 22:50:13
:
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
<[email protected]> wrote:
> <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, [email protected] 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
The text was updated successfully, but these errors were encountered:
Migrated from rt.cpan.org#114757 (status was 'open')
Requestors:
Attachments:
From [email protected] on 2016-05-27 05:17:53
:
From [email protected] on 2016-05-30 21:49:27
:
From [email protected] on 2016-05-31 06:24:11
:
From $_ = 'spro^^%^6ut#@&$�>#!^!#&!pan.org'; y/a-z.@//cd; print on 2016-05-31 13:28:17
:
From $_ = 'spro^^%^6ut#@&$�>#!^!#&!pan.org'; y/a-z.@//cd; print on 2016-05-31 22:50:13
:
From [email protected] on 2016-06-01 07:39:44
:
The text was updated successfully, but these errors were encountered: