Skip to content

Commit

Permalink
CmdProcessor/Eval.pm: make sure to sort hash keys. Display_Subcmd/Eva…
Browse files Browse the repository at this point in the history
…l.pm: podize help

CmdProcessor.pm: simplify slightly
  • Loading branch information
Rocky Bernstein committed Jan 1, 2013
1 parent cd87fea commit 2e106ad
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 16 deletions.
9 changes: 1 addition & 8 deletions 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 '../..';

Expand All @@ -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;
Expand Down
@@ -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 '../../../../../..';

Expand All @@ -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');
Expand Down
31 changes: 29 additions & 2 deletions 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 '../../..';

Expand All @@ -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;
Expand Down Expand Up @@ -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($) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -163,6 +187,9 @@ sub handle_eval_result($) {
};
$DB::eval_result = undef;
@DB::eval_result = undef;

$Data::Dumper::Terse = $old_terse;

}

unless (caller) {
Expand Down

0 comments on commit 2e106ad

Please sign in to comment.