require
5.008;
our
$VERSION
=
'2.20231031'
;
sub
_HAS_VALUE{
return
1; }
sub
_HAS_CHILDREN{
return
1; }
sub
_ALLOWED_CHILDREN {
my
(
$self
,
$child
) =
@_
;
return
1
if
ref
$child
eq
'Mail::AuthenticationResults::Header::Comment'
;
return
1
if
ref
$child
eq
'Mail::AuthenticationResults::Header::Entry'
;
return
0;
}
sub
set_indent_by {
my
(
$self
,
$value
) =
@_
;
$self
->{
'indent_by'
} =
$value
;
return
$self
;
}
sub
indent_by {
my
(
$self
) =
@_
;
return
4
if
!
defined
$self
->{
'indent_by'
};
return
$self
->{
'indent_by'
};
}
sub
set_indent_on {
my
(
$self
,
$type
) =
@_
;
$self
->{
'indent_type_'
.
$type
} = 1;
return
$self
;
}
sub
clear_indent_on {
my
(
$self
,
$type
) =
@_
;
$self
->{
'indent_type_'
.
$type
} = 0;
return
$self
;
}
sub
indent_on {
my
(
$self
,
$type
) =
@_
;
if
(
$type
eq
'Mail::AuthenticationResults::Header::Entry'
) {
return
1
if
!
defined
$self
->{
'indent_type_'
.
$type
};
return
$self
->{
'indent_type_'
.
$type
};
}
if
(
$type
eq
'Mail::AuthenticationResults::Header::SubEntry'
) {
return
0
if
!
defined
$self
->{
'indent_type_'
.
$type
};
return
$self
->{
'indent_type_'
.
$type
};
}
elsif
(
$type
eq
'Mail::AuthenticationResults::Header::Comment'
) {
return
0
if
!
defined
$self
->{
'indent_type_'
.
$type
};
return
$self
->{
'indent_type_'
.
$type
};
}
return
0;
}
sub
set_eol {
my
(
$self
,
$eol
) =
@_
;
if
(
$eol
=~ /^\r?\n$/ ) {
$self
->{
'eol'
} =
$eol
;
}
else
{
croak
'Invalid eol string'
;
}
return
$self
;
}
sub
eol {
my
(
$self
) =
@_
;
return
"\n"
if
!
defined
$self
->{
'eol'
};
return
$self
->{
'eol'
};
}
sub
fold_at {
my
(
$self
) =
@_
;
return
$self
->{
'fold_at'
};
}
sub
set_fold_at {
my
(
$self
,
$fold_at
) =
@_
;
$self
->{
'fold_at'
} =
$fold_at
;
return
$self
;
}
sub
force_fold_at {
my
(
$self
) =
@_
;
return
$self
->{
'force_fold_at'
};
}
sub
set_force_fold_at {
my
(
$self
,
$fold_at
) =
@_
;
$self
->{
'force_fold_at'
} =
$fold_at
;
return
$self
;
}
sub
set_indent_style {
my
(
$self
,
$style
) =
@_
;
if
(
$style
eq
'none'
) {
$self
->clear_indent_on(
'Mail::AuthenticationResults::Header::Entry'
);
$self
->clear_indent_on(
'Mail::AuthenticationResults::Header::SubEntry'
);
$self
->clear_indent_on(
'Mail::AuthenticationResults::Header::Comment'
);
}
elsif
(
$style
eq
'entry'
) {
$self
->set_indent_by( 4 );
$self
->set_indent_on(
'Mail::AuthenticationResults::Header::Entry'
);
$self
->clear_indent_on(
'Mail::AuthenticationResults::Header::SubEntry'
);
$self
->clear_indent_on(
'Mail::AuthenticationResults::Header::Comment'
);
}
elsif
(
$style
eq
'subentry'
) {
$self
->set_indent_by( 4 );
$self
->set_indent_on(
'Mail::AuthenticationResults::Header::Entry'
);
$self
->set_indent_on(
'Mail::AuthenticationResults::Header::SubEntry'
);
$self
->clear_indent_on(
'Mail::AuthenticationResults::Header::Comment'
);
}
elsif
(
$style
eq
'full'
) {
$self
->set_indent_by( 4 );
$self
->set_indent_on(
'Mail::AuthenticationResults::Header::Entry'
);
$self
->set_indent_on(
'Mail::AuthenticationResults::Header::SubEntry'
);
$self
->set_indent_on(
'Mail::AuthenticationResults::Header::Comment'
);
}
else
{
croak
"Unknown indent style $style"
;
}
return
$self
;
}
sub
safe_set_value {
my
(
$self
,
$value
) =
@_
;
$self
->set_value(
$value
);
return
$self
;
}
sub
set_value {
my
(
$self
,
$value
) =
@_
;
croak
'Does not have value'
if
!
$self
->_HAS_VALUE();
croak
'Value cannot be undefined'
if
!
defined
$value
;
croak
'value should be an AuthServID type'
if
ref
$value
ne
'Mail::AuthenticationResults::Header::AuthServID'
;
$self
->{
'value'
} =
$value
;
return
$self
;
}
sub
add_parent {
my
(
$self
,
$parent
) =
@_
;
return
;
}
sub
add_child {
my
(
$self
,
$child
) =
@_
;
croak
'Cannot add a SubEntry as a child of a Header'
if
ref
$child
eq
'Mail::AuthenticationResults::Header::SubEntry'
;
return
$self
->SUPER::add_child(
$child
);
}
sub
_as_hashref {
my
(
$self
) =
@_
;
my
$type
=
lc
ref
$self
;
$type
=~ s/^(.*::)//;
my
$hashref
= {
'type'
=>
$type
};
$hashref
->{
'key'
} =
$self
->key()
if
$self
->_HAS_KEY();
$hashref
->{
'authserv_id'
} =
$self
->value()->_as_hashref()
if
$self
->value();
if
(
$self
->_HAS_CHILDREN() ) {
my
@children
=
map
{
$_
->_as_hashref() } @{
$self
->children() };
$hashref
->{
'children'
} = \
@children
;
}
return
$hashref
;
}
sub
as_string {
my
(
$self
) =
@_
;
my
$header
= Mail::AuthenticationResults::FoldableHeader->new();
$header
->set_try_fold_at(
$self
->fold_at() )
if
defined
$self
->fold_at();
$header
->set_force_fold_at(
$self
->force_fold_at() )
if
defined
$self
->force_fold_at();
$header
->set_eol(
$self
->eol() );
$header
->set_indent(
' '
x
$self
->indent_by() );
$header
->set_sub_indent(
' '
);
$self
->build_string(
$header
);
return
$header
->as_string();
}
sub
build_string {
my
(
$self
,
$header
) =
@_
;
my
$value
=
q{}
;
if
(
$self
->value() ) {
$self
->value()->build_string(
$header
);
}
else
{
$header
->string(
'unknown'
);
}
$header
->separator(
';'
);
my
$sep
= 0;
foreach
my
$child
( @{
$self
->children() } ) {
$header
->separator(
';'
)
if
$sep
;
$sep
= 1;
$child
->as_string_prefix(
$header
);
$child
->build_string(
$header
);
}
if
(
scalar
@{
$self
->search({
'isa'
=>
'entry'
} )->children() } == 0 ) {
$header
->space(
' '
);
$header
->string (
'none'
);
}
return
;
}
1;