summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShawn M Moore <code@sartak.org>2013-07-08 10:22:44 -0400
committerJesse Luehrs <doy@tozt.net>2013-07-08 15:09:07 -0400
commit300de51cc0c82e0e50116e6997046679784b598d (patch)
tree4b7ac09e5bcdd505784efee4cbdec403dcdfe7cc
parent45ffcf36261fced19826f3b5607be3790b5f9ad5 (diff)
downloadreply-300de51cc0c82e0e50116e6997046679784b598d.tar.gz
reply-300de51cc0c82e0e50116e6997046679784b598d.zip
New CollapseStack plugin
-rw-r--r--lib/Reply/Plugin/CollapseStack.pm64
1 files changed, 64 insertions, 0 deletions
diff --git a/lib/Reply/Plugin/CollapseStack.pm b/lib/Reply/Plugin/CollapseStack.pm
new file mode 100644
index 0000000..539effe
--- /dev/null
+++ b/lib/Reply/Plugin/CollapseStack.pm
@@ -0,0 +1,64 @@
+package Reply::Plugin::CollapseStack;
+use strict;
+use warnings;
+# ABSTRACT: display error stack traces only on demand
+
+use base 'Reply::Plugin';
+
+=head1 SYNOPSIS
+
+ ; .replyrc
+ [CollapseStack]
+ num_lines = 1
+
+=head1 DESCRIPTION
+
+This plugin hides stack traces until you specifically request them
+with the C<#stack> command.
+
+The number of lines of stack to always show is configurable; specify
+the C<num_lines> option.
+
+=cut
+
+sub new {
+ my $class = shift;
+ my %opts = @_;
+
+ my $self = $class->SUPER::new(@_);
+ $self->{num_lines} = $opts{num_lines} || 1;
+
+ return $self;
+}
+
+sub mangle_error {
+ my $self = shift;
+ my $error = shift;
+
+ $self->{full_error} = $error;
+
+ my @lines = split /\n/, $error;
+ if (@lines > $self->{num_lines}) {
+ splice @lines, $self->{num_lines};
+ $error = join "\n", @lines, " (Run #stack to see the full trace)";
+ }
+
+ return $error;
+}
+
+sub command_stack {
+ my $self = shift;
+
+ # XXX should use print_error here
+ print($self->{full_error} || "No stack to display.\n");
+
+ return '';
+}
+
+=for Pod::Coverage
+ command_stack
+
+=cut
+
+1;
+