lib/Mail/AuthenticationResults/Header.pm

filter: Statementstmt 100% 136 / 136 Branchbran 92.5% 49 / 54 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 27 / 27 Podpod 100% 18 / 18 totaltotal 98.3% 230 / 235 SCAR 33.7
CC
29
Cov
98%
indent_on
7.0
set_indent_style
5.0
build_string
5.0
CRAP 29.0
« blib/lib/Mail/AuthenticationResults/Token/Comment.pm ↑ Summary lib/Mail/AuthenticationResults/Token/String.pm »
1 package Mail::AuthenticationResults::Header;
2 # ABSTRACT: Class modelling the Entire Authentication Results Header set
3  
4 28 require 5.008;
5 28 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 28 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 28 our $VERSION = '2.20230112'; # VERSION
8 28 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 28 ▶use Mail::AuthenticationResults::Header::AuthServID;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 28 ▶use base 'Mail::AuthenticationResults::Header::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14  
15 296 ▶sub _HAS_VALUE{ return 1; }
Subroutine _HAS_VALUE: called CC=1 SCAR=0.0
16 424 ▶sub _HAS_CHILDREN{ return 1; }
Subroutine _HAS_CHILDREN: called CC=1 SCAR=0.0
17  
18 sub _ALLOWED_CHILDREN {
19 245 ▶ my ( $self, $child ) = @_;
Subroutine _ALLOWED_CHILDREN: called CC=3 SCAR=11.0
20 245 ▶ return 1 if ref $child eq 'Mail::AuthenticationResults::Header::Comment';
Branch: 1 branch
BranchTrueFalseTotal
if ref $child eq "Mail::AuthenticationResults::Header::Comment" 9 236 245
21 236 ▶ return 1 if ref $child eq 'Mail::AuthenticationResults::Header::Entry';
Branch: 1 branch
BranchTrueFalseTotal
if ref $child eq "Mail::AuthenticationResults::Header::Entry" 230 6 236
22 6 return 0;
23 }
24  
25  
26 sub set_indent_by {
27 7 ▶ my ( $self, $value ) = @_;
Subroutine set_indent_by: called CC=1 SCAR=0.0
Pod documented
28 7 $self->{ 'indent_by' } = $value;
29 7 return $self;
30 }
31  
32  
33 sub indent_by {
34 290 ▶ my ( $self ) = @_;
Subroutine indent_by: called CC=2 SCAR=6.9
Pod documented
35 290 ▶ return 4 if ! defined $self->{ 'indent_by' }; #5.8
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"indent_by"} 176 114 290
36 114 return $self->{ 'indent_by'};
37 }
38  
39  
40 sub set_indent_on {
41 10 ▶ my ( $self, $type ) = @_;
Subroutine set_indent_on: called CC=1 SCAR=0.0
Pod documented
42 10 $self->{ 'indent_type_' . $type } = 1;
43 10 return $self;
44 }
45  
46  
47 sub clear_indent_on {
48 20 ▶ my ( $self, $type ) = @_;
Subroutine clear_indent_on: called CC=1 SCAR=0.0
Pod documented
49 20 $self->{ 'indent_type_' . $type } = 0;
50 20 return $self;
51 }
52  
53  
54 sub indent_on {
55 260 ▶ my ( $self, $type ) = @_;
Subroutine indent_on: called CC=7 SCAR=19.5
Pod documented
56 260 ▶ if ( $type eq 'Mail::AuthenticationResults::Header::Entry' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "Mail::AuthenticationResults::Header::Entry") 77 183 260
57 77 ▶ return 1 if ! defined $self->{ 'indent_type_' . $type }; #5.8
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$self{'indent_type_' . $type} 34 43 77
58 43 return $self->{ 'indent_type_' . $type };
59 }
60 183 ▶ if ( $type eq 'Mail::AuthenticationResults::Header::SubEntry' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'Mail::AuthenticationResults::Header::SubEntry') { } 110 73 183
elsif ($type eq 'Mail::AuthenticationResults::Header::Comment') { } 72 1 73
61 110 ▶ return 0 if ! defined $self->{ 'indent_type_' . $type }; #5.8
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$self{'indent_type_' . $type} 43 67 110
62 67 return $self->{ 'indent_type_' . $type };
63 }
64 elsif ( $type eq 'Mail::AuthenticationResults::Header::Comment' ) {
65 72 ▶ return 0 if ! defined $self->{ 'indent_type_' . $type }; #5.8
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$self{'indent_type_' . $type} 44 28 72
66 28 return $self->{ 'indent_type_' . $type };
67 }
68 1 return 0;
69 }
70  
71  
72 sub set_eol {
73 3 ▶ my ( $self, $eol ) = @_;
Subroutine set_eol: called CC=2 SCAR=6.9
Pod documented
74 3 ▶ if ( $eol =~ /^\r?\n$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($eol =~ /^\r?\n$/) { } 2 1 3
75 2 $self->{ 'eol' } = $eol;
76 }
77 else {
78 1 croak 'Invalid eol string';
79 }
80 2 return $self;
81 }
82  
83  
84 sub eol {
85 290 ▶ my ( $self ) = @_;
Subroutine eol: called CC=2 SCAR=6.9
Pod documented
86 290 ▶ return "\n" if ! defined $self->{ 'eol' }; #5.8
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"eol"} 276 14 290
87 14 return $self->{ 'eol' };
88 }
89  
90  
91 sub fold_at {
92 35 ▶ my ( $self ) = @_;
Subroutine fold_at: called CC=1 SCAR=0.0
Pod documented
93 35 return $self->{ 'fold_at' };
94 }
95  
96  
97 sub set_fold_at {
98 4 ▶ my ( $self, $fold_at ) = @_;
Subroutine set_fold_at: called CC=1 SCAR=0.0
Pod documented
99 4 $self->{ 'fold_at' } = $fold_at;
100 4 return $self;
101 }
102  
103  
104 sub force_fold_at {
105 32 ▶ my ( $self ) = @_;
Subroutine force_fold_at: called CC=1 SCAR=0.0
Pod documented
106 32 return $self->{ 'force_fold_at' };
107 }
108  
109  
110 sub set_force_fold_at {
111 1 ▶ my ( $self, $fold_at ) = @_;
Subroutine set_force_fold_at: called CC=1 SCAR=0.0
Pod documented
112 1 $self->{ 'force_fold_at' } = $fold_at;
113 1 return $self;
114 }
115  
116  
117 sub set_indent_style {
118 11 ▶ my ( $self, $style ) = @_;
Subroutine set_indent_style: called CC=5 SCAR=16.1
Pod documented
119  
120 11 ▶ if ( $style eq 'none' ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($style eq 'none') { } 3 8 11
elsif ($style eq 'entry') { } 5 3 8
elsif ($style eq 'subentry') { } 1 2 3
elsif ($style eq 'full') { } 1 1 2
121 3 $self->clear_indent_on( 'Mail::AuthenticationResults::Header::Entry' );
122 3 $self->clear_indent_on( 'Mail::AuthenticationResults::Header::SubEntry' );
123 3 $self->clear_indent_on( 'Mail::AuthenticationResults::Header::Comment' );
124 }
125 elsif ( $style eq 'entry' ) {
126 5 $self->set_indent_by( 4 );
127 5 $self->set_indent_on( 'Mail::AuthenticationResults::Header::Entry' );
128 5 $self->clear_indent_on( 'Mail::AuthenticationResults::Header::SubEntry' );
129 5 $self->clear_indent_on( 'Mail::AuthenticationResults::Header::Comment' );
130 }
131 elsif ( $style eq 'subentry' ) {
132 1 $self->set_indent_by( 4 );
133 1 $self->set_indent_on( 'Mail::AuthenticationResults::Header::Entry' );
134 1 $self->set_indent_on( 'Mail::AuthenticationResults::Header::SubEntry' );
135 1 $self->clear_indent_on( 'Mail::AuthenticationResults::Header::Comment' );
136 }
137 elsif ( $style eq 'full' ) {
138 1 $self->set_indent_by( 4 );
139 1 $self->set_indent_on( 'Mail::AuthenticationResults::Header::Entry' );
140 1 $self->set_indent_on( 'Mail::AuthenticationResults::Header::SubEntry' );
141 1 $self->set_indent_on( 'Mail::AuthenticationResults::Header::Comment' );
142 }
143 else {
144 1 croak "Unknown indent style $style";
145 }
146  
147 10 return $self;
148 }
149  
150 sub safe_set_value {
151 5 ▶ my ( $self, $value ) = @_;
Subroutine safe_set_value: called CC=1 SCAR=0.0
Pod documented
152 5 $self->set_value( $value );
153 3 return $self;
154 }
155  
156 sub set_value {
157 60 ▶ my ( $self, $value ) = @_;
Subroutine set_value: called CC=4 SCAR=13.9
Pod documented
158 60 ▶ croak 'Does not have value' if ! $self->_HAS_VALUE(); # uncoverable branch true
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_HAS_VALUE 0 60 60
159 # HAS_VALUE is 1 for this class
160 60 ▶ croak 'Value cannot be undefined' if ! defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 2 58 60
161 58 ▶ croak 'value should be an AuthServID type' if ref $value ne 'Mail::AuthenticationResults::Header::AuthServID';
Branch: 1 branch
BranchTrueFalseTotal
if ref $value ne "Mail::AuthenticationResults::Header::AuthServID" 2 56 58
162 56 $self->{ 'value' } = $value;
163 56 return $self;
164 }
165  
166 sub add_parent {
167 20 ▶ my ( $self, $parent ) = @_;
Subroutine add_parent: called CC=1 SCAR=0.0
Pod documented
168 20 return;
169 }
170  
171 sub add_child {
172 126 ▶ my ( $self, $child ) = @_;
Subroutine add_child: called CC=2 SCAR=6.9
Pod documented
173 126 ▶ croak 'Cannot add a SubEntry as a child of a Header' if ref $child eq 'Mail::AuthenticationResults::Header::SubEntry';
Branch: 1 branch
BranchTrueFalseTotal
if ref $child eq "Mail::AuthenticationResults::Header::SubEntry" 1 125 126
174 125 return $self->SUPER::add_child( $child );
175 }
176  
177 sub _as_hashref {
178 2 ▶ my ( $self ) = @_;
Subroutine _as_hashref: called CC=4 SCAR=14.0
179  
180 2 my $type = lc ref $self;
181 2 $type =~ s/^(.*::)//;
182 2 my $hashref = { 'type' => $type };
183  
184 2 ▶ $hashref->{'key'} = $self->key() if $self->_HAS_KEY();
Branch: 1 branch
BranchTrueFalseTotal
if $self->_HAS_KEY 0 2 2
185 2 ▶ $hashref->{'authserv_id'} = $self->value()->_as_hashref() if $self->value();
Branch: 1 branch
BranchTrueFalseTotal
if $self->value 2 0 2
186 2 ▶ if ( $self->_HAS_CHILDREN() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_HAS_CHILDREN) 2 0 2
187 2 my @children = map { $_->_as_hashref() } @{ $self->children() };
188 2 $hashref->{'children'} = \@children;
189 }
190 2 return $hashref;
191 }
192  
193 sub as_string {
194 30 ▶ my ( $self ) = @_;
Subroutine as_string: called CC=3 SCAR=11.0
Pod documented
195 30 my $header = Mail::AuthenticationResults::FoldableHeader->new();
196 30 ▶ $header->set_try_fold_at( $self->fold_at() ) if defined $self->fold_at();
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->fold_at 3 27 30
197 30 ▶ $header->set_force_fold_at( $self->force_fold_at() ) if defined $self->force_fold_at();
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->force_fold_at 0 30 30
198 30 $header->set_eol( $self->eol() );
199 30 $header->set_indent( ' ' x $self->indent_by() );
200 30 $header->set_sub_indent( ' ' );
201 30 $self->build_string( $header );
202 30 return $header->as_string();
203 }
204  
205 sub build_string {
206 32 ▶ my ( $self, $header ) = @_;
Subroutine build_string: called CC=5 SCAR=16.1
Pod documented
207 32 my $value = q{};
208 32 ▶ if ( $self->value() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->value) { } 31 1 32
209 31 $self->value()->build_string( $header );
210 }
211 else {
212 1 $header->string( 'unknown' );
213 }
214 32 $header->separator( ';' );
215  
216 32 my $sep = 0;
217 32 foreach my $child ( @{ $self->children() } ) {
218 79 ▶ $header->separator( ';' ) if $sep;
Branch: 1 branch
BranchTrueFalseTotal
if $sep 58 21 79
219 79 $sep = 1;
220 79 $child->as_string_prefix( $header );
221 79 $child->build_string( $header );
222 }
223  
224 32 ▶ if ( scalar @{ $self->search({ 'isa' => 'entry' } )->children() } == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @{$self->search({"isa", "entry"})->children;} == 0) 13 19 32
225 #if ( scalar @{ $self->children() } > 0 ) {
226 # $value .= ' ';
227 #}
228 13 $header->space( ' ' );
229 13 $header->string ( 'none' );
230 }
231  
232 32 return;
233 }
234  
235 28 1;
236  
237 __END__
« blib/lib/Mail/AuthenticationResults/Token/Comment.pm ↑ Summary lib/Mail/AuthenticationResults/Token/String.pm »