CIPP

 view release on metacpan or  search on metacpan

lib/CIPP/Runtime.pm  view on Meta::CPAN

# $Id: Runtime.pm,v 1.2 2004/05/11 08:59:36 joern Exp $

package CIPP::Runtime;

$REVISION = q$Revision: 1.2 $;
$VERSION = "0.42";

use strict;
use FileHandle;
use Cwd;
use Carp;

sub debug {
	return;

	my @c = caller(1);
	$c[3] =~ m!::([^:]+)$!;
	my $sub = $1;
	$0 =~ m!/([^/]+)$!;
	my $file = $1;
	print STDERR "$$ $file\t$sub\t$_[0]\n";
}

sub init_request {
	return;
	use Cwd;
	debug("cwd=".cwd());
	debug("base config was: $cipp::back_prod_path/config/cipp.conf");
	debug("CIPP_Exec::cipp_config_dir=$CIPP_Exec::cipp_config_dir");
	debug("INC: ", join(",",@::INC));
}

sub Read_Config {
	my ($filename, $nocache) = @_;

	$nocache = 1;

	confess "CONFIG\tFile '$filename' not found\n".
		"working directory:".cwd()."\n".
		"\@INC = ".(join(",",@::INC))."\n"
		if not -f $filename;
	
	my $file_timestamp = (stat($filename))[9];
	
	if ( $nocache or not defined $CIPP::Runtime::cfg_timestamp{$filename} or
	     $CIPP::Runtime::cfg_timestamp{$filename} < $file_timestamp ) {
		my $fh = new FileHandle;
		open ($fh, $filename);
		eval join ('', "no strict;\n", <$fh>)."\n1;";
		confess "CONFIG\t$@" if $@;
		close $fh;
		$CIPP::Runtime::cfg_timestamp{$filename} = $file_timestamp;
		debug($filename);
	}
}

sub Exception {
	my ($die_message) = @_;

	my (@type) = split ("\t", $die_message);

	my $message = pop @type;

	if ( (scalar @type) == 0 ) {
		push @type, "general";
	}

	my $type = join ("::", @type);

	my $log_error = Log ("EXC", "TYPE=$type, MESSAGE=$message");
	if ( $log_error ) {
		$message .= "<P><BR><B>Unable to add this exception to the logfile!</B><BR>\n";
		$message .= "=> $log_error";
	}
	print "Content-type: text/html\n\n" if ! $CIPP_Exec::cipp_http_header_printed;
	print "<P>$CIPP_Exec::cipp_error_text<P>";

	if ( $CIPP_Exec::cipp_error_show ) {
		print "<P><B>EXCEPTION: </B>$type<BR>\n",
		      "<B>MESSAGE: </B>$message<P>\n";
		if ( $message =~ /compilation errors/ ) {
			print "<P>You will find the compiler error messages in the webserver error log<P>\n";
		}
	}

	eval {
		confess "CIPP::Runtime version $CIPP::Runtime::VERSION\nSTACK-BACKTRACE";
	};
	my $stack_trace = $@;
	Log ("EXC", "trace: $stack_trace");
	Log ("EXC", "INC:".join(",",@INC));

	if ( $CIPP_Exec::cipp_error_show ) {
		print "<p><pre>$stack_trace</pre>\n";
	}

	Close_Database_Connections();
#	die "TYPE=$type MESSAGE=$message";
}


sub Log {
	my ($type, $message, $filename, $throw) = @_;



( run in 2.591 seconds using v1.01-cache-2.11-cpan-99c4e6809bf )