« lib/Mail/AuthenticationResults/Token/Comment.pm
↑ Summary
blib/lib/Mail/AuthenticationResults/Token/Assignment.pm »
| 1 | package Mail::AuthenticationResults::Header; | ||||||||||||||||||||||
| 2 | # ABSTRACT: Class modelling the Entire Authentication Results Header set | ||||||||||||||||||||||
| 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.20260216'; # VERSION | |||||||||||||||||||||
| 8 | 29 | ▶ | use Carp; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 9 | |||||||||||||||||||||||
| 10 | 29 | ▶ | use Mail::AuthenticationResults::Header::AuthServID; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 11 | |||||||||||||||||||||||
| 12 | 29 | ▶ | use base 'Mail::AuthenticationResults::Header::Base'; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 13 | |||||||||||||||||||||||
| 14 | |||||||||||||||||||||||
| 15 | 300 | ▶ | sub _HAS_VALUE{ return 1; } | ||||||||||||||||||||
|
Subroutine
_HAS_VALUE: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 16 | 441 | ▶ | sub _HAS_CHILDREN{ return 1; } | ||||||||||||||||||||
|
Subroutine
_HAS_CHILDREN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 17 | |||||||||||||||||||||||
| 18 | 255 | ▶ | sub _ALLOWED_CHILDREN { | ||||||||||||||||||||
|
Subroutine
_ALLOWED_CHILDREN: called CC=3 SCAR=11.0
| |||||||||||||||||||||||
| 19 | 255 | my ( $self, $child ) = @_; | |||||||||||||||||||||
| 20 | 255 | ▶ | return 1 if ref $child eq 'Mail::AuthenticationResults::Header::Comment'; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 21 | 244 | ▶ | return 1 if ref $child eq 'Mail::AuthenticationResults::Header::Entry'; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 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
| |||||||||||||||||||||||
| 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
| |||||||||||||||||||||||
| 57 | 92 | ▶ | return 1 if ! defined $self->{ 'indent_type_' . $type }; #5.8 | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 58 | 56 | return $self->{ 'indent_type_' . $type }; | |||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||
| 60 | 200 | ▶ | if ( $type eq 'Mail::AuthenticationResults::Header::SubEntry' ) { | ||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||
| 61 | 119 | ▶ | return 0 if ! defined $self->{ 'indent_type_' . $type }; #5.8 | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 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
| |||||||||||||||||||||||
| 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
| |||||||||||||||||||||||
| 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
| |||||||||||||||||||||||
| 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
| |||||||||||||||||||||||
| 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 | 60 | ▶ | sub set_value { | ||||||||||||||||||||
|
Subroutine
set_value: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||
| 157 | 60 | my ( $self, $value ) = @_; | |||||||||||||||||||||
| 158 | 60 | ▶ | croak 'Does not have value' if ! $self->_HAS_VALUE(); # uncoverable branch true | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 159 | # HAS_VALUE is 1 for this class | ||||||||||||||||||||||
| 160 | 60 | ▶ | croak 'Value cannot be undefined' if ! defined $value; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 161 | 58 | ▶ | croak 'value should be an AuthServID type' if ref $value ne 'Mail::AuthenticationResults::Header::AuthServID'; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 162 | 56 | $self->{ 'value' } = $value; | |||||||||||||||||||||
| 163 | 56 | 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 | 132 | ▶ | sub add_child { | ||||||||||||||||||||
|
Subroutine
add_child: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||
| 172 | 132 | my ( $self, $child ) = @_; | |||||||||||||||||||||
| 173 | 132 | ▶ | croak 'Cannot add a SubEntry as a child of a Header' if ref $child eq 'Mail::AuthenticationResults::Header::SubEntry'; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 174 | 130 | 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
| |||||||||||||||||||||||
| 185 | 2 | ▶ | $hashref->{'authserv_id'} = $self->value()->_as_hashref() if $self->value(); | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 186 | 2 | ▶ | if ( $self->_HAS_CHILDREN() ) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 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
| |||||||||||||||||||||||
| 197 | 33 | ▶ | $header->set_force_fold_at( $self->force_fold_at() ) if defined $self->force_fold_at(); | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 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
| |||||||||||||||||||||||
| 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
| |||||||||||||||||||||||
| 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
| |||||||||||||||||||||||
| 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 | 29 | 1; | |||||||||||||||||||||
| 236 | |||||||||||||||||||||||
| 237 | __END__ | ||||||||||||||||||||||