File: CleanErrors.pm

package info (click to toggle)
libpdl-perldl2-perl 2.002-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 172 kB
  • sloc: perl: 416; makefile: 2
file content (60 lines) | stat: -rw-r--r-- 1,410 bytes parent folder | download | duplicates (2)
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
package PDL::Perldl2::Plugin::CleanErrors;

use strict;
use warnings;
use Devel::REPL::Plugin;

use namespace::clean -except => [ 'meta' ];

around 'error_return' => sub {
   my ($orig, $self) = (shift, shift);
   my ($type, $error) = @_;

   return $orig->($self, $type, clean_error_string($error));
};

# filter out the Devel::REPL, Class::MOP, ... from pdl2 errors
sub clean_error_string {
   my $bigerr = $_[0];
   $bigerr =~ s/^\s+Devel::REPL.*$//ms;
   $bigerr =~ s/^\s+Class::MOP.*$//ms;
   $bigerr =~ s/^\s+Lexical::Persistence.*$//ms;
   $bigerr =~ s/^\s+main::.*$//ms;
   $bigerr =~ s/^\s+eval \{.*$//ms;
   $bigerr =~ s/^\s+PDL::Core::barf.*$//ms;
   return $bigerr;
}

1;

__END__

=head1 NAME

PDL::Perldl2::Plugin::CleanErrors - filter out Moose cruft

=head1 DESCRIPTION

Runtime errors in pdl2 are extremely verbose since they
include the entire call chain from the start of the interactive
Devel::REPL shell, through the Moose and Class::MOP stuff and
including Lexical::Persistence as well.  This plugin, which
is loaded by default, strips out the non-PDL stuff to make the
error messages much more concise.

=head1 SEE ALSO

C<Devel::REPL>

=head1 AUTHOR

Chris Marshall, C<< <chm at cpan dot org> >>

=head1 COPYRIGHT AND LICENSE

Copyright (C) 2011 by Christopher Marshall

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.

=cut