blob: 51cd4fcaace01035ee73a6ea709817ccbe3b1a1f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
package main;
use strict;
use warnings;
# ABSTRACT: display error stack traces only on demand
use mop;
{
local @SIG{qw(__DIE__ __WARN__)};
require Carp::Always;
}
=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
class Reply::Plugin::CollapseStack extends Reply::Plugin {
has $num_lines = 1;
has $full_error;
method compile ($next, @args) {
local $SIG{__DIE__} = \&Carp::Always::_die;
$next->(@args);
}
method execute ($next, @args) {
local $SIG{__DIE__} = \&Carp::Always::_die;
$next->(@args);
}
method mangle_error ($error) {
$full_error = $error;
my @lines = split /\n/, $error;
if (@lines > $num_lines) {
splice @lines, $num_lines;
$error = join "\n", @lines,
" (Run #stack to see the full trace)\n";
}
return $error;
}
method command_stack {
# XXX should use print_error here
print($self->{full_error} || "No stack to display.\n");
return '';
}
}
=for Pod::Coverage
command_stack
=cut
1;
|