?? makefile.pl
字號:
# Makefile.PL - my first attempt at making a makefile# and testing/installing a Perl module# Eric Lease Morgan <emorgan@nd.edu># University Libraries of Notre Dame# 12/24/02 - tweaked for version 2.60; added Mail::Send# 08/26/02 - tweaked for version 2.51; added Digest::MD5# 12/08/00 - added configuration file creation# 12/07/00 - first investigations# let's get started; add magicuse ExtUtils::MakeMaker;# check for previously created preferences fileif (-e "preferences") { &getPrefs ("preferences") }# tell them what's going onprint "\nChecking for the existance of necessary modules...\n\n"; # initialize success flagmy $s = 0; # define the necessary modulesmy @modules = (['CGI', 'CGI'], ['DBI', 'DBI'], ['Digest::MD5', 'Digest::MD5'], ['HTTP::Response', 'LWP'], ['HTTP::Request', 'LWP'], ['LWP::UserAgent', 'LWP'], ['Mail::Send', 'Mail::Send'], ['MIME::Entity', 'MIME::Entity'], ['Net::FTP', 'G/GB/GBARR/libnet-1.0703.tar.gz'], ['Text::Wrap', 'M/MU/MUIR/modules/Text-Tabs+Wrap-98.112902.tar.gz'], ['Time::CTime', 'M/MU/MUIR/modules/Time-modules-100.010301.tar.gz'], ['Time::ParseDate', 'M/MU/MUIR/modules/Time-modules-100.010301.tar.gz'], ['URI::Escape', 'URI'], ['URI::URL', 'URI']); # process each modulefor (my $i = 0; $i <= $#modules; $i++) { # extract the elements my $m = $modules[$i][0]; my $u = $modules[$i][1]; print "Checking for $m... "; $@ = ''; eval "require $m;"; if ($@) { print qq{ Oops! The $m module does not seem to be installed.Probably the best way to get this module is by usingthe cpan program. Here's how: 1) Type 'cpan'. 2) At the cpan prompt type 'install $u'. 3) If installation of the module seemed successful then try to install the MyLibrary module again. 4) If the module was not found by cpan or the installation seemed unsuccessful, then try searching for a newer version at the cpan prompt with the command 'i /$m/' and then downloading/installing your best guess. 5) If all else fails, call Eric. If you do not want or can't use the cpan programto install the missing module, then you will have tovisit your nearest CPAN mirror and install it byhand. Visit: http://www.perl.com/CPAN Exiting.\n\n}; # return failure, bummer return 0; } # yeah! else { print "ok\n"; } } # whew; success!$s = 1;# check successif ($s) { # preamble print "\nAll necessary modules seem to be installed. Whew!\n"; print "\nWe now need to create a tiny configuration file for testing.\n"; # redefine success; sounds like a management vision thing $s = 0; # get the host print << 'EOM';What is the name of the computer where your MyLibrarydatabase resides? If the host is the same host where yourMyLibrary service resides, then enter 'localhost',otherwise, enter the full name of the remote computer (ex:localhost or my.example.edu).EOM my $host = prompt(' Host? ', $PREFS{host} ? $PREFS{host} : 'localhost'); # database print << 'EOM';What is the name of the database containing yourMyLibrary data?EOM my $database = prompt(' Database? ', $PREFS{database} ? $PREFS{database} : 'mylibrary'); ENGINE: # engine print << 'EOM';As of version 2.60 of MyLibrary.pm, the system supports twodatabase engines: MySQL and PostgreSQL. Select thedatabase engine you are using and this script will create aDBI data source connection string for you based on thevalues of database host and database, above: 1) MySQL 2) PostgreSQL EOM my $engine = prompt (' Engine? ', $PREFS{engine} ? $PREFS{engine} : '1'); # build data source string if ($engine == 1) { $data_source = "DBI:mysql:$database:$host" } elsif ($engine == 2) { $data_source = "DBI:Pg:dbname=$database;host=$host" } else { print << 'EOM';Oops! Invalid value for database engine. Validvalues are currently 1 or MySQL or 2 for PostgreSQL.Please try again.EOM prompt(' Press return to continue.'); goto ENGINE } # username print << 'EOM';What is the username that will be accessing the MyLibrarydatabase?EOM my $username = prompt(' Username? ', $PREFS{username} ? $PREFS{username} : ''); # password print << 'EOM';What is the password of username?EOM my $password = prompt(' Password? ', $PREFS{password} ? $PREFS{password} : ''); # save preferences file open (PREFS, "> preferences") || die "Can't open preferences: $!. Call Eric."; print PREFS << "EOPREFS";host = $hostdatabase = $databaseusername = $usernamepassword = $passwordengine = $engineEOPREFS close PREFS; # write configuration file open (CONFIG, "> test.cfg") || die "Can't open test.cfg: $!. Call Eric."; print CONFIG << "EOCONFIG";username = $usernamepassword = $passworddata_source = $data_sourceEOCONFIG close CONFIG; # done print "\nPreferneces and configuration files have been created.\n\n"; $s = 1; }# check successif ($s) { # write makefile WriteMakefile('NAME' => 'MyLibrary', 'VERSION_FROM' => 'MyLibrary.pm', 'DISTNAME' => 'MyLibrary-module',); print "\nDone. Now you must: 1) type 'make' 2) type 'make test', and finally 3) type 'make install'.\n\n";}sub getPrefs { print "\nAh ha! I see this isn't your first time through.\n"; print "Reading preferences..."; my $prefs = @_[0]; # read configuration file open (PREFS, "< $prefs"); while (<PREFS>) { # process each line chomp; s/#.*//; s/^\s+//; s/\s+$//; next unless length; my ($var, $value) = split(/\s*=\s*/, $_, 2); # save the name/value pairs to a hash $PREFS{$var} = $value; } close PREFS; print "done.\n";}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -