File Coverage

blib/lib/Exception/Reporter/Summarizer.pm
Criterion Covered Total %
statement 27 27 100.0
branch 2 4 50.0
condition n/a
subroutine 9 9 100.0
pod 0 5 0.0
total 38 45 84.4


line stmt bran cond sub pod time code
1 1     1   440 use strict;
  1         3  
  1         28  
2 1     1   6 use warnings;
  1         2  
  1         34  
3             package Exception::Reporter::Summarizer 0.015;
4             # ABSTRACT: a thing that summarizes dumpables for reporting
5              
6 1     1   5 use Carp ();
  1         3  
  1         11  
7 1     1   5 use Scalar::Util ();
  1         2  
  1         356  
8              
9             #pod =head1 OVERVIEW
10             #pod
11             #pod This class exists almost entirely to allow C-checking. It provides a
12             #pod C method that returns a blessed, empty object. Passing it any parameters
13             #pod will cause an exception to be thrown.
14             #pod
15             #pod A C method is also provided, which turns a vaguely
16             #pod filename-like string into a safer filename string.
17             #pod
18             #pod =cut
19              
20             sub new {
21 11     11 0 28 my $class = shift;
22              
23 11 50       25 Carp::confess("$class constructor does not take any parameters") if @_;
24              
25 11         98 return bless {}, $class;
26             }
27              
28             sub sanitize_filename {
29 15     15 0 32 my ($self, $filename) = @_;
30              
31             # These don't need to be actually secure, since we won't use this for
32             # opening any filehandles. -- rjbs, 2012-07-03
33 15         38 $filename =~ s/\.+/./g;
34 15         40 $filename =~ s/[^-a-zA-Z0-9]/-/g;
35 15         39 return $filename;
36             }
37              
38             sub register_reporter {
39 11     11 0 26 my ($self, $reporter) = @_;
40              
41             Carp::confess("register_reporter called, but a reporter was already registered")
42 11 50       44 if $self->{reporter};
43              
44 11         22 $self->{reporter} = $reporter;
45 11         35 Scalar::Util::weaken($self->{reporter});
46 11         42 return;
47             }
48              
49 6     6 0 26 sub reporter { $_[0]->{reporter} }
50              
51             sub dump {
52 6     6 0 85 my ($self, $value, $arg) = @_;
53 6         25 $self->reporter->dumper->dump($value, $arg);
54             }
55              
56             1;
57              
58             __END__