#!/usr/bin/perl

# The LearningOnline Network with CAPA
#
# Testing to see if all needed perl components are on
# a system
#
# YEAR=2001
# 9/30 Scott Harrison
#
# I wish there were a more straightforward way to do this.  But I can't
# seem to find the right internals in the perl programming language.
# Also, this program is only a "modest" effort to LOOK and see whether
# necessary perl system dependencies are present.  I do not yet
# try to actually run tests against each needed perl module.

# --------------------------------- Make sure the perl version is suitably high
my $ret=system("find --version 1>/dev/null");
if ($]<5.005) {
    die "DEPENDENCY FAILURE: LON-CAPA requires perl version >= 5.005.\n";
}

# ------------------------------------------ Make sure we have the find command
my $ret=system("find --version 1>/dev/null");
if ($ret) {
    die "DEPENDENCY FAILURE: A test program requires the GNU ".
	"'find' utility.\n";
}

# ----------------------------------------- Read in all the system perl modules
print "Scanning for perl modules...\n";
my $modules; 
foreach my $inc (@INC) {
    my @m=`find $inc -type f -name '*.pm'`;
    foreach my $mod (@m) {
	$modules.=$mod;
    }
}

# --------------- Seeing if dependencies are in our "full" list of perl modules
my %dependencies=qw(
		    GD/Barcode.pm 1
		    GD/Barcode/COOP2of5.pm 1
		    GD/Barcode/Code39.pm 1
		    GD/Barcode/EAN13.pm 1
		    GD/Barcode/EAN8.pm 1
		    GD/Barcode/IATA2of5.pm 1
		    GD/Barcode/ITF.pm 1
		    GD/Barcode/Industrial2of5.pm 1
		    GD/Barcode/Matrix2of5.pm 1
		    GD/Barcode/NW7.pm 1
		    GD/Barcode/UPCA.pm 1
		    GD/Barcode/UPCE.pm 1
		    IO/Dir.pm 1
		    IO/Poll.pm 1
		    IO/Socket/INET.pm 1
		    IO/Socket/UNIX.pm 1
		    Algorithm/Diff.pm 1
		    Algorithm/DiffOld.pm 1
		    Bundle/LWP.pm 1
		    File/Listing.pm 1
		    HTML/AsSubs.pm 1
		    HTML/Element.pm 1
		    HTML/Element/traverse.pm 1
		    HTML/Form.pm 1
		    HTML/Parse.pm 1
		    HTML/Tagset.pm 1
		    HTML/Tree.pm 1
		    HTML/TreeBuilder.pm 1
		    HTTP/Cookies.pm 1
		    HTTP/Daemon.pm 1
		    HTTP/Date.pm 1
		    HTTP/Headers.pm 1
		    HTTP/Headers/Auth.pm 1
		    HTTP/Headers/ETag.pm 1
		    HTTP/Headers/Util.pm 1
		    HTTP/Message.pm 1
		    HTTP/Negotiate.pm 1
		    HTTP/Request.pm 1
		    HTTP/Request/Common.pm 1
		    HTTP/Response.pm 1
		    HTTP/Status.pm 1
		    LWP.pm 1
		    LWP/Authen/Basic.pm 1
		    LWP/Authen/Digest.pm 1
		    LWP/Debug.pm 1
		    LWP/MediaTypes.pm 1
		    LWP/MemberMixin.pm 1
		    LWP/Protocol.pm 1
		    LWP/Protocol/data.pm 1
		    LWP/Protocol/file.pm 1
		    LWP/Protocol/ftp.pm 1
		    LWP/Protocol/gopher.pm 1
		    LWP/Protocol/http.pm 1
		    LWP/Protocol/https.pm 1
		    LWP/Protocol/mailto.pm 1
		    LWP/Protocol/nntp.pm 1
		    LWP/RobotUA.pm 1
		    LWP/Simple.pm 1
		    LWP/UserAgent.pm 1
		    MIME/Body.pm 1
		    MIME/Decoder.pm 1
		    MIME/Decoder/Base64.pm 1
		    MIME/Decoder/Binary.pm 1
		    MIME/Decoder/Gzip64.pm 1
		    MIME/Decoder/NBit.pm 1
		    MIME/Decoder/QuotedPrint.pm 1
		    MIME/Decoder/UU.pm 1
		    MIME/Entity.pm 1
		    MIME/Field/ConTraEnc.pm 1
		    MIME/Field/ContDisp.pm 1
		    MIME/Field/ContType.pm 1
		    MIME/Field/ParamVal.pm 1
		    MIME/Head.pm 1
		    MIME/Parser.pm 1
		    MIME/Parser/Filer.pm 1
		    MIME/Parser/Reader.pm 1
		    MIME/Parser/Results.pm 1
		    MIME/Tools.pm 1
		    MIME/Words.pm 1
		    Net/Cmd.pm 1
		    Net/Config.pm 1
		    Net/Domain.pm 1
		    Net/DummyInetd.pm 1
		    Net/FTP.pm 1
		    Net/FTP/A.pm 1
		    Net/FTP/E.pm 1
		    Net/FTP/I.pm 1
		    Net/FTP/L.pm 1
		    Net/FTP/dataconn.pm 1
		    Net/NNTP.pm 1
		    Net/Netrc.pm 1
		    Net/PH.pm 1
		    Net/POP3.pm 1
		    Net/SMTP.pm 1
		    Net/SNPP.pm 1
		    Net/Time.pm 1
		    Text/Query.pm 1
		    Text/Query/Advanced.pm 1
		    Text/Query/Build.pm 1
		    Text/Query/BuildAdvancedString.pm 1
		    Text/Query/BuildSimpleString.pm 1
		    Text/Query/Optimize.pm 1
		    Text/Query/Parse.pm 1
		    Text/Query/ParseAdvanced.pm 1
		    Text/Query/ParseSimple.pm 1
		    Text/Query/Simple.pm 1
		    Text/Query/Solve.pm 1
		    Text/Query/SolveAdvancedString.pm 1
		    Text/Query/SolveSimpleString.pm 1
		    URI.pm 1
		    URI/Escape.pm 1
		    URI/Heuristic.pm 1
		    URI/URL.pm 1
		    URI/WithBase.pm 1
		    URI/_foreign.pm 1
		    URI/_generic.pm 1
		    URI/_login.pm 1
		    URI/_query.pm 1
		    URI/_segment.pm 1
		    URI/_server.pm 1
		    URI/_userpass.pm 1
		    URI/data.pm 1
		    URI/file.pm 1
		    URI/file/Base.pm 1
		    URI/file/FAT.pm 1
		    URI/file/Mac.pm 1
		    URI/file/OS2.pm 1
		    URI/file/QNX.pm 1
		    URI/file/Unix.pm 1
		    URI/file/Win32.pm 1
		    URI/ftp.pm 1
		    URI/gopher.pm 1
		    URI/http.pm 1
		    URI/https.pm 1
		    URI/ldap.pm 1
		    URI/mailto.pm 1
		    URI/news.pm 1
		    URI/nntp.pm 1
		    URI/pop.pm 1
		    URI/rlogin.pm 1
		    URI/rsync.pm 1
		    URI/snews.pm 1
		    URI/telnet.pm 1
		    WWW/RobotRules.pm 1
		    WWW/RobotRules/AnyDBM_File.pm 1
		    Authen/Krb4.pm 1
		    Bundle/DBD/mysql.pm 1
		    Bundle/DBI.pm 1
		    Crypt/DES.pm 1
		    Crypt/IDEA.pm 1
		    DBD/ADO.pm 1
		    DBD/ExampleP.pm 1
		    DBD/Multiplex.pm 1
		    DBD/NullP.pm 1
		    DBD/Proxy.pm 1
		    DBD/Sponge.pm 1
		    DBD/mysql.pm 1
		    DBI.pm 1
		    DBI/DBD.pm 1
		    DBI/FAQ.pm 1
		    DBI/Format.pm 1
		    DBI/ProxyServer.pm 1
		    DBI/Shell.pm 1
		    DBI/W32ODBC.pm 1
		    Digest.pm 1
		    Digest/HMAC.pm 1
		    Digest/HMAC_MD5.pm 1
		    Digest/HMAC_SHA1.pm 1
		    Digest/MD2.pm 1
		    Digest/MD5.pm 1
		    Digest/SHA1.pm 1
		    HTML/Entities.pm 1
		    HTML/Filter.pm 1
		    HTML/HeadParser.pm 1
		    HTML/LinkExtor.pm 1
		    HTML/Parser.pm 1
		    HTML/TokeParser.pm 1
		    MIME/Base64.pm 1
		    MIME/QuotedPrint.pm 1
		    Math/Cephes.pm 1
		    Math/Cephes/Complex.pm 1
		    Math/Cephes/Fraction.pm 1
		    Mysql.pm 1
		    Mysql/Statement.pm 1
		    SHA.pm 1
		    Safe/Hole.pm 1
		    Win32/DBIODBC.pm 1
		    Algorithm/Diff.pm 1
		    Apache/Constants.pm 1
		    Apache/File.pm 1
		    capa.pm 1
		    CGI.pm 1
		    CGI/Cookie.pm 1
		    Crypt/DES.pm 1
		    DBI.pm 1
		    Fcntl.pm 1
		    File/Copy.pm 1
		    FileHandle.pm 1
		    GDBM_File.pm 1
		    HTML/TokeParser.pm 1
		    HTML/TreeBuilder.pm 1
		    HTTP/Headers.pm 1
		    IO/Socket.pm 1
		    LWP/UserAgent.pm 1
		    Math/Cephes.pm 1
		    Math/Random.pm 1
		    Opcode.pm 1
		    POSIX.pm 1
		    Safe.pm 1
		    Safe/Hole.pm 1
		    Socket.pm 1
		    strict.pm 1
		    Text/Query.pm 1
		    tth.pm 1
		    vars.pm 1
		    );

my $errorflag=0;
foreach my $dep (keys %dependencies) {
    unless ($modules=~/$dep/) {
	print "MISSING $dep\n";
	$errorflag++;
    }
}

unless ($errorflag) {
    print "All perl modules needed by LON-CAPA appear to be present.\n";
}

exit $errorflag;
