Perché un modulo di compilazione di per sé, ma non riescono quando viene utilizzato da qualche altra parte?

StackOverflow https://stackoverflow.com/questions/2202243

  •  18-09-2019
  •  | 
  •  

Domanda

Ho un modulo Perl che appare per compilare bene da sé, ma sta causando altri programmi a fallire la compilazione quando è incluso:

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.

Le prime righe di rebat-report-status sono

...
3 use Rebat;
4 use Rebat::Store;
5 use strict;
...
È stato utile?

Soluzione

Modifica (per i posteri): Un altro motivo per questo si verifichi, e forse il motivo più comune, è che c'è una dipendenza circolare tra i moduli che si sta utilizzando

.

Cerca in Rebat/Store.pm di indizi. Il registro dice tentativo di Ricarica è stata interrotta. Forse Rebat importa già Rebat::Store, e Rebat::Store ha qualche controllo pacchetto-scope contro essere caricato due volte.

Questo codice viene illustrato il tipo di situazione che intendo:

# 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.

Il codice verrà compilato (e stampare 42) se si rimuove la linea use M1::M2 in m1.pl. Nel tuo caso, potrebbe non essere necessario per use Rebat::Store esplicitamente nel programma.

Altri suggerimenti

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.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top