« blib/lib/Mail/AuthenticationResults/Header/Comment.pm
↑ Summary
lib/Mail/AuthenticationResults/Token/String.pm »
| 1 | package Mail::AuthenticationResults::Header::Group; | ||
| 2 | # ABSTRACT: Class modelling Groups of Authentication Results Header parts | ||
| 3 | |||
| 4 | require 5.008; | ||
| 5 | use strict; | ||
| 6 | use warnings; | ||
| 7 | our $VERSION = '2.20260216'; # VERSION | ||
| 8 | use Scalar::Util qw{ refaddr }; | ||
| 9 | use Carp; | ||
| 10 | |||
| 11 | use base 'Mail::AuthenticationResults::Header::Base'; | ||
| 12 | |||
| 13 | |||
| 14 | sub _HAS_CHILDREN{ return 1; } | ||
| 15 | |||
| 16 | sub _ALLOWED_CHILDREN { | ||
| 17 | my ( $self, $child ) = @_; | ||
| 18 | return 1 if ref $child eq 'Mail::AuthenticationResults::Header'; | ||
| 19 | return 1 if ref $child eq 'Mail::AuthenticationResults::Header::AuthServID'; | ||
| 20 | return 1 if ref $child eq 'Mail::AuthenticationResults::Header::Comment'; | ||
| 21 | return 1 if ref $child eq 'Mail::AuthenticationResults::Header::Entry'; | ||
| 22 | return 1 if ref $child eq 'Mail::AuthenticationResults::Header::Group'; | ||
| 23 | return 1 if ref $child eq 'Mail::AuthenticationResults::Header::SubEntry'; | ||
| 24 | return 1 if ref $child eq 'Mail::AuthenticationResults::Header::Version'; | ||
| 25 | return 0; | ||
| 26 | } | ||
| 27 | |||
| 28 | sub add_child { | ||
| 29 | my ( $self, $child ) = @_; | ||
| 30 | croak 'Cannot add child' if ! $self->_ALLOWED_CHILDREN( $child ); | ||
| 31 | croak 'Cannot add a class as its own parent' if refaddr $self == refaddr $child; | ||
| 32 | |||
| 33 | if ( ref $child eq 'Mail::AuthenticationResults::Header::Group' ) { | ||
| 34 | foreach my $subchild ( @{ $child->children() } ) { | ||
| 35 | $self->add_child( $subchild ); | ||
| 36 | } | ||
| 37 | ## ToDo what to return in this case? | ||
| 38 | } | ||
| 39 | else { | ||
| 40 | foreach my $current_child ( @{ $self->children() } ) { | ||
| 41 | if ( $current_child == $child ) { | ||
| 42 | return $child; | ||
| 43 | } | ||
| 44 | } | ||
| 45 | $self->SUPER::add_child( $child ); | ||
| 46 | } | ||
| 47 | |||
| 48 | return $child; | ||
| 49 | } | ||
| 50 | |||
| 51 | sub build_string { | ||
| 52 | my ( $self, $header ) = @_; | ||
| 53 | |||
| 54 | my $sep = 0; | ||
| 55 | foreach my $child ( @{ $self->children() } ) { | ||
| 56 | $header->separator( ';' ) if $sep; | ||
| 57 | $header->space( "\n" ) if $sep; | ||
| 58 | $sep = 1; | ||
| 59 | $child->build_string( $header ); | ||
| 60 | } | ||
| 61 | |||
| 62 | return; | ||
| 63 | } | ||
| 64 | |||
| 65 | 1; | ||
| 66 | |||
| 67 | __END__ |