* Arne Becker via RT (bug-MailTools@rt.cpan.org) [141117 15:29]:
Show quoted text> If the "require" fails, we end up with an entry in %INC like this:
> $INC{'Mail/Field/Date.pm'} => undef.
Good deduction. I understand your explanation.
Show quoted text> Since there is no error checking after the eval "require ...", we just
> continue.
We cannot add error checking, because many modules may accidentally
try to compile all kinds of weird (non Perl) files. We cannot break
existing installations.
Show quoted text> But if another module does "use Mail::Field" (or MIME::Parser), sub
> import gets called again.
Maybe even a recursive require.
Show quoted text> I think, this is what happens with multi-threading: Thread 1 is still
> working on the BEGIN{} sections, i.e. has started "require", but not
> finished yet. Then thread 2 comes along with its use statement and sees
> the still empty path, which only gets set when thread 1 finishes.
I hate Perl threads ;-)
Show quoted text> Fixes:
> 1.
> In Mail::Field, sub _require_dir, include the error check:
Not possible. Sorry, the code is much older than me ;-)
Show quoted text> 2.
> Ensure that the modules for Date::Format and Date::Parse are there and
> can be "required".
> I think the dependency on Date::Parse may be missing, but there is a
> dependency in Date::Format, which is in the same module TimeDate, so
> maybe this is correct.
Both dependencies are in Makefile.PL If some (Linux) destribution
thinks it's optional, than please file a bug-report at them.
Show quoted text> 3. For the multi-threading problem, maybe it's enough to add this to sub
> import:
>
> foreach my $f (keys %INC)
> { next unless defined $INC{$f};
> next if $f !~ /^Mail(\W)Field\W/i;
> $dir_sep = $1;
> $dir = ($INC{$f} =~ /(.*Mail\W+Field)/i)[0] . $dir_sep;
>
> although the correct fix seems to be to make sub import synchronized.
Adding that defined $INC{$f} seems to be the best solution, yes.
What do you think... is the last line equivalent to
($dir = $INC{$f}) =~ s/(Mail\W+Field).*/$1$dir_sep/;
Show quoted text> I think, it would also be a good idea to store "I did the require of my
> sub modules" in a package global variable in Mail::Field. Doing it on
> every call of import seems wrong. Alternatively, move that part out of
> import and into a separate BEGIN{} block.
Those things in BEGIN often cause problems with mod_perl. The 'tried all'
flag may cause problems with packages which are added later, and add
to @INC. MailTools is one of the oldest modules, written in the time
(and style) of very old Perl... where everyone was using 'do some.pl'
and so on. So easy to break...
If you want good email modules, use Mail::Box or the Email::* suite.
Show quoted text> I don't think this behaviour was introduced with 2.13, it seems it was
> there before. Due to the hash randomization changes in perl 5.18 it does
> not always trigger.
Agree.
--
Regards,
MarkOv
------------------------------------------------------------------------
Mark Overmeer MSc MARKOV Solutions
Mark@Overmeer.net solutions@overmeer.net
http://Mark.Overmeer.net http://solutions.overmeer.net