From c92dddcbac622bd6462daff812d73685ad8a2a75 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Tue, 21 Jun 2011 10:22:25 +0200 Subject: [PATCH] =?utf8?q?Funktion=20f=C3=BCr=20unified=20diff=20zweier=20?= =?utf8?q?Objekte/Strings=20in=20Debugausgabe?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/LXDebug.pm | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) 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; -- 2.20.1