| line | stmt | bran | cond | sub | pod | time | code | 
| 1 | 1 |  |  | 1 |  | 322 | use strict; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 21 |  | 
| 2 | 1 |  |  | 1 |  | 2 | use warnings; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 35 |  | 
| 3 |  |  |  |  |  |  | package Exception::Reporter::Summarizer::Text; | 
| 4 |  |  |  |  |  |  | # ABSTRACT: a summarizer for plain text strings | 
| 5 |  |  |  |  |  |  | $Exception::Reporter::Summarizer::Text::VERSION = '0.014'; | 
| 6 | 1 |  |  | 1 |  | 3 | use parent 'Exception::Reporter::Summarizer'; | 
|  | 1 |  |  |  |  | 0 |  | 
|  | 1 |  |  |  |  | 8 |  | 
| 7 |  |  |  |  |  |  |  | 
| 8 |  |  |  |  |  |  | #pod =head1 OVERVIEW | 
| 9 |  |  |  |  |  |  | #pod | 
| 10 |  |  |  |  |  |  | #pod This summarizer will summarize simple, non-empty strings by accepting them | 
| 11 |  |  |  |  |  |  | #pod verbatim.  They are assumed to be text, and will be encoded to UTF-8.  If that | 
| 12 |  |  |  |  |  |  | #pod fails, they will be used verbatim, possibly with strange results. | 
| 13 |  |  |  |  |  |  | #pod | 
| 14 |  |  |  |  |  |  | #pod The summary's C will be the first non-blank line of the string. | 
| 15 |  |  |  |  |  |  | #pod | 
| 16 |  |  |  |  |  |  | #pod =cut | 
| 17 |  |  |  |  |  |  |  | 
| 18 |  |  |  |  |  |  | # Maybe in the future we can have options to allow empty strings. -- rjbs, | 
| 19 |  |  |  |  |  |  | # 2013-02-06 | 
| 20 |  |  |  |  |  |  |  | 
| 21 | 1 |  |  | 1 |  | 45 | use Encode (); | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 10 |  | 
| 22 | 1 |  |  | 1 |  | 3 | use Try::Tiny; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 211 |  | 
| 23 |  |  |  |  |  |  |  | 
| 24 |  |  |  |  |  |  | sub can_summarize { | 
| 25 | 8 |  |  | 8 | 0 | 6 | my ($self, $entry) = @_; | 
| 26 | 8 |  |  |  |  | 9 | my $value = $entry->[1]; | 
| 27 | 8 | 50 |  |  |  | 15 | return unless defined $value; | 
| 28 | 8 | 100 |  |  |  | 14 | return if ref $value; | 
| 29 | 5 | 50 |  |  |  | 11 | return if ref \$value ne 'SCALAR'; | 
| 30 | 5 |  |  |  |  | 10 | return 1; | 
| 31 |  |  |  |  |  |  | } | 
| 32 |  |  |  |  |  |  |  | 
| 33 |  |  |  |  |  |  | sub summarize { | 
| 34 | 5 |  |  | 5 | 0 | 6 | my ($self, $entry, $internal_arg) = @_; | 
| 35 | 5 |  |  |  |  | 7 | my ($name, $value, $arg) = @$entry; | 
| 36 |  |  |  |  |  |  |  | 
| 37 | 5 |  |  |  |  | 10 | my $fn_base = $self->sanitize_filename($name); | 
| 38 |  |  |  |  |  |  |  | 
| 39 |  |  |  |  |  |  | my $octets = try { | 
| 40 | 5 |  |  | 5 |  | 142 | encode('utf-8', $value, Encode::FB_CROAK); | 
| 41 |  |  |  |  |  |  | } catch { | 
| 42 | 5 |  |  | 5 |  | 44 | $value; | 
| 43 | 5 |  |  |  |  | 18 | }; | 
| 44 |  |  |  |  |  |  |  | 
| 45 | 5 |  |  |  |  | 23 | my $ident = $value; | 
| 46 | 5 |  |  |  |  | 9 | $ident =~ s/\A\n+//; | 
| 47 | 5 |  |  |  |  | 11 | ($ident) = split /\n/, $ident; | 
| 48 |  |  |  |  |  |  |  | 
| 49 |  |  |  |  |  |  | return { | 
| 50 | 5 |  |  |  |  | 24 | filename => "$fn_base.txt", | 
| 51 |  |  |  |  |  |  | ident    => $ident, | 
| 52 |  |  |  |  |  |  | mimetype => 'text/plain', | 
| 53 |  |  |  |  |  |  | charset  => 'utf-8', # possibly a lie if the try failed | 
| 54 |  |  |  |  |  |  | body     => "$value", | 
| 55 |  |  |  |  |  |  | }; | 
| 56 |  |  |  |  |  |  | } | 
| 57 |  |  |  |  |  |  |  | 
| 58 |  |  |  |  |  |  | 1; | 
| 59 |  |  |  |  |  |  |  | 
| 60 |  |  |  |  |  |  | __END__ |