File Coverage

blib/lib/Mail/Message/Head/FieldGroup.pm
Criterion Covered Total %
statement 50 76 65.7
branch 3 16 18.7
condition 2 11 18.1
subroutine 16 24 66.6
pod 18 19 94.7
total 89 146 60.9


line stmt bran cond sub pod time code
1             # This code is part of Perl distribution Mail-Message version 4.04.
2             # The POD got stripped from this file by OODoc version 3.06.
3             # For contributors see file ChangeLog.
4              
5             # This software is copyright (c) 2001-2026 by Mark Overmeer.
6              
7             # This is free software; you can redistribute it and/or modify it under
8             # the same terms as the Perl 5 programming language system itself.
9             # SPDX-License-Identifier: Artistic-1.0-Perl OR GPL-1.0-or-later
10              
11              
12             package Mail::Message::Head::FieldGroup;{
13             our $VERSION = '4.04';
14             }
15              
16 5     5   11116 use parent 'Mail::Reporter';
  5         12  
  5         39  
17              
18 5     5   405 use strict;
  5         12  
  5         146  
19 5     5   25 use warnings;
  5         12  
  5         396  
20              
21 5     5   33 use Log::Report 'mail-message', import => [ qw/trace/ ];
  5         10  
  5         58  
22              
23 5     5   971 use Scalar::Util qw/blessed/;
  5         21  
  5         8200  
24              
25             #--------------------
26              
27             sub new(@)
28 79     79 1 761095 { my $class = shift;
29              
30 79         137 my @fields;
31 79         311 push @fields, shift while blessed $_[0];
32              
33 79         407 $class->SUPER::new(@_, fields => \@fields);
34             }
35              
36             sub init($$)
37 79     79 0 231 { my ($self, $args) = @_;
38 79         265 $self->SUPER::init($args);
39              
40 79   66     422 my $head = $self->{MMHF_head} = $args->{head} || Mail::Message::Head::Partial->new;
41              
42             $self->add($_) # add specified object fields
43 79         144 for @{$args->{fields}};
  79         261  
44              
45             $self->add($_, delete $args->{$_}) # add key-value paired fields
46 79         664 for grep m/^[A-Z]/, keys %$args;
47              
48 79 50       347 $self->{MMHF_version} = $args->{version} if defined $args->{version};
49 79 50       248 $self->{MMHF_software} = $args->{software} if defined $args->{software};
50 79 50       210 $self->{MMHF_type} = $args->{type} if defined $args->{type};
51 79         195 $self->{MMHF_fns} = [];
52 79         392 $self;
53             }
54              
55              
56 0     0 1 0 sub implementedTypes() { $_[0]->notImplemented }
57              
58              
59 0     0 1 0 sub from($) { $_[0]->notImplemented }
60              
61              
62             sub clone()
63 0     0 1 0 { my $self = shift;
64 0         0 my $clone = bless %$self, ref $self;
65 0         0 $clone->{MMHF_fns} = [ $self->fieldNames ];
66 0         0 $clone;
67             }
68              
69             #--------------------
70              
71 386     386 1 1091 sub head() { $_[0]->{MMHF_head} }
72              
73              
74             sub attach($)
75 0     0 1 0 { my ($self, $head) = @_;
76 0         0 $head->add($_->clone) for $self->fields;
77 0         0 $self;
78             }
79              
80              
81             sub delete()
82 12     12 1 37 { my $self = shift;
83 12         40 my $head = $self->head;
84 12         49 $head->removeField($_) for $self->fields;
85 12         51 $self;
86             }
87              
88              
89             sub add(@)
90 0     0 1 0 { my $self = shift;
91 0 0       0 my $field = $self->head->add(@_) or return ();
92 0         0 push @{$self->{MMHF_fns}}, $field->name;
  0         0  
93 0         0 $self;
94             }
95              
96              
97             sub fields()
98 75     75 1 124 { my $self = shift;
99 75         180 my $head = $self->head;
100 75         195 map $head->get($_), $self->fieldNames;
101             }
102              
103              
104 75     75 1 137 sub fieldNames() { @{ $_[0]->{MMHF_fns}} }
  75         461  
105              
106              
107             sub addFields(@)
108 53     53 1 107 { my $self = shift;
109 53         145 my $head = $self->head;
110              
111 53         123 push @{$self->{MMHF_fns}}, @_;
  53         304  
112 53         132 @_;
113             }
114              
115             #--------------------
116              
117 35     35 1 199 sub version() { $_[0]->{MMHF_version} }
118              
119              
120 35     35 1 156 sub software() { $_[0]->{MMHF_software} }
121              
122              
123 106     106 1 14295 sub type() { $_[0]->{MMHF_type} }
124              
125             #--------------------
126              
127             sub detected($$$)
128 51     51 1 99 { my $self = shift;
129 51         239 @$self{ qw/MMHF_type MMHF_software MMHF_version/ } = @_;
130             }
131              
132              
133 0     0 1   sub collectFields(;$) { $_[0]->notImplemented }
134              
135             #--------------------
136              
137             sub print(;$)
138 0     0 1   { my $self = shift;
139 0   0       my $out = shift || select;
140 0           $_->print($out) for $self->fields;
141             }
142              
143              
144             sub details()
145 0     0 1   { my $self = shift;
146 0   0       my $type = $self->type || 'Unknown';
147              
148 0           my $software = $self->software;
149 0 0 0       undef $software if defined($software) && $type eq $software;
150 0           my $version = $self->version;
151 0 0         my $release = defined $software
    0          
    0          
152             ? (defined $version ? " ($software $version)" : " ($software)")
153             : (defined $version ? " ($version)" : '');
154              
155 0           my $fields = scalar $self->fields;
156 0           "$type $release, $fields fields";
157             }
158              
159             1;