Torsten Mangner said:
Hi group,
i need a capability (via a skript or something) to test my skripts (at
compile time),
If you are using a script to check other scripts, the question of
"compile time" doesn't come up -- you won't be compiling the scripts
you are testing.
if all subroutines that are called in the programm are
really defined or 'use'd.
You don't "use" a subroutine, you "use" a module which may define some
subroutines.
In all its generality, your problem will be hard to solve. Since
subroutine calls can be modified at run time, there is no easy way
to know which subroutines will be called without running the program.
Since subroutine definitions can be added or modified at run time,
there is no way of telling which calls will succeeded without running
the program.
If you can settle for a fixed list of sub names, add this to your
script:
CHECK {
report_sub( $_) for qw( sub1 sub2 ...);
sub report_sub {
my $name = shift;
my $status = 'unknown';
$status = 'declared' if exists &$name;
$status = 'defined' if defined &$name;
print "$name is $status\n";
}
}
The CHECK block is run after compilation is complete (that means, all
"use" statements have been executed at this point). For the application
of "exists" and "defined" to subroutines, see "perldoc -f exists".
Anno