I'm expecting:
#!/usr/bin/perl
use autodie;
# autodie in effect here
{
no autodie;
# autodie is not in effect here
}
# autodie should be in effect here because of the supposedly lexical scope
# of autodie, but this doesn't die:
open my $i, '<', '/nonexistent';
I base that on perldoc autodie
that 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"
Also, { no autodie }
(in a scope) is even part of the SYNOPSIS
use/no warnings
behaves as I expect:
#!/usr/bin/perl
use warnings;
{
no warnings;
}
# This *does* generate a warning
print undef;
Have I missed something or do you agree there a bug in autodie? I didn't find anything in the autodie buglist
This is perl, v5.10.1 (*) built for i486-linux-gnu-thread-multi
EDIT: I've now filed a bug report
I can reproduce this with v5.10.0 (Debian x86_64) and ActiveState 5.14.2.
Try this location for bug reports.
EDIT I tested some: to circumvent the problem until the bug is fixed, you'll need to use
autodie again:
use strict;
use autodie;
do {
no autodie;
# ...
} while(0);
use autodie;
open FILE, '<', '/non-existing'; # dies again.
The Synopsis doesn't actually show the directive having a lexical scope, but it is mentioned multiple times elsewhere in the documentation. This is clearly a bug.
The question becomes: Does the bug still exist?
$ perl -E'use autodie; say $autodie::VERSION'
2.1001
$ perl -we'use autodie; { no autodie; } open(my $fh, "<", "nonexistant");'
$ perl -we'use autodie; open(my $fh, "<", "nonexistant");'
Can't open 'nonexistant' for reading: 'No such file or directory' at -e line 1
$ perl -we'{ use autodie; } open(my $fh, "<", "nonexistant");'
Yes, it does. It's only no autodie;
that's broken, though. Oddly, that version of autodie is newer than what's currently available on CPAN?! So I downgraded and tried again.
$ perl -E'use autodie; say $autodie::VERSION'
2.10
$ perl -we'use autodie; { no autodie; } open(my $fh, "<", "nonexistant");'
$ perl -we'use autodie; open(my $fh, "<", "nonexistant");'
Can't open 'nonexistant' for reading: 'No such file or directory' at -e line 1
$ perl -we'{ use autodie; } open(my $fh, "<", "nonexistant");'
Bugs can be filed using autodie's bug tracker.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With