lib/Mail/AuthenticationResults/Header/Comment.pm

filter: Statementstmt 100% 58 / 58 Branchbran 89.2% 25 / 28 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod 100% 3 / 3 totaltotal 96.9% 95 / 98 SCAR 27.1
CC
15
Cov
97%
set_value
8.0
safe_set_value
8.0
BEGIN
1.0
CRAP 15.0
« lib/Mail/AuthenticationResults/Header/Group.pm ↑ Summary blib/lib/Mail/AuthenticationResults/Header/SubEntry.pm »
1 package Mail::AuthenticationResults::Header::Comment;
2 # ABSTRACT: Class modelling Comment parts of the Authentication Results Header
3  
4 29 require 5.008;
5 29 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 29 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 29 our $VERSION = '2.20230112'; # VERSION
8 29 ▶use Scalar::Util qw{ weaken };
Subroutine BEGIN: called CC=1 SCAR=0.0
9 29 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 29 ▶use base 'Mail::AuthenticationResults::Header::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13  
14 352 ▶sub _HAS_VALUE{ return 1; }
Subroutine _HAS_VALUE: called CC=1 SCAR=0.0
15  
16 sub safe_set_value {
17 13 ▶ my ( $self, $value ) = @_;
Subroutine safe_set_value: called CC=8 SCAR=20.8
Pod documented
18  
19 13 ▶ $value = q{} if ! defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 13 13
20  
21 13 $value =~ s/\t/ /g;
22 13 $value =~ s/\n/ /g;
23 13 $value =~ s/\r/ /g;
24  
25 13 my $remain = $value;
26 13 my $depth = 0;
27 13 my $nested_ok = 1;
28 13 ▶ while ( length $remain > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $remain > 0) 119 13 132
29 119 my $first = substr( $remain,0,1 );
30 119 $remain = substr( $remain,1 );
31 119 ▶ $depth++ if $first eq '(';
Branch: 1 branch
BranchTrueFalseTotal
if $first eq "(" 6 113 119
32 119 ▶ $depth-- if $first eq ')';
Branch: 1 branch
BranchTrueFalseTotal
if $first eq ")" 6 113 119
33 119 ▶ $nested_ok = 0 if $depth == -1;
Branch: 1 branch
BranchTrueFalseTotal
if $depth == -1 5 114 119
34 }
35 13 ▶ $nested_ok = 0 if $depth != 0;
Branch: 1 branch
BranchTrueFalseTotal
if $depth != 0 4 9 13
36  
37 # Remove parens if nested comments would be broken by them.
38 13 ▶ if ( ! $nested_ok ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($nested_ok) 5 8 13
39 5 $value =~ s/\(/ /g;
40 5 $value =~ s/\)/ /g;
41 }
42  
43 13 $value =~ s/^\s+//;
44 13 $value =~ s/\s+$//;
45 #$value =~ s/;/ /g;
46  
47 13 $self->set_value( $value );
48 13 return $self;
49 }
50  
51 sub set_value {
52 93 ▶ my ( $self, $value ) = @_;
Subroutine set_value: called CC=8 SCAR=20.8
Pod documented
53  
54 93 my $remain = $value;
55 93 my $depth = 0;
56 93 ▶ while ( length $remain > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $remain > 0) 1682 90 1772
57 1682 my $first = substr( $remain,0,1 );
58 1682 $remain = substr( $remain,1 );
59 1682 ▶ $depth++ if $first eq '(';
Branch: 1 branch
BranchTrueFalseTotal
if $first eq "(" 6 1676 1682
60 1682 ▶ $depth-- if $first eq ')';
Branch: 1 branch
BranchTrueFalseTotal
if $first eq ")" 7 1675 1682
61 1682 ▶ croak 'Out of order parens in comment' if $depth == -1;
Branch: 1 branch
BranchTrueFalseTotal
if $depth == -1 3 1679 1682
62 }
63 90 ▶ croak 'Mismatched parens in comment' if $depth != 0;
Branch: 1 branch
BranchTrueFalseTotal
if $depth != 0 2 88 90
64 88 ▶ croak 'Invalid characters in value' if $value =~ /\n/;
Branch: 1 branch
BranchTrueFalseTotal
if $value =~ /\n/ 0 88 88
65 88 ▶ croak 'Invalid characters in value' if $value =~ /\r/;
Branch: 1 branch
BranchTrueFalseTotal
if $value =~ /\r/ 0 88 88
66  
67 88 $self->{ 'value' } = $value;
68 88 return $self;
69 }
70  
71 sub build_string {
72 83 ▶ my ( $self, $header ) = @_;
Subroutine build_string: called CC=1 SCAR=0.0
Pod documented
73 83 $header->comment( '(' . $self->value() . ')' );
74 83 return;
75 }
76  
77 29 1;
78  
79 __END__
« lib/Mail/AuthenticationResults/Header/Group.pm ↑ Summary blib/lib/Mail/AuthenticationResults/Header/SubEntry.pm »