Reporter/Summarizer/Text.pm

filter: Statementstmt 100% 33 / 33 Branchbran 66.6% 4 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 2 totaltotal 92.0% 46 / 50 SCAR 13.9
CC
4
Cov
95%
can_summarize
4.1
BEGIN
1.0
BEGIN
1.0
CRAP 4.0
« Reporter/Summarizer/ExceptionClass.pm ↑ Summary Reporter/Dumper.pm »
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::Text;
4 # ABSTRACT: a summarizer for plain text strings
5 1 $Exception::Reporter::Summarizer::Text::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 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<ident> 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 ▶use Encode ();
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 sub can_summarize {
25 8 ▶ my ($self, $entry) = @_;
Subroutine can_summarize: called CC=4 SCAR=14.0
Pod undocumented
26 8 my $value = $entry->[1];
27 8 ▶ return unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 8 8
28 8 ▶ return if ref $value;
Branch: 1 branch
BranchTrueFalseTotal
if ref $value 3 5 8
29 5 ▶ return if ref \$value ne 'SCALAR';
Branch: 1 branch
BranchTrueFalseTotal
if ref \$value ne "SCALAR" 0 5 5
30 5 return 1;
31 }
32  
33 sub summarize {
34 5 ▶ my ($self, $entry, $internal_arg) = @_;
Subroutine summarize: called CC=1 SCAR=0.0
Pod undocumented
35 5 my ($name, $value, $arg) = @$entry;
36  
37 5 my $fn_base = $self->sanitize_filename($name);
38  
39 my $octets = try {
40 5 ▶ encode('utf-8', $value, Encode::FB_CROAK);
Subroutine __ANON__: called CC=1 SCAR=0.0
41 } catch {
42 5 ▶ $value;
Subroutine __ANON__: called CC=1 SCAR=0.0
43 5 };
44  
45 5 my $ident = $value;
46 5 $ident =~ s/\A\n+//;
47 5 ($ident) = split /\n/, $ident;
48  
49 return {
50 5 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 1;
59  
60 __END__
« Reporter/Summarizer/ExceptionClass.pm ↑ Summary Reporter/Dumper.pm »