Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

CmdProcessor/Eval.pm: make sure to sort hash keys. Display_Subcmd/Eva…

…l.pm: podize help

CmdProcessor.pm: simplify slightly
  • Loading branch information...
commit 2e106ad229bb99a4d0f4e974541b391656ea7af8 1 parent cd87fea
Rocky Bernstein authored
View
9 lib/Devel/Trepan/CmdProcessor.pm
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
-# Copyright (C) 2011, 2012 Rocky Bernstein <rocky@cpan.org>
+# Copyright (C) 2011-2013 Rocky Bernstein <rocky@cpan.org>
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;
View
15 lib/Devel/Trepan/CmdProcessor/Command/Set_Subcmd/Display_Subcmd/Eval.pm
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
-# Copyright (C) 2011, 2012 Rocky Bernstein <rocky@cpan.org>
+# Copyright (C) 2011-2013 Rocky Bernstein <rocky@cpan.org>
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<set display> {B<dumper>|B<dprint>|B<tidy>}
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<tidy> option sets to use L<Data::Dumper::Perltidy>; I<dumper> uses
+L<Data::Dumper>. When the L<Data::Printer module> is installed,
+I<dprint> specifies using that.
-See also 'show display eval', 'eval', and 'set autoeval'.
+See also C<show display eval>, C<eval>, and C<set autoeval>.
+=cut
HELP
our $MIN_ABBREV = length('ev');
View
31 lib/Devel/Trepan/CmdProcessor/Eval.pm
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
-# Copyright (C) 2012 Rocky Bernstein <rocky@cpan.org>
+# Copyright (C) 2012-2013 Rocky Bernstein <rocky@cpan.org>
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) {
Please sign in to comment.
Something went wrong with that request. Please try again.