diff --git a/lib/Devel/Trepan/CmdProcessor.pm b/lib/Devel/Trepan/CmdProcessor.pm index e573770..5f22b16 100644 --- a/lib/Devel/Trepan/CmdProcessor.pm +++ b/lib/Devel/Trepan/CmdProcessor.pm @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright (C) 2011, 2012 Rocky Bernstein +# Copyright (C) 2011-2013 Rocky Bernstein use rlib '../..'; @@ -14,13 +14,6 @@ use warnings; no warnings 'redefine'; use vars qw(@EXPORT @ISA $eval_result); # Showing eval results can be done using either data dump package. -use if !@ISA, Data::Dumper; - -# Eval does uses its own variables. -# FIXME: have a way to customize Data:Dumper, PerlTidy etc. -$Data::Dumper::Terse = 1; -require Data::Dumper; - unless (@ISA) { require Devel::Trepan::CmdProcessor::Load; require Devel::Trepan::BrkptMgr; diff --git a/lib/Devel/Trepan/CmdProcessor/Command/Set_Subcmd/Display_Subcmd/Eval.pm b/lib/Devel/Trepan/CmdProcessor/Command/Set_Subcmd/Display_Subcmd/Eval.pm index 9758bf7..6f34651 100644 --- a/lib/Devel/Trepan/CmdProcessor/Command/Set_Subcmd/Display_Subcmd/Eval.pm +++ b/lib/Devel/Trepan/CmdProcessor/Command/Set_Subcmd/Display_Subcmd/Eval.pm @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright (C) 2011, 2012 Rocky Bernstein +# Copyright (C) 2011-2013 Rocky Bernstein use warnings; no warnings 'redefine'; no warnings 'once'; use rlib '../../../../../..'; @@ -17,15 +17,18 @@ our $CMD = 'set display eval'; my @DISPLAY_TYPES = @Devel::Trepan::CmdProcessor::DISPLAY_TYPES; my $param = join('|', @DISPLAY_TYPES); our $HELP = <<"HELP"; -${CMD} \{$param\} +=pod + +B {B|B|B} Set how you want the evaluation results shown. -The 'tidy' option sets to use Data::Dumper::Perltidy. 'dumper' uses -Data::Dumper. When the Data::Printer module is installed, -'dprint' specifies using that. +The I option sets to use L; I uses +L. When the L is installed, +I specifies using that. -See also 'show display eval', 'eval', and 'set autoeval'. +See also C, C, and C. +=cut HELP our $MIN_ABBREV = length('ev'); diff --git a/lib/Devel/Trepan/CmdProcessor/Eval.pm b/lib/Devel/Trepan/CmdProcessor/Eval.pm index 5ccf9fe..340c9a2 100644 --- a/lib/Devel/Trepan/CmdProcessor/Eval.pm +++ b/lib/Devel/Trepan/CmdProcessor/Eval.pm @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright (C) 2012 Rocky Bernstein +# Copyright (C) 2012-2013 Rocky Bernstein use warnings; use rlib '../../..'; @@ -8,6 +8,8 @@ use Devel::Trepan::Util qw(hash_merge uniq_abbrev); use PadWalker qw(peek_my peek_our); use strict; +# Note DB::Eval uses and sets its own variables. + use vars qw($HAVE_EVAL_WITH_LEXICALS); BEGIN { $HAVE_EVAL_WITH_LEXICALS = eval("use Eval::WithLexicals; 1") ? 1 : 0; @@ -77,6 +79,11 @@ sub eval($$$$$) { } } +# FIXME: have a way to customize Data::Dumper, PerlTidy etc. +require Data::Dumper; +# FIXME: remove this when converted to OO forms of Data::Dumper +$Data::Dumper::Terse = 1; + my $last_eval_value = 0; sub handle_eval_result($) { @@ -91,6 +98,15 @@ sub handle_eval_result($) { my $fn; my $print_properties = {}; my $evdisp = $self->{settings}{displayeval}; + + # FIXME: switch over entirely to the OO way of using Data::Dumper + # than set this global. + my $old_terse = $Data::Dumper::Terse; + $Data::Dumper::Terse = 1; + + + # FIXME: this is way ugly. We could probably use closures + # (anonymous subroutines) to combine this and the if code below if ('tidy' eq $evdisp) { $fn = \&Data::Dumper::Perltidy::Dumper; } elsif ('dprint' eq $evdisp) { @@ -128,7 +144,15 @@ sub handle_eval_result($) { $self->msg("$prefix\n\@\{$val_str}"); } elsif ('%' eq $return_type) { if (%DB::eval_result) { - $val_str = $fn->(\%DB::eval_result, %$print_properties); + if ('dumper' eq $evdisp) { + my $d = Data::Dumper->new([\%DB::eval_result]); + $d->Terse(1)->Sortkeys(1); + $val_str = $d->Dump() + } elsif ('dprint' eq $evdisp) { + $val_str = $fn->(\%DB::eval_result, %$print_properties); + } else { + $val_str = $fn->(\%DB::eval_result); + } chomp $val_str; @{$DB::D[$last_eval_value++]} = %DB::eval_result; } else { @@ -163,6 +187,9 @@ sub handle_eval_result($) { }; $DB::eval_result = undef; @DB::eval_result = undef; + + $Data::Dumper::Terse = $old_terse; + } unless (caller) {