2

I'm cleaning up code and removed the now deprecated Forecast::IO module from my Perl script. When I did, I started getting this error:

[root@server cgi-bin]# perl Weather.pm
Undefined subroutine &B::perlstring called at /usr/local/share/perl5/Params/ValidationCompiler/Compiler.pm line 248.
Compilation failed in require at /usr/local/lib64/perl5/DateTime.pm line 13.
BEGIN failed--compilation aborted at /usr/local/lib64/perl5/DateTime.pm line 13.
Compilation failed in require at Weather.pm line 1340.
BEGIN failed--compilation aborted at Weather.pm line 1340.

Line 1340 where the error occurs is innocuously enough, use DateTime;.

I wasn't sure what DateTime could be up to that would cause it to be upset I wasn't using the unrelated Forecast::IO module any longer, so I started taking apart the latter module to figure out what code was preventing the error. The essential part seems to be that Moo is included in Forecast::IO and it has at least one Moo has declaration:

package Forecast::IO;
use Moo;
has testkey => ( is => 'ro' ); 
1;

For some reason, if that module with at least those lines exists, DateTime loads fine. Otherwise, the error I mentioned above occurs, choking on DateTime's line 13, use Carp;. Even if I put use Moo; has testkey => ( is => 'ro' ); into my own module, it fails upon use DateTime.

Even though I've used grep -r Forecast::IO to traverse the codebase to look for some errant reference and come up empty. So, I decided to try to just load the DateTime module: perl -MDateTime. That too produces the error:

[root@server cgi-bin]# perl -MDateTime
Undefined subroutine &B::perlstring called at     /usr/local/share/perl5/Params/ValidationCompiler/Compiler.pm line 248.
Compilation failed in require at /usr/local/lib64/perl5/DateTime.pm line 13.
BEGIN failed--compilation aborted at /usr/local/lib64/perl5/DateTime.pm line 13.
Compilation failed in require.
BEGIN failed--compilation aborted.
Timothy R. Butler
  • 1,097
  • 7
  • 20
  • The error is about `B::perstring` missing, first called at line 340 (nearest to 248 the error reports) in `Params::ValidationCompiler::Compiler`. What version of these modules do you have? – zdim Jul 11 '21 at 03:22
  • I have `B::C` 1.57 and `Params::ValidationCompiler` 0.30. Interestingly, I just upgraded `DateTime` from CPAN and that seems to have fixed the error. I'm curious why `DateTime` broke and why having that `Moo` based module somehow "fixed" it, but with the current release of DateTime, the error goes away without having to require `Forecast::IO`. – Timothy R. Butler Jul 11 '21 at 03:26
  • Ah, that may explain it. The weird thing is that it doesn't complain about `use B qw(perlstring);` -- but it does about using it later. So I guess things may have been different (broken?) in earlier versions. But so all is well for you now? :) – zdim Jul 11 '21 at 03:34
  • @zdim Yes, thankfully! Thank you for the help. I'm curious what was going on, but at least it is working now! – Timothy R. Butler Jul 13 '21 at 16:41
  • 1
    Alright :), This definitely triggers my curiosity as well ... It is a great summary of reasons why I am restrained with using the full power of CPAN: often all kinds of code gets involved, so much so that I have no way to check what some of not-so-well-tested code is doing. (But then of course there are all the good reasons for using it fully...) – zdim Jul 13 '21 at 17:39
  • @zdim Good point! I'm really surprised I haven't noticed more such issues in the past. Thanks again! :-) – Timothy R. Butler Jul 16 '21 at 20:23

0 Answers0