File: CollapseStack.pm

package info (click to toggle)
libreply-perl 0.35-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 276 kB
  • ctags: 130
  • sloc: perl: 1,425; makefile: 2
file content (113 lines) | stat: -rw-r--r-- 1,915 bytes parent folder | download
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package Reply::Plugin::CollapseStack;
BEGIN {
  $Reply::Plugin::CollapseStack::AUTHORITY = 'cpan:DOY';
}
$Reply::Plugin::CollapseStack::VERSION = '0.35';
use strict;
use warnings;
# ABSTRACT: display error stack traces only on demand

use base 'Reply::Plugin';

{
    local @SIG{qw(__DIE__ __WARN__)};
    require Carp::Always;
}


sub new {
    my $class = shift;
    my %opts = @_;

    my $self = $class->SUPER::new(@_);
    $self->{num_lines} = $opts{num_lines} || 1;

    return $self;
}

sub compile {
    my $self = shift;
    my ($next, @args) = @_;

    local $SIG{__DIE__} = \&Carp::Always::_die;
    $next->(@args);
}

sub execute {
    my $self = shift;
    my ($next, @args) = @_;

    local $SIG{__DIE__} = \&Carp::Always::_die;
    $next->(@args);
}

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)\n";
    }

    return $error;
}

sub command_stack {
    my $self = shift;

    # XXX should use print_error here
    print($self->{full_error} || "No stack to display.\n");

    return '';
}


1;

__END__

=pod

=encoding UTF-8

=head1 NAME

Reply::Plugin::CollapseStack - display error stack traces only on demand

=head1 VERSION

version 0.35

=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.

=for Pod::Coverage command_stack

=head1 AUTHOR

Jesse Luehrs <doy@tozt.net>

=head1 COPYRIGHT AND LICENSE

This software is Copyright (c) 2014 by Jesse Luehrs.

This is free software, licensed under:

  The MIT (X11) License

=cut