mein Kollege und ich haben schon seit einer Weile ein
Problem mit dem Import von Modulen mit komplexen Beziehungen.
Module, die sich gegenseitig importieren stellen teilweise
nicht wie erwartet Modulfunktionen im erwarteten Namensraum
zu Verfügung.
Bevor ich hier versuche den Effekt zu beschreiben, poste ich
mal einfach 2 Beispiele.
Das erste Beispiel funktioniert, das 2. nicht.
Für Tips, was wir hier falsch machen würde ich mich sehr freuen.
Danke!
1. Beispiel, 1xScript, 2xModul
Dies kommt dabei raus:
(16:14:59) [2] ./test.pl
main company::show_company
Undefined subroutine &company::read_artist called at company.pm line
33 (#1)
(F) The subroutine indicated hasn't been defined, or if it was, it
has
since been undefined.
Uncaught exception from user code:
Undefined subroutine &company::read_artist called at
company.pm line 33.
at company.pm line 33
company::show_company() called at ./test.pl line 15
test.pl
##################
#!/usr/bin/perl
use warnings;
use diagnostics;
use strict;
use artist qw {
show_artist
};
use company qw {
show_company
};
show_company();
show_artist();
artist.pm
########################
package artist;
use warnings;
use diagnostics;
use strict;
use company qw {
read_company
};
use Exporter;
use vars qw(@ISA @EXPORT @EXPORT_OK);
@ISA = qw(Exporter);
@EXPORT_OK = qw(
read_artist
show_artist
);
sub read_artist {
my ( $package, $filename, $line, $subroutine, $hasargs,
$wantarray, $evaltext, $is_require, $hints, $bitmask ) =
caller( 0 );
print STDOUT "$package $subroutine\n";
}
sub show_artist {
my ( $package, $filename, $line, $subroutine, $hasargs,
$wantarray, $evaltext, $is_require, $hints, $bitmask ) =
caller( 0 );
print STDOUT "$package $subroutine\n";
read_company();
read_artist();
print "Show Artist and the appendant Company...";
}
return(1);
company.pm
######################
package company;
use warnings;
use diagnostics;
use strict;
use artist qw {
read_artist
};
use Exporter;
use vars qw(@ISA @EXPORT @EXPORT_OK);
@ISA = qw(Exporter);
@EXPORT_OK = qw(
read_company
show_company
);
sub read_company {
my ( $package, $filename, $line, $subroutine, $hasargs,
$wantarray, $evaltext, $is_require, $hints, $bitmask ) =
caller( 0 );
print STDOUT "$package $subroutine\n";
}
sub show_company {
my ( $package, $filename, $line, $subroutine, $hasargs,
$wantarray, $evaltext, $is_require, $hints, $bitmask ) =
caller( 0 );
print STDOUT "$package $subroutine\n";
read_artist();
read_company();
print "Show Company and the appendant artists...";
}
return(1);
##############################################################
2. Beispiel, 1xScript, 4xModul
Dies kommt dabei raus:
(17:22:51) [3] ./test.pl
main company::show_company
company artist_read::read_artist
company company_read::read_company
Show Company and the appendant artists...
main artist::show_artist
artist company_read::read_company
artist artist_read::read_artist
Show Artist and the appendant Company...
test.pl
##################
#!/usr/bin/perl
use warnings;
use diagnostics;
use strict;
use artist qw {
show_artist
};
use company qw {
show_company
};
show_company();
show_artist();
artist.pm
########################
package artist;
use warnings;
use diagnostics;
use strict;
use company_read qw {
read_company
};
use artist_read qw {
read_artist
};
use Exporter;
use vars qw(@ISA @EXPORT @EXPORT_OK);
@ISA = qw(Exporter);
@EXPORT_OK = qw(
show_artist
);
sub show_artist {
my ( $package, $filename, $line, $subroutine, $hasargs,
$wantarray, $evaltext, $is_require, $hints, $bitmask ) =
caller( 0 );
print STDOUT "$package $subroutine\n";
read_company();
read_artist();
print "Show Artist and the appendant Company...\n";
}
return(1);
company.pm
######################
package company;
use warnings;
use diagnostics;
use strict;
use artist_read qw {
read_artist
};
use company_read qw {
read_company
};
use Exporter;
use vars qw(@ISA @EXPORT @EXPORT_OK);
@ISA = qw(Exporter);
@EXPORT_OK = qw(
show_company
);
sub show_company {
my ( $package, $filename, $line, $subroutine, $hasargs,
$wantarray, $evaltext, $is_require, $hints, $bitmask ) =
caller( 0 );
print STDOUT "$package $subroutine\n";
read_artist();
read_company();
print "Show Company and the appendant artists...\n";
}
return(1);
artist_read.pm
######################
package artist_read;
use warnings;
use diagnostics;
use strict;
use Exporter;
use vars qw(@ISA @EXPORT @EXPORT_OK);
@ISA = qw(Exporter);
@EXPORT_OK = qw(
read_artist
);
sub read_artist {
my ( $package, $filename, $line, $subroutine, $hasargs,
$wantarray, $evaltext, $is_require, $hints, $bitmask ) =
caller( 0 );
print STDOUT "$package $subroutine\n";
}
return(1);
company_read.pm
######################
package company_read;
use warnings;
use diagnostics;
use strict;
use Exporter;
use vars qw(@ISA @EXPORT @EXPORT_OK);
@ISA = qw(Exporter);
@EXPORT_OK = qw(
read_company
);
sub read_company {
my ( $package, $filename, $line, $subroutine, $hasargs,
$wantarray, $evaltext, $is_require, $hints, $bitmask ) =
caller( 0 );
print STDOUT "$package $subroutine\n";
}
return(1);