| 1 | use strict; | ||
| 2 | use warnings; | ||
| 3 | package Exception::Reporter::Summarizer::MooseException; | ||
| 4 | # ABSTRACT: a summarizer for Moose exceptions | ||
| 5 | $Exception::Reporter::Summarizer::MooseException::VERSION = '0.014'; | ||
| 6 | use parent 'Exception::Reporter::Summarizer'; | ||
| 7 | |||
| 8 | #pod =head1 OVERVIEW | ||
| 9 | #pod | ||
| 10 | #pod This summarizer handles only L<Moose::Exception> objects. A dumped exception | ||
| 11 | #pod will result in two summaries: | ||
| 12 | #pod | ||
| 13 | #pod * a text summary of the exceptions full message | ||
| 14 | #pod * a dump of the exception object, just in case it's hiding secrets!@ | ||
| 15 | #pod | ||
| 16 | #pod =cut | ||
| 17 | |||
| 18 | use Try::Tiny; | ||
| 19 | |||
| 20 | sub can_summarize { | ||
| 21 | my ($self, $entry) = @_; | ||
| 22 | return try { $entry->[1]->isa('Moose::Exception') }; | ||
| 23 | } | ||
| 24 | |||
| 25 | sub summarize { | ||
| 26 | my ($self, $entry, $internal_arg) = @_; | ||
| 27 | my ($name, $exception, $arg) = @$entry; | ||
| 28 | |||
| 29 | my $fn_base = $self->sanitize_filename($name); | ||
| 30 | |||
| 31 | my $ident = $exception->message; | ||
| 32 | ($ident) = split /\n/, $ident; # only the first line, please | ||
| 33 | |||
| 34 | # I've never seen this happen with Moose, but we handle it for | ||
| 35 | # Exception::Class, so... -- rjbs, 2016-01-26 | ||
| 36 | $ident = "Moose exception of class " . ref $exception unless length $ident; | ||
| 37 | |||
| 38 | my @summaries = ( | ||
| 39 | { | ||
| 40 | filename => "exception-msg.txt", | ||
| 41 | mimetype => 'text/plain', | ||
| 42 | ident => $ident, | ||
| 43 | body => $exception->as_string, | ||
| 44 | }, | ||
| 45 | { | ||
| 46 | filename => "exception-dump.txt", | ||
| 47 | %{ $self->dump($exception, { basename => 'exception-dump' }) }, | ||
| 48 | ident => "exception dump", | ||
| 49 | }, | ||
| 50 | ); | ||
| 51 | |||
| 52 | return @summaries; | ||
| 53 | } | ||
| 54 | |||
| 55 | 1; | ||
| 56 | |||
| 57 | __END__ |