From: Moritz Bunkus Date: Tue, 21 Jun 2011 08:22:25 +0000 (+0200) Subject: Funktion für unified diff zweier Objekte/Strings in Debugausgabe X-Git-Tag: release-2.7.0beta1~372 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=c92dddcbac622bd6462daff812d73685ad8a2a75;p=kivitendo-erp.git Funktion für unified diff zweier Objekte/Strings in Debugausgabe --- diff --git a/SL/LXDebug.pm b/SL/LXDebug.pm index 4e7790791..397b179ef 100644 --- a/SL/LXDebug.pm +++ b/SL/LXDebug.pm @@ -21,7 +21,7 @@ use YAML; use strict; -my $data_dumper_available; +my ($data_dumper_available, $text_diff_available); our $global_level; our $watch_form; @@ -219,6 +219,24 @@ sub dump_sql_result { $self->message($level, $prefix . sprintf('(%d row%s)', scalar @{ $results }, scalar @{ $results } > 1 ? 's' : '')); } +sub show_diff { + my ($self, $level, $item1, $item2, %params) = @_; + + if (!$self->_load_text_diff) { + $self->warn("Perl module Text::Diff is not available"); + return; + } + + my @texts = map { ref $_ ? YAML::Dump($_) : $_ } ($item1, $item2); + + $self->message($level, Text::Diff::diff(\$texts[0], \$texts[1], \%params)); +} + +sub _load_text_diff { + $text_diff_available = eval("use Text::Diff (); 1;") ? 1 : 0 unless defined $text_diff_available; + return $text_diff_available; +} + sub enable_sub_tracing { my ($self) = @_; $global_level |= TRACE;