| 1 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | package Exception::Reporter::Summarizer::ExceptionClass; | ||||||||||
| 4 | # ABSTRACT: a summarizer for Exception::Class exceptions | ||||||||||
| 5 | 1 | $Exception::Reporter::Summarizer::ExceptionClass::VERSION = '0.014'; | |||||||||
| 6 | 1 | ▶ | use parent 'Exception::Reporter::Summarizer'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | #pod =head1 OVERVIEW | ||||||||||
| 9 | #pod | ||||||||||
| 10 | #pod This summarizer handles only L<Exception::Class> objects. A dumped exception | ||||||||||
| 11 | #pod will result in between one and four summaries: | ||||||||||
| 12 | #pod | ||||||||||
| 13 | #pod * a text summary of the exceptions full message | ||||||||||
| 14 | #pod * if available, a dump of the exception's pid, time, uid, etc. | ||||||||||
| 15 | #pod * if available, the stringification of the exception's stack trace | ||||||||||
| 16 | #pod * if any fields are defined, a dump of the exception's fields | ||||||||||
| 17 | #pod | ||||||||||
| 18 | #pod =cut | ||||||||||
| 19 | |||||||||||
| 20 | 1 | ▶ | use Exception::Class 1.30; # NoContextInfo | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 21 | 1 | ▶ | use Try::Tiny; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 22 | |||||||||||
| 23 | sub can_summarize { | ||||||||||
| 24 | 10 | ▶ | my ($self, $entry) = @_; | ||||||||
|
Subroutine
can_summarize: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 25 | 10 | ▶ | return try { $entry->[1]->isa('Exception::Class::Base') }; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 26 | } | ||||||||||
| 27 | |||||||||||
| 28 | sub summarize { | ||||||||||
| 29 | 2 | ▶ | my ($self, $entry, $internal_arg) = @_; | ||||||||
|
Subroutine
summarize: called CC=5 SCAR=18.0
Pod
undocumented
| |||||||||||
| 30 | 2 | my ($name, $exception, $arg) = @$entry; | |||||||||
| 31 | |||||||||||
| 32 | 2 | my $fn_base = $self->sanitize_filename($name); | |||||||||
| 33 | |||||||||||
| 34 | 2 | my $ident = $exception->error; | |||||||||
| 35 | 2 | ($ident) = split /\n/, $ident; # only the first line, please | |||||||||
| 36 | |||||||||||
| 37 | # Yes, I have seen the case below need handling! -- rjbs, 2012-07-03 | ||||||||||
| 38 | 2 | ▶ | $ident = "exception of class " . ref $exception unless length $ident; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | |||||||||||
| 40 | # Another option here is to dump this in a few parts: | ||||||||||
| 41 | # * a YAML dump of the message, error, and fields | ||||||||||
| 42 | # * a dump of the stack trace | ||||||||||
| 43 | 2 | my @summaries = ({ | |||||||||
| 44 | filename => "exception-msg.txt", | ||||||||||
| 45 | mimetype => 'text/plain', | ||||||||||
| 46 | ident => $ident, | ||||||||||
| 47 | body => $exception->full_message, | ||||||||||
| 48 | }); | ||||||||||
| 49 | |||||||||||
| 50 | 2 | ▶ | if (! $exception->NoContextInfo) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | 2 | my $context = $self->dump({ | |||||||||
| 52 | time => $exception->time, | ||||||||||
| 53 | pid => $exception->pid, | ||||||||||
| 54 | uid => $exception->uid, | ||||||||||
| 55 | euid => $exception->euid, | ||||||||||
| 56 | gid => $exception->gid, | ||||||||||
| 57 | egid => $exception->egid, | ||||||||||
| 58 | }, { basename => 'exception-context' }); | ||||||||||
| 59 | |||||||||||
| 60 | 2 | push @summaries, ( | |||||||||
| 61 | { | ||||||||||
| 62 | filename => "exception-stack.txt", | ||||||||||
| 63 | mimetype => 'text/plain', | ||||||||||
| 64 | ident => "stack trace", | ||||||||||
| 65 | body => $exception->trace->as_string({ | ||||||||||
| 66 | max_arg_length => 0, | ||||||||||
| 67 | }), | ||||||||||
| 68 | }, | ||||||||||
| 69 | { | ||||||||||
| 70 | filename => 'exception-context.txt', | ||||||||||
| 71 | %$context, | ||||||||||
| 72 | ident => 'exception context info', | ||||||||||
| 73 | }, | ||||||||||
| 74 | ); | ||||||||||
| 75 | } | ||||||||||
| 76 | |||||||||||
| 77 | 2 | ▶ | if ($exception->Fields) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 78 | 0 | my $hash = {}; | |||||||||
| 79 | 0 | for my $field ($exception->Fields) { | |||||||||
| 80 | 0 | $hash->{ $field } = $exception->$field; | |||||||||
| 81 | } | ||||||||||
| 82 | |||||||||||
| 83 | 0 | my $fields = $self->dump($hash, { basename => 'exception-fields' }); | |||||||||
| 84 | 0 | push @summaries, { | |||||||||
| 85 | filename => "exception-fields.txt", | ||||||||||
| 86 | %$fields, | ||||||||||
| 87 | ident => "exception fields", | ||||||||||
| 88 | }; | ||||||||||
| 89 | } | ||||||||||
| 90 | |||||||||||
| 91 | 2 | return @summaries; | |||||||||
| 92 | } | ||||||||||
| 93 | |||||||||||
| 94 | 1 | 1; | |||||||||
| 95 | |||||||||||
| 96 | __END__ | ||||||||||