summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2013-07-05 16:38:37 -0400
committerJesse Luehrs <doy@tozt.net>2013-07-05 16:38:37 -0400
commit0d94442be3eb8dff98a5e429768af2a681389939 (patch)
treeffc2d92816ce1444b4c1128bb74f6d7f41e1ad5b /lib
parentb0c20052b1a6db347d9fe777ee7e554bad31112a (diff)
downloadreply-0d94442be3eb8dff98a5e429768af2a681389939.tar.gz
reply-0d94442be3eb8dff98a5e429768af2a681389939.zip
make the DataDump plugin respect stringification overload by default
Diffstat (limited to 'lib')
-rw-r--r--lib/Reply/Plugin/DataDump.pm25
1 files changed, 23 insertions, 2 deletions
diff --git a/lib/Reply/Plugin/DataDump.pm b/lib/Reply/Plugin/DataDump.pm
index 64d756e..a020adb 100644
--- a/lib/Reply/Plugin/DataDump.pm
+++ b/lib/Reply/Plugin/DataDump.pm
@@ -5,7 +5,8 @@ use warnings;
use base 'Reply::Plugin';
-use Data::Dump 'pp';
+use Data::Dump 'dumpf';
+use overload ();
=head1 SYNOPSIS
@@ -18,10 +19,30 @@ This plugin uses L<Data::Dump> to format results.
=cut
+sub new {
+ my $class = shift;
+ my %opts = @_;
+ $opts{respect_stringification} = 1
+ unless defined $opts{respect_stringification};
+
+ my $self = $class->SUPER::new(@_);
+ $self->{filter} = sub {
+ my ($ctx, $ref) = @_;
+ return unless $ctx->is_blessed;
+ my $stringify = overload::Method($ref, '""');
+ return unless $stringify;
+ return {
+ dump => $stringify->($ref),
+ };
+ } if $opts{respect_stringification};
+
+ return $self;
+}
+
sub mangle_result {
my $self = shift;
my (@result) = @_;
- return @result ? pp(@result) : ();
+ return @result ? dumpf(@result, $self->{filter}) : ();
}
1;