blib/lib/auto/share/dist/Cmd-Dwarf/app/lib/Dwarf/Error.pm untested

filter: Statementstmt 0.0% 0 / 38 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 65 CC 4 SCAR 13.5
CC
4
Cov
0%
body
6.0
throw
6.0
flush
6.0
CRAP 3.8
1 package Dwarf::Error;
2 use Dwarf::Pragma;
3 use Dwarf::Message::Error;
4  
5 use overload '""' => \&stringify;
6  
7 use Dwarf::Accessor {
8 rw => [qw/autoflush messages/],
9 };
10  
11 sub new {
12 my $invocant = shift;
13 my $class = ref($invocant) || $invocant;
14 my $self = bless {
15 autoflush => 0,
16 messages => [],
17 @_
18 }, $class;
19 return $self;
20 }
21  
22 sub message { $_[0]->messages->[0] }
23 sub body { $_[0]->message ? $_[0]->message->body : [] }
24  
25 sub throw {
26 my $self = shift;
27  
28 my $m = Dwarf::Message::Error->new;
29 $m->data([@_]);
30  
31 if ($self->autoflush) {
32 $self->{messages} = [$m];
33 $self->flush;
34 } else {
35 push @{ $self->{messages} }, $m;
36 }
37  
38 return $self;
39 }
40  
41 sub flush {
42 my $self = shift;
43 if (@{ $self->messages }) {
44 die $self;
45 }
46 }
47  
48 sub stringify {
49 my $self = shift;
50 return join "\n", @{ $self->messages };
51 }
52  
53 1;