File Coverage

lib/Mail/DMARC/Report/Aggregate/Metadata.pm
Criterion Covered Total %
statement 47 47 100.0
branch 21 22 95.4
condition 2 3 66.6
subroutine 14 14 100.0
pod 0 10 0.0
total 84 96 87.5


line stmt bran cond sub pod time code
1             package Mail::DMARC::Report::Aggregate::Metadata;
2 12     12   90 use strict;
  12         27  
  12         367  
3 12     12   68 use warnings;
  12         70  
  12         500  
4              
5             our $VERSION = '1.20230215';
6              
7 12     12   82 use XML::LibXML;
  12         29  
  12         123  
8              
9 12     12   2002 use parent 'Mail::DMARC::Base';
  12         31  
  12         95  
10              
11             sub org_name {
12 63 100   63 0 960 return $_[0]->{org_name} if 1 == scalar @_;
13 17         92 return $_[0]->{org_name} = $_[1];
14             }
15              
16             sub email {
17 48 100   48 0 1064 return $_[0]->{email} if 1 == scalar @_;
18 17         276 return $_[0]->{email} = $_[1];
19             }
20              
21             sub extra_contact_info {
22 30 100   30 0 866 return $_[0]->{extra_contact_info} if 1 == scalar @_;
23 13         48 return $_[0]->{extra_contact_info} = $_[1];
24             }
25              
26             sub report_id {
27 54 100   54 0 1003 return $_[0]->{report_id} if 1 == scalar @_;
28 14         69 return $_[0]->{report_id} = $_[1];
29             }
30              
31             sub date_range {
32 2 100   2 0 762 return $_[0]->{date_range} if 1 == scalar @_;
33              
34             # croak "invalid date_range" if ('HASH' ne ref $_->[1]);
35 1         7 return $_[0]->{date_range} = $_[1];
36             }
37              
38             sub begin {
39 47 100   47 0 1024 return $_[0]->{date_range}{begin} if 1 == scalar @_;
40 18         96 return $_[0]->{date_range}{begin} = $_[1];
41             }
42              
43             sub end {
44 47 100   47 0 1017 return $_[0]->{date_range}{end} if 1 == scalar @_;
45 18         79 return $_[0]->{date_range}{end} = $_[1];
46             }
47              
48             sub error {
49 11 100   11 0 2150 return $_[0]->{error} if 1 == scalar @_;
50 3         4 return push @{ $_[0]->{error} }, $_[1];
  3         18  
51             }
52              
53             sub uuid {
54 18 100   18 0 850 return $_[0]->{uuid} if 1 == scalar @_;
55 3         15 return $_[0]->{uuid} = $_[1];
56             }
57              
58             sub as_xml {
59 7     7 0 801 my $self = shift;
60 7         16 my $meta = "\t\n";
61              
62 7         18 foreach my $f (qw/ org_name email extra_contact_info report_id /) {
63 28 50       76 my $val = $self->$f or next;
64 28         642 $val = XML::LibXML::Text->new( $val )->toString();
65 28         233 $meta .= "\t\t<$f>$val\n";
66             }
67 7         24 my $begin = XML::LibXML::Text->new( $self->begin )->toString();
68 7         36 my $end = XML::LibXML::Text->new( $self->end )->toString();
69 7         56 $meta .= "\t\t\n\t\t\t" . $begin . "\n"
70             . "\t\t\t" . $end . "\n\t\t\n";
71              
72 7         25 my $errors = $self->error;
73 7 100 66     43 if ( $errors && @$errors ) {
74 3         8 foreach my $err ( @$errors ) {
75 4         40 $err = XML::LibXML::Text->new( $err )->toString();
76 4         21 $meta .= "\t\t$err\n";
77             };
78             };
79 7         18 $meta .= "\t";
80 7         37 return $meta;
81             }
82              
83             1;
84              
85             __END__