blib/lib/Mail/AuthenticationResults/Header/Comment.pm untested

filter: Statementstmt 0.0% 0 / 60 Branchbran 0.0% 0 / 24 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 98 CC 13 SCAR 35.9
CC
13
Cov
0%
safe_set_value
56.0
set_value
56.0
_HAS_VALUE
2.0
CRAP 36.4
1 package Mail::AuthenticationResults::Header::Comment;
2 # ABSTRACT: Class modelling Comment parts of the Authentication Results Header
3  
4 require 5.008;
5 use strict;
6 use warnings;
7 our $VERSION = '2.20260216'; # VERSION
8 use Scalar::Util qw{ weaken };
9 use Carp;
10  
11 use base 'Mail::AuthenticationResults::Header::Base';
12  
13  
14 sub _HAS_VALUE{ return 1; }
15  
16 sub safe_set_value {
17 my ( $self, $value ) = @_;
18  
19 $value = q{} if ! defined $value;
20  
21 $value =~ s/\t/ /g;
22 $value =~ s/\n/ /g;
23 $value =~ s/\r/ /g;
24  
25 my $remain = $value;
26 my $depth = 0;
27 my $nested_ok = 1;
28 while ( length $remain > 0 ) {
29 my $first = substr( $remain,0,1 );
30 $remain = substr( $remain,1 );
31 $depth++ if $first eq '(';
32 $depth-- if $first eq ')';
33 $nested_ok = 0 if $depth == -1;
34 }
35 $nested_ok = 0 if $depth != 0;
36  
37 # Remove parens if nested comments would be broken by them.
38 if ( ! $nested_ok ) {
39 $value =~ s/\(/ /g;
40 $value =~ s/\)/ /g;
41 }
42  
43 $value =~ s/^\s+//;
44 $value =~ s/\s+$//;
45 #$value =~ s/;/ /g;
46  
47 $self->set_value( $value );
48 return $self;
49 }
50  
51 sub set_value {
52 my ( $self, $value ) = @_;
53  
54 my $remain = $value;
55 my $depth = 0;
56 while ( length $remain > 0 ) {
57 my $first = substr( $remain,0,1 );
58 $remain = substr( $remain,1 );
59 $depth++ if $first eq '(';
60 $depth-- if $first eq ')';
61 croak 'Out of order parens in comment' if $depth == -1;
62 }
63 croak 'Mismatched parens in comment' if $depth != 0;
64 croak 'Invalid characters in value' if $value =~ /\n/;
65 croak 'Invalid characters in value' if $value =~ /\r/;
66  
67 $self->{ 'value' } = $value;
68 return $self;
69 }
70  
71 sub build_string {
72 my ( $self, $header ) = @_;
73 $header->comment( '(' . $self->value() . ')' );
74 return;
75 }
76  
77 1;
78  
79 __END__