Unexpected/TraitFor/StringifyingError.pm

filter: Statementstmt 100% 37 / 37 Branchbran 100% 8 / 8 Conditioncond 83.3% 5 / 6 MC/DCmcdc 75.0% 3 / 4 Subroutinesub 100% 9 / 9 Podpod 100% 2 / 2 totaltotal 96.9% 64 / 66 CC 7 SCAR 11.4
CC
7
Cov
98%
__ANON__
6.0
as_string
2.0
BEGIN
1.0
CRAP 3.1
« Unexpected/Functions.pm ↑ Summary Unexpected/TraitFor/ErrorLeader.pm »
1 package Unexpected::TraitFor::StringifyingError;
2  
3 4 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 4 ▶use Unexpected::Functions qw( inflate_placeholders parse_arg_list );
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use Unexpected::Types qw( ArrayRef Bool Str );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 4 requires qw( BUILD );
10  
11 # Object attributes (public)
12 23 ▶has 'args' => is => 'ro', isa => ArrayRef, default => sub { [] };
Subroutine __ANON__: called CC=1 SCAR=0.0
13  
14 4 has 'error' => is => 'ro', isa => Str, default => 'Unknown error';
15  
16 4 has 'no_quote_bind_values' => is => 'ro', isa => Bool, default => 0;
17  
18 # Construction
19 33 ▶around 'BUILDARGS' => sub {
Subroutine __ANON__: called CC=6 SCAR=17.9
20 33 my ($orig, $self, @args) = @_; my $attr = parse_arg_list( @args );
21  
22 33 my $e = delete $attr->{error};
23  
24 33 ▶ $e and ref $e eq 'CODE' and $e = $e->( $self, $attr );
Branch: 1 branch
BranchTrueFalseTotal
$e and ref $e eq "CODE" and $e = &$e($self, $attr) 1 32 33
Condition100%3/3
$e and ref $e eq "CODE"
!ll&&!rl&&r
11211
MC/DC100%2/2
$e and ref $e eq "CODE"
$e ref $e eq "CODE"
Truth table100%3/3
A and B
A= $eB= ref $e eq "CODE"
ABresult
0X0
100
111
25 33 ▶ $e and $e .= q() and chomp $e;
Branch: 1 branch
BranchTrueFalseTotal
$e and $e .= '' and chomp $e 22 11 33
Condition66%2/3
$e and $e .= ''
!ll&&!rl&&r
11022
MC/DC50%1/2
$e and $e .= ''
$e $e .= ''
Truth table66%2/3
A and B
A= $eB= $e .= ''
ABresult
0X0
100
111
26 33 ▶ $e and $attr->{error} = $e;
Branch: 1 branch
BranchTrueFalseTotal
$e and $attr->{"error"} = $e 22 11 33
27 33 return $attr;
28 4 };
29  
30 31 ▶after 'BUILD' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
31 # Fixes 98c94be8-d01e-11e2-8bc5-3f0fbdbf7481 WTF? Stringify fails.
32 # Bug only happens when Moose class inherits from Moo class which
33 # uses overload string. Moose class inherits from Moose class which
34 # has consumed a ::Role::WithOverloading works. Moo inherits from
35 # Moo also works
36 31 my $self = shift; $self->as_string; return;
37 4 };
38  
39 # Public methods
40 13 ▶sub as_boolean {
Subroutine as_boolean: called CC=1 SCAR=0.0
Pod documented
41 13 return 1;
42 }
43  
44 53 ▶sub as_string { # Stringifies the error and inflates the placeholders
Subroutine as_string: called CC=2 SCAR=6.9
Pod documented
45 53 my $self = shift; my $e = $self->error;
46  
47 53 ▶ 0 > index $e, '[_' and return "${e}\n";
Branch: 1 branch
BranchTrueFalseTotal
index($e, "[_") == -1 and return "$e\n" 39 14 53
48  
49 14 my $opts = [ '[?]', '[]', $self->no_quote_bind_values ];
50  
51 14 return inflate_placeholders( $opts, $e, @{ $self->args } )."\n";
52 }
53  
54 4 1;
55  
56 __END__
« Unexpected/Functions.pm ↑ Summary Unexpected/TraitFor/ErrorLeader.pm »