Subject: | Failed tests without optional Mail::IMAPClient installed |
Hi,
although Mail::IMAPClient is listed as an optional module, the test '40mbox/40append' fails with the following error message if the module isn't installed:
40mbox/40append.....ok 1/32ERROR: Package Mail::Box::IMAP4 does not implement Mail::Box::foundIn.
Please warn the author, this shouldn't happen. at ../lib/Mail/Reporter.pm line 196
Mail::Reporter::notImplemented('Mail::Box::IMAP4') called at ../lib/Mail/Box.pm line 155
Mail::Box::foundIn('Mail::Box::IMAP4', '=empty', 'create', 1, 'access', 'rw', 'folderdir', '/home/niko/src/libmail-box-perl-2.060/tests/folders', 'extract', ...) called at ../lib/Mail/Box/Manager.pm line 208
Mail::Box::Manager::open('Mail::Box::Manager=HASH(0x814db44)', 'folder', '=empty', 'folderdir', '/home/niko/src/libmail-box-perl-2.060/tests/folders', 'lock_type', 'NONE', 'extract', 'LAZY', ...) called at 40mbox/40append.t line 107
The reason for the failure is that Mail::Box::Manager tries to autodetect foldertype with 'eval "require $class"' for all available foldertypes without checking if it tries to require the same class twice. The second require() for the same class is successful even when there's a compilation error in the first one.
The available foldertypes hash has both the keys 'imap' and 'imap4' pointing to the same class, and so the code ends up with an empty Mail::Box::IMAP4 class if its dependencies are not present.
The fact that the second require() always succeeds is a bit surprising: AIUI the example equivalent subroutine in 'perldoc -f require' seems to contradict this. Anyway, it is easy to show that this is the case. Consider the following script:
#!/usr/bin/perl -w
use strict;
for (1..2) {
print "$_...\n";
eval "require BrokenClass";
print $@ ? $@ : "OK\n";
}
with BrokenClass.pm containing something that doesn't compile cleanly. The output is:
rebekka% ./t3.pl
1...
syntax error at BrokenClass.pm line 1, near "="
Compilation failed in require at (eval 1) line 3.
2...
OK
I am attaching a patch that fixes the autodetection in Mail::Box::Manager. I haven't looked for similar problems elsewhere in the code.
Version information:
- Mail-Box 2.060
- Perl 5.8.7
- Debian GNU/Linux (unstable)
--
Niko Tyni
ntyni@iki.fi
--- libmail-box-perl-2.060/lib/Mail/Box/Manager.pm 2005-03-15 21:02:43.000000000 +0000
+++ libmail-box-perl-2.060-mod/lib/Mail/Box/Manager.pm 2005-06-12 12:16:10.416349853 +0000
@@ -199,8 +199,10 @@
unless($folder_type)
{ # Try to autodetect foldertype.
+ my %tried;
foreach (@{$self->{MBM_folder_types}})
{ (my $abbrev, $class, @defaults) = @$_;
+ next if $tried{$class}++;
eval("require $class");
next if $@;
@@ -355,9 +357,11 @@
# Try to autodetect the folder-type and then add the message.
my ($name, $class, @gen_options, $found);
+ my %tried;
foreach (@{$self->{MBM_folder_types}})
{ ($name, $class, @gen_options) = @$_;
+ next if $tried{$class}++;
eval "require $class";
next if $@;