Message/Head.pm

filter: Statementstmt 80.0% 92 / 115 Branchbran 75.0% 30 / 40 Conditioncond 50.0% 2 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 67.6% 23 / 34 Podpod 76.0% 19 / 25 totaltotal 75.4% 166 / 220 SCAR 34.6
CC
25
Cov
78%
get
10.1
string_unless_carp
6.0
init
4.0
CRAP 31.7
« Reporter.pm ↑ Summary Message/Convert/MimeEntity.pm »
1 # Copyrights 2001-2023 by [Mark Overmeer <markov@cpan.org>].
2 # For other contributors see ChangeLog.
3 # See the manual pages for details on the licensing terms.
4 # Pod stripped from pm file by OODoc 2.03.
5 # This code is part of distribution Mail-Message. Meta-POD processed with
6 # OODoc into POD and HTML manual-pages. See README.md
7 # Copyright Mark Overmeer. Licensed under the same terms as Perl itself.
8  
9 package Mail::Message::Head;
10 38 ▶use vars '$VERSION';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 38 $VERSION = '3.013';
12  
13 38 ▶use base 'Mail::Reporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 38 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 38 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 38 ▶use Mail::Message::Head::Complete;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 38 ▶use Mail::Message::Field::Fast;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 38 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 38 ▶use Scalar::Util 'weaken';
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24  
25 38 use overload qq("") => 'string_unless_carp'
26 38 ▶ , bool => 'isEmpty';
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 # To satisfy overload in static resolving.
29 0 ▶sub toString() { shift->load->toString }
Subroutine toString: not called CC=1 SCAR=6.9
Pod undocumented
30 0 ▶sub string() { shift->load->string }
Subroutine string: not called CC=1 SCAR=6.9
Pod undocumented
31  
32 sub string_unless_carp()
33 0 ▶{ my $self = shift;
Subroutine string_unless_carp: not called CC=2 SCAR=17.9
Pod undocumented
34 0 ▶ return $self->toString unless (caller)[0] eq 'Carp';
Branch: 1 branch
BranchTrueFalseTotal
unless (caller)[0] eq "Carp" 0 0 0
35  
36 0 (my $class = ref $self) =~ s/^Mail::Message/MM/;
37 0 "$class object";
38 }
39  
40 #------------------------------------------
41  
42  
43 sub new(@)
44 173 ▶{ my $class = shift;
Subroutine new: called CC=2 SCAR=7.1
Pod documented
45  
46 173 ▶ return Mail::Message::Head::Complete->new(@_)
Branch: 1 branch
BranchTrueFalseTotal
if $class eq __PACKAGE__ 0 173 173
47 if $class eq __PACKAGE__;
48  
49 173 $class->SUPER::new(@_);
50 }
51
52 sub init($)
53 173 ▶{ my ($self, $args) = @_;
Subroutine init: called CC=4 SCAR=14.0
Pod undocumented
54  
55 173 $self->SUPER::init($args);
56  
57 $self->{MMH_field_type} = $args->{field_type}
58 173 ▶ if $args->{field_type};
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"field_type"} 0 173 173
59  
60 $self->message($args->{message})
61 173 ▶ if defined $args->{message};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args->{"message"} 26 147 173
62  
63 173 $self->{MMH_fields} = {};
64 173 $self->{MMH_order} = [];
65 173 ▶ $self->{MMH_modified} = $args->{modified} || 0;
Condition50%1/2
$args->{'modified'} || 0
l!l
0173
MC/DC0%0/1
$args->{'modified'} || 0
$args->{'modified'}
Truth table50%1/2
A
A= $args->{'modified'}
Aresult
11
00
66 173 $self;
67 }
68  
69  
70 sub build(@)
71 3 ▶{ shift;
Subroutine build: called CC=1 SCAR=0.0
Pod documented
72 3 Mail::Message::Head::Complete->build(@_);
73 }
74  
75 #------------------------------------------
76  
77  
78 0 ▶sub isDelayed { 1 }
Subroutine isDelayed: not called CC=1 SCAR=6.9
Pod documented
79  
80  
81 sub modified(;$)
82 72 ▶{ my $self = shift;
Subroutine modified: called CC=2 SCAR=7.1
Pod documented
83 72 ▶ return $self->isModified unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 72 72
84 72 $self->{MMH_modified} = shift;
85 }
86  
87  
88 0 ▶sub isModified() { shift->{MMH_modified} }
Subroutine isModified: not called CC=1 SCAR=6.9
Pod documented
89  
90  
91 217 ▶sub isEmpty { scalar keys %{shift->{MMH_fields}} }
Subroutine isEmpty: called CC=1 SCAR=0.0
Pod documented
92  
93  
94 sub message(;$)
95 170 ▶{ my $self = shift;
Subroutine message: called CC=2 SCAR=7.0
Pod documented
96 170 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 170 0 170
97 170 { $self->{MMH_message} = shift;
98 170 weaken($self->{MMH_message});
99 }
100  
101 170 $self->{MMH_message};
102 }
103  
104  
105 218 ▶sub orderedFields() { grep defined $_, @{shift->{MMH_order}} }
Subroutine orderedFields: called CC=1 SCAR=0.0
Pod documented
106  
107  
108 19 ▶sub knownNames() { keys %{shift->{MMH_fields}} }
Subroutine knownNames: called CC=1 SCAR=0.0
Pod documented
109  
110 #------------------------------------------
111  
112  
113 sub get($;$)
114 960 ▶{ my $known = shift->{MMH_fields};
Subroutine get: called CC=10 SCAR=23.1
Pod documented
115 960 my $value = $known->{lc(shift)};
116 960 my $index = shift;
117  
118 960 ▶ if(defined $index)
Branch: 2 branches
BranchTrueFalseTotal
if (defined $index) { } 199 761 960
elsif (wantarray) { } 22 739 761
119 199 ▶ { return ! defined $value ? undef
Branch: 3 branches
BranchTrueFalseTotal
!defined($value) ? : 13 186 199
ref $value eq 'ARRAY' ? : 0 186 186
$index == 0 ? : 186 0 186
120 : ref $value eq 'ARRAY' ? $value->[$index]
121 : $index == 0 ? $value
122 : undef;
123 }
124 elsif(wantarray)
125 22 ▶ { return ! defined $value ? ()
Branch: 2 branches
BranchTrueFalseTotal
!defined($value) ? : 2 20 22
ref $value eq 'ARRAY' ? : 4 16 20
126 : ref $value eq 'ARRAY' ? @$value
127 : ($value);
128 }
129 else
130 739 ▶ { return ! defined $value ? undef
Branch: 2 branches
BranchTrueFalseTotal
!defined($value) ? : 514 225 739
ref $value eq 'ARRAY' ? : 2 223 225
131 : ref $value eq 'ARRAY' ? $value->[-1]
132 : $value;
133 }
134 }
135  
136 0 ▶sub get_all(@) { my @all = shift->get(@_) } # compatibility, force list
Subroutine get_all: not called CC=1 SCAR=6.9
Pod undocumented
137 0 ▶sub setField($$) {shift->add(@_)} # compatibility
Subroutine setField: not called CC=1 SCAR=6.9
Pod undocumented
138  
139  
140 sub study($;$)
141 2 ▶{ my $self = shift;
Subroutine study: called CC=3 SCAR=11.0
Pod documented
142 2 ▶ return map {$_->study} $self->get(@_)
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 1 1 2
143 if wantarray;
144  
145 1 my $got = $self->get(@_);
146 1 ▶ defined $got ? $got->study : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $got ? : 1 0 1
147 }
148  
149 #------------------------------------------
150  
151  
152  
153 sub isMultipart()
154 131 ▶{ my $type = shift->get('Content-Type', 0);
Subroutine isMultipart: called CC=2 SCAR=7.2
Pod documented
155 131 ▶ $type && scalar $type->body =~ m[^multipart/]i;
Branch: 1 branch
BranchTrueFalseTotal
$type and scalar $type->body =~ m[^multipart/]i 131 0 131
156 }
157  
158 #------------------------------
159  
160 sub read($)
161 26 ▶{ my ($self, $parser) = @_;
Subroutine read: called CC=3 SCAR=11.0
Pod documented
162  
163 26 my @fields = $parser->readHeader;
164 26 @$self{ qw/MMH_begin MMH_end/ } = (shift @fields, shift @fields);
165  
166 26 ▶ my $type = $self->{MMH_field_type} || 'Mail::Message::Field::Fast';
Condition50%1/2
$self->{'MMH_field_type'} || 'Mail::Message::Field::Fast'
l!l
026
MC/DC0%0/1
$self->{'MMH_field_type'} || 'Mail::Message::Field::Fast'
$self->{'MMH_field_type'}
Truth table50%1/2
A
A= $self->{'MMH_field_type'}
Aresult
11
00
167  
168 $self->addNoRealize($type->new( @$_ ))
169 26 for @fields;
170  
171 26 $self;
172 }
173  
174  
175 # Warning: fields are added in addResentGroup() as well!
176 sub addOrderedFields(@)
177 654 ▶{ my $order = shift->{MMH_order};
Subroutine addOrderedFields: called CC=2 SCAR=6.9
Pod documented
178 654 foreach (@_)
179 655 { push @$order, $_;
180 655 weaken( $order->[-1] );
181 }
182 654 @_;
183 }
184  
185  
186 0 ▶sub load($) {shift}
Subroutine load: not called CC=1 SCAR=6.9
Pod documented
187  
188  
189 sub fileLocation()
190 0 ▶{ my $self = shift;
Subroutine fileLocation: not called CC=1 SCAR=6.9
Pod documented
191 0 @$self{ qw/MMH_begin MMH_end/ };
192 }
193  
194  
195 sub moveLocation($)
196 0 ▶{ my ($self, $dist) = @_;
Subroutine moveLocation: not called CC=1 SCAR=6.9
Pod documented
197 0 $self->{MMH_begin} -= $dist;
198 0 $self->{MMH_end} -= $dist;
199 0 $self;
200 }
201  
202  
203 sub setNoRealize($)
204 0 ▶{ my ($self, $field) = @_;
Subroutine setNoRealize: not called CC=1 SCAR=6.9
Pod documented
205  
206 0 my $known = $self->{MMH_fields};
207 0 my $name = $field->name;
208  
209 0 $self->addOrderedFields($field);
210 0 $known->{$name} = $field;
211 0 $field;
212 }
213  
214  
215 sub addNoRealize($)
216 292 ▶{ my ($self, $field) = @_;
Subroutine addNoRealize: called CC=3 SCAR=11.0
Pod documented
217  
218 292 my $known = $self->{MMH_fields};
219 292 my $name = $field->name;
220  
221 292 $self->addOrderedFields($field);
222  
223 292 ▶ if(defined $known->{$name})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $known->{$name}) { } 4 288 292
224 4 ▶ { if(ref $known->{$name} eq 'ARRAY') { push @{$known->{$name}}, $field }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $known->{$name} eq 'ARRAY') { } 1 3 4
225 3 else { $known->{$name} = [ $known->{$name}, $field ] }
226 }
227 else
228 288 { $known->{$name} = $field;
229 }
230  
231 292 $field;
232 }
233  
234 #------------------------------------------
235  
236  
237 38 1;
« Reporter.pm ↑ Summary Message/Convert/MimeEntity.pm »