9a324495a74044099b986039bd9e912e9912ddd1
[p5sagit/Devel-REPL.git] / lib / Devel / REPL / Plugin / DDS.pm
1 package Devel::REPL::Plugin::DDS;
2
3 use Devel::REPL::Plugin;
4 use Data::Dump::Streamer ();
5
6 around 'format_result' => sub {
7    my $orig = shift;
8    my $self = shift;
9    my @to_dump = @_;
10    my $out;
11    if (@to_dump != 1 || ref $to_dump[0]) {
12       if (@to_dump == 1 && overload::Method($to_dump[0], '""')) {
13          $out = "@to_dump";
14       } else {
15          my $dds = Data::Dump::Streamer->new;
16          $dds->Freezer(sub { "$_[0]"; });
17          $dds->Data(@to_dump);
18          $out = $dds->Out;
19       }
20    } else {
21       $out = $to_dump[0];
22    }
23    $self->$orig($out);
24 };
25
26 1;
27
28 __END__
29
30 =head1 NAME
31
32 Devel::REPL::Plugin::DDS - Format results with Data::Dump::Streamer
33
34 =head1 SYNOPSIS
35
36  # in your re.pl file:
37  use Devel::REPL;
38  my $repl = Devel::REPL->new;
39  $repl->load_plugin('DDS');
40  $repl->run;
41
42  # after you run re.pl:
43  $ map $_*2, ( 1,2,3 )
44  $ARRAY1 = [
45              2,
46              4,
47              6
48            ];
49
50  $
51
52 =cut
53