From: John Graham-C. <jgr...@us...> - 2004-11-30 21:13:12
|
Update of /cvsroot/popfile/engine In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4256 Modified Files: Makefile popfile.pl Added Files: popfile.pck make_packing_list.pl Log Message: Added support for a 'packing list' that can check POPFile's configuration on start up and warn (in the log file) or error about optional or required modules Index: popfile.pl =================================================================== RCS file: /cvsroot/popfile/engine/popfile.pl,v retrieving revision 1.223 retrieving revision 1.224 diff -C2 -d -r1.223 -r1.224 *** popfile.pl 28 Jul 2004 14:16:59 -0000 1.223 --- popfile.pl 30 Nov 2004 21:13:01 -0000 1.224 *************** *** 31,39 **** # ---------------------------------------------------------------------------- use strict; use locale; - use lib defined($ENV{POPFILE_ROOT})?$ENV{POPFILE_ROOT}:'./'; - use POPFile::Loader; --- 31,74 ---- # ---------------------------------------------------------------------------- + # Check the packing list of POPFile to ensure that all the required + # modules are present. + + my $packing_list = 'popfile.pck'; + my $fatal = 0; + my $log = ''; + + if ( open PACKING, "<$packing_list" ) { + while (<PACKING>) { + if ( /^(REQUIRED|OPTIONAL-([^\t]+))\t([^\t]+)\t([^\r\n]+)/ ) { + my ( $required, $why, $version, $module ) = ( $1, $2, $3, $4 ); + + # Find the module and set $ver to the loaded version, or -1 if + # the module was not found + + local $::SIG{__DIE__}; + local $::SIG{__WARN__}; + eval "require $module"; + my $ver = ${"${module}::VERSION"} || ${"${module}::VERSION"} || 0; + $ver = ${"${module}::VERSION"} || ${"${module}::VERSION"} || 0; + $ver = -1 if $@; + + if ( $ver == -1 ) { + if ( $required eq 'REQUIRED' ) { + $fatal = 1; + print STDERR "ERROR: POPFile needs Perl module $module, please install it.\n"; + } else { + $log .= "WARNING: POPFile may require Perl module $module; it is needed for \"$why\".\n"; + } + } + } + } + close PACKING; + } else { + $log .= "WARNING: Couldn't open POPFile packing list ($packing_list) so cannot check configuration\n"; + } + use strict; use locale; use lib defined($ENV{POPFILE_ROOT})?$ENV{POPFILE_ROOT}:'./'; use POPFile::Loader; *************** *** 65,68 **** --- 100,110 ---- $POPFile->CORE_start(); + # If there were any log messages from the packing list check then + # log them now + + if ( $log ne '' ) { + $POPFile->get_module( 'POPFile::Logger' )->debug( 0, $log ); + } + # This is the main POPFile loop that services requests, it will # exit only when we need to exit Index: Makefile =================================================================== RCS file: /cvsroot/popfile/engine/Makefile,v retrieving revision 1.38 retrieving revision 1.39 diff -C2 -d -r1.38 -r1.39 *** Makefile 31 Aug 2004 13:58:20 -0000 1.38 --- Makefile 30 Nov 2004 21:13:01 -0000 1.39 *************** *** 142,143 **** --- 142,150 ---- @echo $(POPFILE_REVISION) >> $@ + # Make's the POPFile packing list + + .PHONY: packing popfile.pck + packing: popfile.pck + + popfile.pck: popfile.pl bayes.pl pipe.pl insert.pl Classifier/*.pm POPFile/*.pm Proxy/*.pm Services/*.pm UI/*.pm + @perl make_packing_list.pl $@ $? --- NEW FILE: popfile.pck --- REQUIRED 0.0.0 Date::Format REQUIRED 0.0.0 Date::Parse REQUIRED 0.0.0 Digest::MD5 OPTIONAL-Japanese Language Support 0.0.0 Encode::Guess REQUIRED 0.0.0 Getopt::Long REQUIRED 0.0.0 HTML::Tagset REQUIRED 0.0.0 HTML::Template REQUIRED 0.0.0 IO::Handle REQUIRED 0.0.0 IO::Select REQUIRED 0.0.0 IO::Socket REQUIRED 0.0.0 IO::Socket::INET OPTIONAL-SSL Connection Support 0.0.0 IO::Socket::SSL OPTIONAL-Socks Proxy Support 0.0.0 IO::Socket::Socks REQUIRED 0.0.0 MIME::Base64 REQUIRED 0.0.0 MIME::QuotedPrint REQUIRED 0.0.0 Sys::Hostname OPTIONAL-Japanese Language Support 0.0.0 Text::Kakasi REQUIRED 0.0.0 UI::HTTP OPTIONAL-XMLRPC Interface 0.0.0 XMLRPC::Transport::HTTP --- NEW FILE: make_packing_list.pl --- #!/usr/bin/perl # ---------------------------------------------------------------------------- # # make_packing_list.pl # # Builds the POPFile packing list of required modules # # Copyright (c) 2001-2004 John Graham-Cumming # # This file is part of POPFile # # POPFile is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # POPFile is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with POPFile; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # Modified by Sam Schinke (ssc...@us...) # # ---------------------------------------------------------------------------- use strict; # Hash that maps a module name (e.g. Foo::Bar) to either REQUIRED # or optional. A module is REQUIRED if it is in a use statement and # OPTIONAL if it is in a require. my %modules; # ARGV should contain the name of the packing list to generate # followed by a list of files to search for use statements. my $output = shift @ARGV; foreach my $file (@ARGV) { scan_file( $file ); } open PACKAGE, ">$output"; foreach my $module (sort keys %modules) { if ( $module !~ /^Classifier|POPFile|Proxy/ ) { print PACKAGE "$modules{$module}\t0.0.0\t$module\n"; } } close PACKAGE; # --------------------------------------------------------------------------- # # scan_file # # Look in a file for require and use statements and update the %modules # hash # # --------------------------------------------------------------------------- sub scan_file { my ( $file ) = @_; if ( open FILE, "<$file" ) { while ( <FILE> ) { if ( /^[ \t]*require[ \t]+([^ \t]+::[^ \t\r\n;]+)/ ) { $modules{$1} = 'OPTIONAL-TODO'; next; } if ( /^[ \t]*use[ \t]+([^ \t]+::[^ \t\r\n;]+)/ ) { $modules{$1} = 'REQUIRED'; next; } } close FILE; } } |