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 CC 15 SCAR 17.7
CC
15
Cov
97%
set_value
8.0
safe_set_value
8.0
BEGIN
1.0
CRAP 5.9
« blib/lib/Mail/AuthenticationResults/Header/Entry.pm ↑ Summary lib/Mail/AuthenticationResults/Header/Group.pm »
1 package Mail::AuthenticationResults::Header::Comment;
2 # ABSTRACT: Class modelling Comment parts of the Authentication Results Header
3  
4 30 require 5.008;
5 30 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 30 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 30 our $VERSION = '2.20260216'; # VERSION
8 30 ▶use Scalar::Util qw{ weaken };
Subroutine BEGIN: called CC=1 SCAR=0.0
9 30 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 30 ▶use base 'Mail::AuthenticationResults::Header::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13  
14 360 ▶sub _HAS_VALUE{ return 1; }
Subroutine _HAS_VALUE: called CC=1 SCAR=0.0
15  
16 15 ▶sub safe_set_value {
Subroutine safe_set_value: called CC=8 SCAR=20.8
Pod documented
17 15 my ( $self, $value ) = @_;
18  
19 15 ▶ $value = q{} if ! defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 15 15
20  
21 15 $value =~ s/\t/ /g;
22 15 $value =~ s/\n/ /g;
23 15 $value =~ s/\r/ /g;
24  
25 15 my $remain = $value;
26 15 my $depth = 0;
27 15 my $nested_ok = 1;
28 15 ▶ while ( length $remain > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $remain > 0) 153 15 168
29 153 my $first = substr( $remain,0,1 );
30 153 $remain = substr( $remain,1 );
31 153 ▶ $depth++ if $first eq '(';
Branch: 1 branch
BranchTrueFalseTotal
if $first eq "(" 6 147 153
32 153 ▶ $depth-- if $first eq ')';
Branch: 1 branch
BranchTrueFalseTotal
if $first eq ")" 6 147 153
33 153 ▶ $nested_ok = 0 if $depth == -1;
Branch: 1 branch
BranchTrueFalseTotal
if $depth == -1 5 148 153
34 }
35 15 ▶ $nested_ok = 0 if $depth != 0;
Branch: 1 branch
BranchTrueFalseTotal
if $depth != 0 4 11 15
36  
37 # Remove parens if nested comments would be broken by them.
38 15 ▶ if ( ! $nested_ok ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($nested_ok) 5 10 15
39 5 $value =~ s/\(/ /g;
40 5 $value =~ s/\)/ /g;
41 }
42  
43 15 $value =~ s/^\s+//;
44 15 $value =~ s/\s+$//;
45 #$value =~ s/;/ /g;
46  
47 15 $self->set_value( $value );
48 15 return $self;
49 }
50  
51 95 ▶sub set_value {
Subroutine set_value: called CC=8 SCAR=20.8
Pod documented
52 95 my ( $self, $value ) = @_;
53  
54 95 my $remain = $value;
55 95 my $depth = 0;
56 95 ▶ while ( length $remain > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $remain > 0) 1716 92 1808
57 1716 my $first = substr( $remain,0,1 );
58 1716 $remain = substr( $remain,1 );
59 1716 ▶ $depth++ if $first eq '(';
Branch: 1 branch
BranchTrueFalseTotal
if $first eq "(" 6 1710 1716
60 1716 ▶ $depth-- if $first eq ')';
Branch: 1 branch
BranchTrueFalseTotal
if $first eq ")" 7 1709 1716
61 1716 ▶ croak 'Out of order parens in comment' if $depth == -1;
Branch: 1 branch
BranchTrueFalseTotal
if $depth == -1 3 1713 1716
62 }
63 92 ▶ croak 'Mismatched parens in comment' if $depth != 0;
Branch: 1 branch
BranchTrueFalseTotal
if $depth != 0 2 90 92
64 90 ▶ croak 'Invalid characters in value' if $value =~ /\n/;
Branch: 1 branch
BranchTrueFalseTotal
if $value =~ /\n/ 0 90 90
65 90 ▶ croak 'Invalid characters in value' if $value =~ /\r/;
Branch: 1 branch
BranchTrueFalseTotal
if $value =~ /\r/ 0 90 90
66  
67 90 $self->{ 'value' } = $value;
68 90 return $self;
69 }
70  
71 91 ▶sub build_string {
Subroutine build_string: called CC=1 SCAR=0.0
Pod documented
72 91 my ( $self, $header ) = @_;
73 91 $header->comment( '(' . $self->value() . ')' );
74 91 return;
75 }
76  
77 30 1;
78  
79 __END__
« blib/lib/Mail/AuthenticationResults/Header/Entry.pm ↑ Summary lib/Mail/AuthenticationResults/Header/Group.pm »