Why does the module compile on its own, but fail when used from other sources?

I have a Perl module that seems to compile itself, but causes other programs to fail to compile when it is turned on:

me@host :~/code $ perl -c -Imodules modules/Rebat/Store.pm modules/Rebat/Store.pm syntax OK me@host :~/code $ perl -c -Imodules bin/rebat-report-status Attempt to reload Rebat/Store.pm aborted Compilation failed in require at bin/rebat-report-status line 4. BEGIN failed--compilation aborted at bin/rebat-report-status line 4. 

The first few lines of rebat-report-status are

 ... 3 use Rebat; 4 use Rebat::Store; 5 use strict; ... 
+4
source share
2 answers

Change (for posterity). Another reason for this, and perhaps the most common reason, is that there is a circular relationship between the modules you use.


Check out Rebat/Store.pm for tips. Your log says that the reboot attempt was aborted. It is possible that Rebat already importing Rebat::Store , and Rebat::Store has some scope check for the package to be downloaded twice.

This code demonstrates the kind of situation that I have in mind:

 # m1.pl: use M1; use M1::M2; M1::M2::x(); # M1.pm package M1; use M1::M2; 1; # M1/M2.pm package M1::M2; our $imported = 0; sub import { die "Attempt to reload M1::M2 aborted.\n" if $imported++; } sub x { print "42\n" } 1; 

 $ perl m1.pl Attempt to reload M1::M2 aborted. BEGIN failed--compilation aborted at m1.pl line 3. 

The code will compile (and print 42) if you simply delete the line use M1::M2 in m1.pl In your case, you may not need to explicitly use Rebat::Store in your program.

+8
source

perldoc perldiag :

  Attempt to reload %s aborted. (F) You tried to load a file with "use" or "require" that failed to compile once already. Perl will not try to compile this file again unless you delete its entry from %INC. See "require" in perlfunc and "%INC" in perlvar. 
+3
source

Source: https://habr.com/ru/post/1300325/


All Articles