Subject: | Perl 5.10.0 displayed a "invalid dirhandle" warning in Mail/Field.pm |
Date: | Thu, 26 Jun 2008 09:58:28 +0200 |
To: | <bug-MailTools [...] rt.cpan.org> |
From: | "Manuel Hecht - OTRS AG" <manuel.hecht [...] otrs.com> |
Hi @ all
Perl 5.10.0 displayed a "invalid dirhandle" warning in Mail/Field.pm (line
51), if "use warnings" is enabled:
Show quoted text
> index.pl: closedir() attempted on invalid dirhandle DIR at Mail/Field.pm
line 51.
Here the code part:
Show quoted text> sub _require_dir
> { my($class,$dir,$dir_sep) = @_;
>
> opendir DIR, $dir
> or return;
>
> my @inc;
>
> foreach my $f (readdir DIR)
> { $f =~ /^([\w\-]+)/ or next;
> my $p = $1;
> my $n = "$dir$dir_sep$p";
>
> if(-d $n )
> { _require_dir("${class}::$f", $n, $dir_sep);
> }
> else
> { $p =~ s/-/_/go;
> eval "require ${class}::$p";
> }
> }
> closedir DIR;
> }
The usage of the barewords as filehandles/dirhandles is deprecated in Perl
5.10!
I think there are two solutions of this problem:
1. Use a indirect dirhandle:
Show quoted text> sub _require_dir
> { my($class,$dir,$dir_sep) = @_;
>
> opendir my $DirHandle, $dir
> or return;
>
> my @inc;
>
> foreach my $f (readdir $DirHandle)
> { $f =~ /^([\w\-]+)/ or next;
> my $p = $1;
> my $n = "$dir$dir_sep$p";
>
> if(-d $n )
> { _require_dir("${class}::$f", $n, $dir_sep);
> }
> else
> { $p =~ s/-/_/go;
> eval "require ${class}::$p";
> }
> }
> closedir $DirHandle;
> }
This code works perfect under Perl 5.10, but I think the usage of indirect
filehandles
needs Perl 5.6.0 or later!
2. Disable Warnings in this part of the code:
Show quoted text> sub _require_dir
> { my($class,$dir,$dir_sep) = @_;
>
> no warnings;
>
> opendir DIR, $dir
> or return;
>
> my @inc;
>
> foreach my $f (readdir DIR)
> { $f =~ /^([\w\-]+)/ or next;
> my $p = $1;
> my $n = "$dir$dir_sep$p";
>
> if(-d $n )
> { _require_dir("${class}::$f", $n, $dir_sep);
> }
> else
> { $p =~ s/-/_/go;
> eval "require ${class}::$p";
> }
> }
> closedir DIR;
>
> use warnings;
> }
This solution works with Perl 5.0, but I think it's not really a fix, is a
workaround. ;-)
Best regards,
Manuel Hecht
((otrs)) :: OTRS AG :: Europaring 4 :: D - 94315 Straubing
Fon: +49 (0)9421 56818 0 :: Fax: +49 (0)9421 56818 18
http://www.otrs.com/ :: Communication with success!