I am trying to understand why IO::File does not work with use autodie :
Example # 1 : a test program using open :
#! /usr/bin/env perl # use strict; use warnings; use feature qw(say); use autodie; use IO::File; open( my $fh, "<", "bogus_file" ); # my $fh = IO::File->new( "bogus_file", "r" ); while ( my $line = $fh->getline ) { chomp $line; say qq(Line = "$line"); }
This fails:
Can't open 'bogus_file' for reading: 'No such file or directory' at ./test.pl line 9
autodie seems to work.
Example # 2 : the same test program, but now using IO::File :
#! /usr/bin/env perl # use strict; use warnings; use feature qw(say); use autodie; use IO::File; # open( my $fh, "<", "bogus_file" ); my $fh = IO::File->new( "bogus_file", "r" ); while ( my $line = $fh->getline ) { chomp $line; say qq(Line = "$line"); }
This fails:
Can't call method "getline" on an undefined value at ./test.pl line 11.
It seems autodie did not catch the bad IO::File->new open.
However, as far as I can tell, IO::File->new uses open under it. Here is the code from IO::File :
sub new { my $type = shift; my $class = ref($type) || $type || "IO::File"; @_ >= 0 && @_ <= 3 or croak "usage: $class->new([FILENAME [,MODE [,PERMS]]])"; my $fh = $class->SUPER::new(); if (@_) { $fh->open(@_)
What makes autodie not work as expected?
source share