lib/Mail/AuthenticationResults/Header.pm

filter: Statementstmt 100% 136 / 136 Branchbran 92.5% 49 / 54 (1 uncoverable) Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 27 / 27 Podpod 100% 18 / 18 totaltotal 98.3% 230 / 235 (1 uncoverable) CC 29 SCAR 11.9
CC
29
Cov
98%
indent_on
7.0
set_indent_style
5.0
build_string
5.0
CRAP 3.3
« lib/Mail/AuthenticationResults/Token/Comment.pm ↑ Summary lib/Mail/AuthenticationResults/Header/Version.pm »
1 package Mail::AuthenticationResults::Header;
2 # ABSTRACT: Class modelling the Entire Authentication Results Header set
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.20261029'; # VERSION
8 30 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 30 ▶use Mail::AuthenticationResults::Header::AuthServID;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 30 ▶use base 'Mail::AuthenticationResults::Header::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14  
15 302 ▶sub _HAS_VALUE{ return 1; }
Subroutine _HAS_VALUE: called CC=1 SCAR=0.0
16 2443 ▶sub _HAS_CHILDREN{ return 1; }
Subroutine _HAS_CHILDREN: called CC=1 SCAR=0.0
17  
18 4255 ▶sub _ALLOWED_CHILDREN {
Subroutine _ALLOWED_CHILDREN: called CC=3 SCAR=11.0
19 4255 my ( $self, $child ) = @_;
20 4255 ▶ return 1 if ref $child eq 'Mail::AuthenticationResults::Header::Comment';
Branch: 1 branch
BranchTrueFalseTotal
if ref $child eq "Mail::AuthenticationResults::Header::Comment" 11 4244 4255
21 4244 ▶ return 1 if ref $child eq 'Mail::AuthenticationResults::Header::Entry';
Branch: 1 branch
BranchTrueFalseTotal
if ref $child eq "Mail::AuthenticationResults::Header::Entry" 4238 6 4244
22 6 return 0;
23 }
24  
25  
26 8 ▶sub set_indent_by {
Subroutine set_indent_by: called CC=1 SCAR=0.0
Pod documented
27 8 my ( $self, $value ) = @_;
28 8 $self->{ 'indent_by' } = $value;
29 8 return $self;
30 }
31  
32  
33 325 ▶sub indent_by {
Subroutine indent_by: called CC=2 SCAR=6.9
Pod documented
34 325 my ( $self ) = @_;
35 325 ▶ return 4 if ! defined $self->{ 'indent_by' }; #5.8
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"indent_by"} 184 141 325
36 141 return $self->{ 'indent_by'};
37 }
38  
39  
40 13 ▶sub set_indent_on {
Subroutine set_indent_on: called CC=1 SCAR=0.0
Pod documented
41 13 my ( $self, $type ) = @_;
42 13 $self->{ 'indent_type_' . $type } = 1;
43 13 return $self;
44 }
45  
46  
47 20 ▶sub clear_indent_on {
Subroutine clear_indent_on: called CC=1 SCAR=0.0
Pod documented
48 20 my ( $self, $type ) = @_;
49 20 $self->{ 'indent_type_' . $type } = 0;
50 20 return $self;
51 }
52  
53  
54 292 ▶sub indent_on {
Subroutine indent_on: called CC=7 SCAR=19.5
Pod documented
55 292 my ( $self, $type ) = @_;
56 292 ▶ if ( $type eq 'Mail::AuthenticationResults::Header::Entry' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "Mail::AuthenticationResults::Header::Entry") 92 200 292
57 92 ▶ return 1 if ! defined $self->{ 'indent_type_' . $type }; #5.8
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$self{'indent_type_' . $type} 36 56 92
58 56 return $self->{ 'indent_type_' . $type };
59 }
60 200 ▶ if ( $type eq 'Mail::AuthenticationResults::Header::SubEntry' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'Mail::AuthenticationResults::Header::SubEntry') { } 119 81 200
elsif ($type eq 'Mail::AuthenticationResults::Header::Comment') { } 80 1 81
61 119 ▶ return 0 if ! defined $self->{ 'indent_type_' . $type }; #5.8
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$self{'indent_type_' . $type} 44 75 119
62 75 return $self->{ 'indent_type_' . $type };
63 }
64 elsif ( $type eq 'Mail::AuthenticationResults::Header::Comment' ) {
65 80 ▶ return 0 if ! defined $self->{ 'indent_type_' . $type }; #5.8
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$self{'indent_type_' . $type} 46 34 80
66 34 return $self->{ 'indent_type_' . $type };
67 }
68 1 return 0;
69 }
70  
71  
72 3 ▶sub set_eol {
Subroutine set_eol: called CC=2 SCAR=6.9
Pod documented
73 3 my ( $self, $eol ) = @_;
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 325 ▶sub eol {
Subroutine eol: called CC=2 SCAR=6.9
Pod documented
85 325 my ( $self ) = @_;
86 325 ▶ return "\n" if ! defined $self->{ 'eol' }; #5.8
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"eol"} 311 14 325
87 14 return $self->{ 'eol' };
88 }
89  
90  
91 38 ▶sub fold_at {
Subroutine fold_at: called CC=1 SCAR=0.0
Pod documented
92 38 my ( $self ) = @_;
93 38 return $self->{ 'fold_at' };
94 }
95  
96  
97 4 ▶sub set_fold_at {
Subroutine set_fold_at: called CC=1 SCAR=0.0
Pod documented
98 4 my ( $self, $fold_at ) = @_;
99 4 $self->{ 'fold_at' } = $fold_at;
100 4 return $self;
101 }
102  
103  
104 35 ▶sub force_fold_at {
Subroutine force_fold_at: called CC=1 SCAR=0.0
Pod documented
105 35 my ( $self ) = @_;
106 35 return $self->{ 'force_fold_at' };
107 }
108  
109  
110 1 ▶sub set_force_fold_at {
Subroutine set_force_fold_at: called CC=1 SCAR=0.0
Pod documented
111 1 my ( $self, $fold_at ) = @_;
112 1 $self->{ 'force_fold_at' } = $fold_at;
113 1 return $self;
114 }
115  
116  
117 12 ▶sub set_indent_style {
Subroutine set_indent_style: called CC=5 SCAR=16.1
Pod documented
118 12 my ( $self, $style ) = @_;
119  
120 12 ▶ if ( $style eq 'none' ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($style eq 'none') { } 3 9 12
elsif ($style eq 'entry') { } 5 4 9
elsif ($style eq 'subentry') { } 1 3 4
elsif ($style eq 'full') { } 2 1 3
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 2 $self->set_indent_by( 4 );
139 2 $self->set_indent_on( 'Mail::AuthenticationResults::Header::Entry' );
140 2 $self->set_indent_on( 'Mail::AuthenticationResults::Header::SubEntry' );
141 2 $self->set_indent_on( 'Mail::AuthenticationResults::Header::Comment' );
142 }
143 else {
144 1 croak "Unknown indent style $style";
145 }
146  
147 11 return $self;
148 }
149  
150 5 ▶sub safe_set_value {
Subroutine safe_set_value: called CC=1 SCAR=0.0
Pod documented
151 5 my ( $self, $value ) = @_;
152 5 $self->set_value( $value );
153 3 return $self;
154 }
155  
156 61 ▶sub set_value {
Subroutine set_value: called CC=4 SCAR=13.9
Pod documented
157 61 my ( $self, $value ) = @_;
158 61 ▶ croak 'Does not have value' if ! $self->_HAS_VALUE(); # uncoverable branch true
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_HAS_VALUE 0 61 61
159 # HAS_VALUE is 1 for this class
160 61 ▶ croak 'Value cannot be undefined' if ! defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 2 59 61
161 59 ▶ 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 57 59
162 57 $self->{ 'value' } = $value;
163 57 return $self;
164 }
165  
166 20 ▶sub add_parent {
Subroutine add_parent: called CC=1 SCAR=0.0
Pod documented
167 20 my ( $self, $parent ) = @_;
168 20 return;
169 }
170  
171 2132 ▶sub add_child {
Subroutine add_child: called CC=2 SCAR=6.9
Pod documented
172 2132 my ( $self, $child ) = @_;
173 2132 ▶ 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" 2 2130 2132
174 2130 return $self->SUPER::add_child( $child );
175 }
176  
177 2 ▶sub _as_hashref {
Subroutine _as_hashref: called CC=4 SCAR=14.0
178 2 my ( $self ) = @_;
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 33 ▶sub as_string {
Subroutine as_string: called CC=3 SCAR=11.0
Pod documented
194 33 my ( $self ) = @_;
195 33 my $header = Mail::AuthenticationResults::FoldableHeader->new();
196 33 ▶ $header->set_try_fold_at( $self->fold_at() ) if defined $self->fold_at();
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->fold_at 3 30 33
197 33 ▶ $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 33 33
198 33 $header->set_eol( $self->eol() );
199 33 $header->set_indent( ' ' x $self->indent_by() );
200 33 $header->set_sub_indent( ' ' );
201 33 $self->build_string( $header );
202 33 return $header->as_string();
203 }
204  
205 35 ▶sub build_string {
Subroutine build_string: called CC=5 SCAR=16.1
Pod documented
206 35 my ( $self, $header ) = @_;
207 35 my $value = q{};
208 35 ▶ if ( $self->value() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->value) { } 32 3 35
209 32 $self->value()->build_string( $header );
210 }
211 else {
212 3 $header->string( 'unknown' );
213 }
214 35 $header->separator( ';' );
215  
216 35 my $sep = 0;
217 35 foreach my $child ( @{ $self->children() } ) {
218 95 ▶ $header->separator( ';' ) if $sep;
Branch: 1 branch
BranchTrueFalseTotal
if $sep 71 24 95
219 95 $sep = 1;
220 95 $child->as_string_prefix( $header );
221 95 $child->build_string( $header );
222 }
223  
224 35 ▶ if ( scalar @{ $self->search({ 'isa' => 'entry' } )->children() } == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @{$self->search({"isa", "entry"})->children;} == 0) 13 22 35
225 #if ( scalar @{ $self->children() } > 0 ) {
226 # $value .= ' ';
227 #}
228 13 $header->space( ' ' );
229 13 $header->string ( 'none' );
230 }
231  
232 35 return;
233 }
234  
235 30 1;
236  
237 __END__
« lib/Mail/AuthenticationResults/Token/Comment.pm ↑ Summary lib/Mail/AuthenticationResults/Header/Version.pm »