From: Moritz Bunkus Date: Wed, 25 Apr 2007 11:27:20 +0000 (+0000) Subject: Den zuletzt implementierten Mechanismus entfernt, um $form-Variablen zu überwachen... X-Git-Tag: release-2.4.3^2~451 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=e7191bc2818007bf58cec5e2167e977904f0ac44;p=kivitendo-erp.git Den zuletzt implementierten Mechanismus entfernt, um $form-Variablen zu überwachen, und dafür einen neuen Mechanismus implementiert, der auf tie basiert. Dadurch ist es möglich, immer die exakte Zeilennummer zu erfahren, in der eine Variable geändert wird. --- diff --git a/SL/Form.pm b/SL/Form.pm index 79a075f12..0718a83ff 100644 --- a/SL/Form.pm +++ b/SL/Form.pm @@ -132,6 +132,11 @@ sub new { my $self = {}; + if ($LXDebug::watch_form) { + require SL::Watchdog; + tie %{ $self }, 'SL::Watchdog'; + } + read(STDIN, $_, $ENV{CONTENT_LENGTH}); if ($ENV{QUERY_STRING}) { diff --git a/SL/LXDebug.pm b/SL/LXDebug.pm index 4bb420398..8a4dd2923 100644 --- a/SL/LXDebug.pm +++ b/SL/LXDebug.pm @@ -15,11 +15,15 @@ use POSIX qw(strftime); my $data_dumper_available; +our $global_level; +our $watch_form; + BEGIN { eval("use Data::Dumper"); $data_dumper_available = $@ ? 0 : 1; $global_level = NONE; + $watch_form = 0; } sub new { @@ -30,7 +34,6 @@ sub new { $self->{"file"} = "/tmp/lx-office-debug.log"; $self->{"target"} = FILE_TARGET; $self->{"level"} = 0; - $self->{"watchedvars"} = {}; while ($_[0]) { $self->{ $_[0] } = $_[1]; @@ -57,8 +60,6 @@ sub enter_sub { my ($self, $level) = @_; $level *= 1; - $self->check_watched_form_variables(); - return 1 unless ($global_level & TRACE); # ignore if traces aren't active return 1 if $level && !($global_level & $level); # ignore if level of trace isn't active @@ -82,8 +83,6 @@ sub leave_sub { my ($self, $level) = @_; $level *= 1; - $self->check_watched_form_variables(); - return 1 unless ($global_level & TRACE); # ignore if traces aren't active return 1 if $level && !($global_level & $level); # ignore if level of trace isn't active @@ -103,7 +102,6 @@ sub leave_sub { sub message { my ($self, $level, $message) = @_; - $self->check_watched_form_variables(); $self->_write(level2string($level), $message) if (($self->{"level"} | $global_level) & $level || !$level); } @@ -151,26 +149,4 @@ sub level2string { join '/', qw(info debug1 debug2 query trace)[ grep { (reverse split //, sprintf "%05b", $_[0])[$_] } 0..4 ] } -sub watch_form_variable { - my ($self, $var) = @_; - - $self->{"watchedvars"}->{$var} = $main::form->{$var}; - $self->_write("WATCH", "Adding \$form->{$var} with current value \"$main::form->{$var}\""); -} - -sub check_watched_form_variables { - my ($self) = @_; - - return unless $main::form; - - foreach my $var (sort(keys(%{ $self->{"watchedvars"} }))) { - if ($main::form->{$var} ne $self->{"watchedvars"}->{$var}) { - $self->_write("WATCH", "Variable \$form->{$var} changed from \"" . - $self->{"watchedvars"}->{$var} . "\" to \"" . - $main::form->{$var} . "\""); - $self->{"watchedvars"}->{$var} = $main::form->{$var}; - } - } -} - 1; diff --git a/SL/Watchdog.pm b/SL/Watchdog.pm new file mode 100644 index 000000000..3aac6532b --- /dev/null +++ b/SL/Watchdog.pm @@ -0,0 +1,38 @@ +package SL::Watchdog; + +use Data::Dumper; + +require Tie::Hash; + +@ISA = (Tie::StdHash); + +my %watched_variables; + +sub STORE { + my ($this, $key, $value) = @_; + + if (substr($key, 0, 10) eq "Watchdog::") { + substr $key, 0, 10, ""; + $watched_variables{$key} = $value; + if ($value) { + $main::lxdebug->_write("WATCH", "Starting to watch '$key' with current value '$this->{$key}'"); + } else { + $main::lxdebug->_write("WATCH", "Stopping to watch '$key'"); + } + return; + + } + + if ($watched_variables{$key} + && ($this->{$key} ne $value)) { + my $subroutine = (caller 1)[3]; + my ($self_filename, $self_line) = (caller)[1, 2]; + $main::lxdebug->_write("WATCH", + "Value of '$key' changed from '$this->{$key}' to '$value' " + . "in ${subroutine} at ${self_filename}:${self_line}"); + } + + $this->{$key} = $value; +} + +1; diff --git a/lx-erp.conf b/lx-erp.conf index 85291943a..8ab6ce8d1 100644 --- a/lx-erp.conf +++ b/lx-erp.conf @@ -1,5 +1,5 @@ use Cwd; -use vars qw($userspath $spool $memberfile $templates $sendmail $language $sid $latex $eur $webdav $lizenzen $jscalendar); +use vars qw($userspath $spool $memberfile $templates $sendmail $language $sid $latex $eur $webdav $lizenzen $jscalendar $watch_form_variables); # path to user configuration files $userspath = "users"; @@ -81,7 +81,14 @@ $dbcharset = "ISO-8859-15"; # # Beipiel: # $LXDebug::global_level = LXDebug::TRACE | LXDebug::QUERY; -$LXDebug::global_level = LXDebug::ALL; +$LXDebug::global_level = LXDebug::NONE; + +# Überwachung der Inhalte von $form aktiviert oder nicht? Wenn ja, +# dann können einzelne Variablen mit +# $form->{"Watchdog::"} = 1; +# überwacht werden. Bedeutet aber auch einen Geschwindigkeitsverlust, +# weshalb sie normalerweise deaktiviert ist. +$LXDebug::watch_form = 0; 1;