File Coverage

lib/Mail/AuthenticationResults/Header/Group.pm
Criterion Covered Total %
statement 47 47 100.0
branch 26 26 100.0
condition n/a
subroutine 9 9 100.0
pod 2 2 100.0
total 84 84 100.0


line stmt bran cond sub pod time code
1             package Mail::AuthenticationResults::Header::Group;
2             # ABSTRACT: Class modelling Groups of Authentication Results Header parts
3              
4             require 5.008;
5 30     30   159488 use strict;
  30         64  
  30         7176  
6 30     30   163 use warnings;
  30         52  
  30         2665  
7             our $VERSION = '2.20260216'; # VERSION
8 30     30   195 use Scalar::Util qw{ refaddr };
  30         48  
  30         1747  
9 30     30   230 use Carp;
  30         52  
  30         1806  
10              
11 30     30   176 use base 'Mail::AuthenticationResults::Header::Base';
  30         46  
  30         15194  
12              
13              
14 2379     2379   4795 sub _HAS_CHILDREN{ return 1; }
15              
16             sub _ALLOWED_CHILDREN {
17 1058     1058   1675 my ( $self, $child ) = @_;
18 1058 100       2442 return 1 if ref $child eq 'Mail::AuthenticationResults::Header';
19 1016 100       2722 return 1 if ref $child eq 'Mail::AuthenticationResults::Header::AuthServID';
20 1012 100       2022 return 1 if ref $child eq 'Mail::AuthenticationResults::Header::Comment';
21 1000 100       2673 return 1 if ref $child eq 'Mail::AuthenticationResults::Header::Entry';
22 424 100       1199 return 1 if ref $child eq 'Mail::AuthenticationResults::Header::Group';
23 207 100       557 return 1 if ref $child eq 'Mail::AuthenticationResults::Header::SubEntry';
24 5 100       10 return 1 if ref $child eq 'Mail::AuthenticationResults::Header::Version';
25 1         10 return 0;
26             }
27              
28             sub add_child {
29 638     638 1 6817 my ( $self, $child ) = @_;
30 638 100       1397 croak 'Cannot add child' if ! $self->_ALLOWED_CHILDREN( $child );
31 637 100       1477 croak 'Cannot add a class as its own parent' if refaddr $self == refaddr $child;
32              
33 636 100       1292 if ( ref $child eq 'Mail::AuthenticationResults::Header::Group' ) {
34 216         392 foreach my $subchild ( @{ $child->children() } ) {
  216         694  
35 215         621 $self->add_child( $subchild );
36             }
37             ## ToDo what to return in this case?
38             }
39             else {
40 420         678 foreach my $current_child ( @{ $self->children() } ) {
  420         957  
41 350 100       817 if ( $current_child == $child ) {
42 6         18 return $child;
43             }
44             }
45 414         1263 $self->SUPER::add_child( $child );
46             }
47              
48 630         1650 return $child;
49             }
50              
51             sub build_string {
52 18     18 1 34 my ( $self, $header ) = @_;
53              
54 18         28 my $sep = 0;
55 18         39 foreach my $child ( @{ $self->children() } ) {
  18         49  
56 20 100       59 $header->separator( ';' ) if $sep;
57 20 100       57 $header->space( "\n" ) if $sep;
58 20         31 $sep = 1;
59 20         163 $child->build_string( $header );
60             }
61              
62 18         34 return;
63             }
64              
65             1;
66              
67             __END__