BIMI/Role/HasError.pm

filter: Statementstmt 95.6% 44 / 46 Branchbran 100% 8 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 87.5% 14 / 16 Podpod 100% 7 / 7 totaltotal 94.8% 73 / 77 CC 8 SCAR 7.4
CC
8
Cov
96%
add_error_object
4.0
deserialize_errors
3.0
add_error
3.0
CRAP 2.1
« BIMI/Options.pm ↑ Summary BIMI/CacheBackend/File.pm »
1 package Mail::BIMI::Role::HasError;
2 # ABSTRACT: Class to model an error
3 29 our $VERSION = '3.20261116'; # VERSION
4 29 ▶use 5.20.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 29 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 29 ▶use Mail::BIMI::Prelude;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 29 ▶use Mail::BIMI::Trait::Cacheable;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 29 ▶use Mail::BIMI::Trait::CacheSerial;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 29 ▶use Mail::BIMI::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 29 ▶use Sub::Install;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 102 ▶has errors => ( is => 'rw', isa => 'ArrayRef', lazy => 1, default => sub{return []}, traits => ['Cacheable','CacheSerial'] );
Subroutine __ANON__: called CC=1 SCAR=0.0
13 0 ▶has warnings => ( is => 'rw', isa => 'ArrayRef', lazy => 1, default => sub{return []}, traits => ['Cacheable'] );
Subroutine __ANON__: not called CC=1 SCAR=1.2
14  
15  
16  
17 14 ▶sub serialize_errors($self) {
Subroutine serialize_errors: called CC=1 SCAR=0.0
Pod documented
18 14 my @data = map {{
19 5 code => $_->code,
20 detail => $_->detail,
21 }} $self->errors->@*;
22 14 return \@data;
23 }
24  
25  
26 7 ▶sub deserialize_errors($self,$value) {
Subroutine deserialize_errors: called CC=3 SCAR=11.0
Pod documented
27 7 foreach my $error ($value->@*) {
28 my $error_object = Mail::BIMI::Error->new(
29 code => $error->{code},
30 2 ▶ ( $error->{detail} ? ( detail => $error->{detail} ) : () ),
Branch: 1 branch
BranchTrueFalseTotal
$error->{'detail'} ? : 1 1 2
31 );
32 2 $self->add_error_object($error_object);
33 }
34 }
35  
36  
37 28 ▶sub add_error($self,$code,$detail=undef) {
Subroutine add_error: called CC=3 SCAR=11.0
Pod documented
38 28 ▶ my $error = Mail::BIMI::Error->new(
Branch: 1 branch
BranchTrueFalseTotal
$detail ? : 4 24 28
39 code=>$code,
40 ($detail?(detail=>$detail):()),
41 );
42 28 $self->add_error_object($error);
43 }
44  
45  
46 0 ▶sub add_warning($self,$detail) {
Subroutine add_warning: not called CC=1 SCAR=6.9
Pod documented
47 0 push $self->warnings->@*, $detail;
48 }
49  
50  
51 36 ▶sub add_error_object($self,$error) {
Subroutine add_error_object: called CC=4 SCAR=13.9
Pod documented
52 36 ▶ if ( ref $error eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $error eq 'ARRAY') { } 3 33 36
53 3 foreach my $suberror ( $error->@* ){
54 3 $self->add_error_object($suberror);
55 }
56 }
57 else {
58 33 ▶ $self->log_verbose(join(' : ',
Branch: 1 branch
BranchTrueFalseTotal
$error->detail ? : 5 28 33
59 'Error',
60 $error->code,
61 $error->description,
62 ( $error->detail ? $error->detail : () ),
63 ));
64 33 push $self->errors->@*, $error;
65 }
66 }
67  
68  
69 36 ▶sub error_codes($self) {
Subroutine error_codes: called CC=1 SCAR=0.0
Pod documented
70 36 my @error_codes = map { $_->code } $self->errors->@*;
71 36 return \@error_codes;
72 }
73  
74  
75 22 ▶sub filter_errors($self,$error) {
Subroutine filter_errors: called CC=1 SCAR=0.0
Pod documented
76 22 return grep { $_->code eq $error } $self->errors->@*;
77 }
78  
79 29 1;
80  
81 __END__
« BIMI/Options.pm ↑ Summary BIMI/CacheBackend/File.pm »