Skip Menu |

This queue is for tickets about the MailTools CPAN distribution.

Report information
The Basics
Id: 37114
Status: resolved
Priority: 0/
Queue: MailTools

People
Owner: Nobody in particular
Requestors: manuel.hecht [...] otrs.com
Cc:
AdminCc:

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



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!
Sorry, your email got burried in my spam. I think the problem is differently. There is only one DIR, but the function is called recursively. This means that the inner call closes the file-handle of the outer call. When returning, the closedir complains about an undef DIR... Simple fix: add local *DIR before opendir.
Subject: AW: [rt.cpan.org #37114] Perl 5.10.0 displayed a "invalid dirhandle" warning in Mail/Field.pm
Date: Thu, 10 Jul 2008 12:54:55 +0200
To: <bug-MailTools [...] rt.cpan.org>
From: "Manuel Hecht - OTRS AG" <manuel.hecht [...] otrs.com>
Hi Hm, i overlooked the recursion. Sorry. I can verify the fix. It works perfect for me! :-) Thanks. Is the fix part of the next version? 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! Show quoted text
-----Ursprüngliche Nachricht----- Von: Mark Overmeer via RT [mailto:bug-MailTools@rt.cpan.org] Gesendet: Mittwoch, 9. Juli 2008 23:14 An: manuel.hecht@otrs.com Betreff: [rt.cpan.org #37114] Perl 5.10.0 displayed a "invalid dirhandle" warning in Mail/Field.pm <URL: http://rt.cpan.org/Ticket/Display.html?id=37114 > Sorry, your email got burried in my spam. I think the problem is differently. There is only one DIR, but the function is called recursively. This means that the inner call closes the file-handle of the outer call. When returning, the closedir complains about an undef DIR... Simple fix: add local *DIR before opendir.
2.04 was released on June 29