Message/Body.pm

filter: Statementstmt 82.3% 173 / 210 Branchbran 68.5% 85 / 124 Conditioncond 57.4% 58 / 101 MC/DCmcdc 37.7% 23 / 61 Subroutinesub 67.9% 36 / 53 Podpod 94.1% 32 / 34 totaltotal 69.8% 407 / 583 CC 101 SCAR 40.4
CC
101
Cov
73%
init
169.5
write
20.0
language
17.9
CRAP 56.6
« Box/Parser/Perl.pm ↑ Summary Message/Replace/MailInternet.pm »
1 # This code is part of Perl distribution Mail-Message version 4.05.
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::Body;{
13 37 our $VERSION = '4.05';
14 }
15  
16 37 ▶use parent 'Mail::Reporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 37 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 37 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 37 ▶use Log::Report 'mail-message', import => [ qw/__x error fault info panic/ ];
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 37 ▶use Scalar::Util qw/weaken refaddr blessed/;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 37 ▶use File::Basename qw/basename/;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 37 ▶use Mail::Message::Field ();
Subroutine BEGIN: called CC=1 SCAR=0.0
27 37 ▶use Mail::Message::Body::Lines ();
Subroutine BEGIN: called CC=1 SCAR=0.0
28 37 ▶use Mail::Message::Body::File ();
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 37 ▶use MIME::Types ();
Subroutine BEGIN: called CC=1 SCAR=0.0
31 37 my $mime_types = MIME::Types->new;
32 37 my $mime_plain = $mime_types->type('text/plain');
33  
34 #--------------------
35  
36 use overload
37 419 ▶ bool => sub {1}, # $body->print if $body
Subroutine BEGIN: called CC=1 SCAR=0.1
Subroutine __ANON__: called CC=1 SCAR=0.0
38 '""' => 'string_unless_carp',
39 '@{}' => 'lines',
40 6 ▶ '==' => sub {ref $_[1] && refaddr $_[0] == refaddr $_[1]},
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
ref $_[1] and builtin::refaddr($_[0]) == builtin::refaddr($_[1]) 6 0 6
41 37 ▶ '!=' => sub {ref $_[1] && refaddr $_[0] != refaddr $_[1]};
Subroutine __ANON__: called CC=2 SCAR=7.0
Branch: 1 branch
BranchTrueFalseTotal
ref $_[1] and builtin::refaddr($_[0]) != builtin::refaddr($_[1]) 53 0 53
42  
43 #--------------------
44  
45 37 my $body_count = 0; # to be able to compare bodies for equivalence.
46  
47 sub new(@)
48 327 ▶{ my $class = shift;
Subroutine new: called CC=3 SCAR=11.0
Pod documented
49 327 ▶ $class eq __PACKAGE__ or return $class->SUPER::new(@_);
Branch: 1 branch
BranchTrueFalseTotal
$class eq __PACKAGE__ or return $class->SUPER::new(@_) 19 308 327
50  
51 19 my %args = @_;
52 19 ▶ exists $args{file} ? Mail::Message::Body::File->new(@_) : Mail::Message::Body::Lines->new(@_);
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'file'} ? : 0 19 19
53 }
54  
55 # All body implementations shall implement all of the following!!
56 0 ▶sub _data_from_filename(@) { $_[0]->notImplemented }
Subroutine _data_from_filename: not called CC=1 SCAR=6.9
57 0 ▶sub _data_from_filehandle(@) { $_[0]->notImplemented }
Subroutine _data_from_filehandle: not called CC=1 SCAR=6.9
58 0 ▶sub _data_from_lines(@) { $_[0]->notImplemented }
Subroutine _data_from_lines: not called CC=1 SCAR=6.9
59  
60 sub init($)
61 308 ▶{ my ($self, $args) = @_;
Subroutine init: called CC=48 SCAR=51.3
Pod undocumented
62 308 $self->SUPER::init($args);
63  
64 308 ▶ $self->{MMB_modified} = $args->{modified} || 0;
Condition50%1/2
$args->{'modified'} || 0
l!l
0308
MC/DC0%0/1
$args->{'modified'} || 0
$args->{'modified'}
Truth table50%1/2
A
A= $args->{'modified'}
Aresult
11
00
65  
66 308 my $filename = $args->{filename};
67 308 my $mime = $args->{mime_type};
68  
69 308 ▶ if(defined(my $file = $args->{file}))
Branch: 3 branches
BranchTrueFalseTotal
if (defined(my $file = $args->{'file'})) { } 3 305 308
elsif (defined(my $data = $args->{'data'})) { } 155 150 305
elsif (not $self->isMultipart || $self->isNested) { } 89 61 150
70 {
71 3 ▶ if(!ref $file)
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $file) { } 0 3 3
elsif (ref $file eq 'GLOB' or builtin::blessed($file) and $file->isa('IO::Handle')) { } 3 0 3
72 0 ▶ { $self->_data_from_filename($file) or return;
Branch: 1 branch
BranchTrueFalseTotal
$self->_data_from_filename($file) or return 0 0 0
73 0 ▶ $filename ||= $file;
Condition0%0/3
$filename ||= $file
l!l&&r!l&&!r
000
MC/DC0%0/2
$filename ||= $file
$filename $file
Truth table0%0/3
A ||= B
A= $filenameB= $file
ABresult
1X1
011
000
74 0 ▶ $mime ||= $mime_types->mimeTypeOf($filename) || (-T $file ? 'text/plain' : 'application/octet-stream');
Branch: 1 branch
BranchTrueFalseTotal
-T $file ? : 0 0 0
Condition0%0/6
$mime ||= $mime_types->mimeTypeOf($filename) || (-T $file ? "text/plain" : "application/octet-stream")
l!l&&r!l&&!r
000
$mime_types->mimeTypeOf($filename) || (-T $file ? 'text/plain' : 'application/octet-stream')
l!l&&r!l&&!r
000
MC/DC0%0/3
$mime ||= $mime_types->mimeTypeOf($filename) || (-T $file ? "text/plain" : "application/octet-stream")
$mime $mime_types->mimeTypeOf($filename) (-T $file ? 'text/plain' : 'application/octet-stream')
Truth table0%0/4
A ||= B || C
A= $mimeB= $mime_types->mimeTypeOf($filename)C= (-T $file ? 'text/plain' : 'application/octet-stream')
ABCresult
1XX1
01X1
0011
0000
75 }
76 ▶ elsif(ref $file eq 'GLOB' || (blessed $file && $file->isa('IO::Handle')))
Condition33%2/6
ref $file eq "GLOB" or builtin::blessed($file) and $file->isa("IO::Handle")
l!l&&r!l&&!r
030
builtin::blessed($file) and $file->isa("IO::Handle")
!ll&&!rl&&r
003
MC/DC0%0/3
ref $file eq "GLOB" or builtin::blessed($file) and $file->isa("IO::Handle")
ref $file eq "GLOB" builtin::blessed($file) $file->isa("IO::Handle")
Truth table25%1/4
A or B and C
A= ref $file eq "GLOB"B= builtin::blessed($file)C= $file->isa("IO::Handle")
ABCresult
1XX1
0111
00X0
0100
77 3 ▶ { $self->_data_from_filehandle($file) or return;
Branch: 1 branch
BranchTrueFalseTotal
$self->_data_from_filehandle($file) or return 3 0 3
78 }
79 else
80 0 ▶ { error __x"message body: illegal datatype '{type}' for file option.", type => ref $file // $file;
Condition0%0/3
ref $file // $file
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $file // $file
ref $file $file
Truth table0%0/3
A // B
A= ref $fileB= $file
ABresult
1X1
011
000
81 }
82 }
83 elsif(defined(my $data = $args->{data}))
84 {
85 155 ▶ if(!ref $data)
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $data) { } 88 67 155
elsif (ref $data eq 'ARRAY') { } 67 0 67
86 88 { my @lines = split /^/, $data;
87 88 $self->_data_from_lines(\@lines)
88 }
89 elsif(ref $data eq 'ARRAY')
90 67 ▶ { $self->_data_from_lines($data) or return;
Branch: 1 branch
BranchTrueFalseTotal
$self->_data_from_lines($data) or return 67 0 67
91 }
92 else
93 0 ▶ { error __x"message body: illegal datatype '{type}' for data option.", type => ref $data // $data;
Condition0%0/3
ref $data // $data
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $data // $data
ref $data $data
Truth table0%0/3
A // B
A= ref $dataB= $data
ABresult
1X1
011
000
94 }
95 }
96 ▶ elsif(! $self->isMultipart && ! $self->isNested)
Condition100%3/3
$self->isMultipart || $self->isNested
l!l&&r!l&&!r
491289
MC/DC100%2/2
$self->isMultipart || $self->isNested
$self->isMultipart $self->isNested
Truth table100%3/3
A || B
A= $self->isMultipartB= $self->isNested
ABresult
1X1
011
000
97 { # Neither 'file' nor 'data', so empty body.
98 89 ▶ $self->_data_from_lines( [] ) or return;
Branch: 1 branch
BranchTrueFalseTotal
$self->_data_from_lines([]) or return 89 0 89
99 }
100  
101 # Set the content info
102  
103 308 my ($transfer, $disp, $descr, $cid, $lang) = @$args{ qw/transfer_encoding disposition description content_id language/ };
104  
105 308 ▶ if(defined $filename)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $filename) 0 308 308
106 0 ▶ { $disp //= Mail::Message::Field->new(
Branch: 1 branch
BranchTrueFalseTotal
-T $filename ? : 0 0 0
Condition0%0/3
$disp //= "Mail::Message::Field"->new("Content-Disposition", -T $filename ? "inline" : "attachment", "filename", basename($filename))
l!l&&r!l&&!r
000
MC/DC0%0/2
$disp //= "Mail::Message::Field"->new("Content-Disposition", -T $filename ? "inline" : "attachment", "filename", basename($filename))
$disp "Mail::Message::Field"->new("Content-Disposition", -T $filename ? "inline" : "attachment", "filename", basename($filename))
Truth table0%0/3
A //= B
A= $dispB= "Mail::Message::Field"->new("Content-Disposition", -T $filename ? "inline" : "attachment", "filename", basename($filename))
ABresult
1X1
011
000
107 'Content-Disposition' => (-T $filename ? 'inline' : 'attachment'),
108 filename => basename($filename)
109 );
110 0 ▶ $mime //= $mime_types->mimeTypeOf($filename);
Condition0%0/3
$mime //= $mime_types->mimeTypeOf($filename)
l!l&&r!l&&!r
000
MC/DC0%0/2
$mime //= $mime_types->mimeTypeOf($filename)
$mime $mime_types->mimeTypeOf($filename)
Truth table0%0/3
A //= B
A= $mimeB= $mime_types->mimeTypeOf($filename)
ABresult
1X1
011
000
111 }
112  
113 308 ▶ if(ref $mime && $mime->isa('MIME::Type'))
Branch: 1 branch
BranchTrueFalseTotal
if (ref $mime and $mime->isa("MIME::Type")) 0 308 308
Condition66%2/3
ref $mime and $mime->isa("MIME::Type")
!ll&&!rl&&r
243650
MC/DC0%0/2
ref $mime and $mime->isa("MIME::Type")
ref $mime $mime->isa("MIME::Type")
Truth table66%2/3
A and B
A= ref $mimeB= $mime->isa("MIME::Type")
ABresult
0X0
100
111
114 0 { $mime = $mime->type;
115 }
116  
117 308 ▶ if(defined(my $based = $args->{based_on}))
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $based = $args->{'based_on'})) { } 131 177 308
118 131 ▶ { $mime //= $based->type;
Condition66%2/3
$mime //= $based->type
l!l&&r!l&&!r
84470
MC/DC0%0/2
$mime //= $based->type
$mime $based->type
Truth table66%2/3
A //= B
A= $mimeB= $based->type
ABresult
1X1
011
000
119 131 ▶ $transfer //= $based->transferEncoding;
Condition66%2/3
$transfer //= $based->transferEncoding
l!l&&r!l&&!r
131180
MC/DC0%0/2
$transfer //= $based->transferEncoding
$transfer $based->transferEncoding
Truth table66%2/3
A //= B
A= $transferB= $based->transferEncoding
ABresult
1X1
011
000
120 131 ▶ $disp //= $based->disposition;
Condition33%1/3
$disp //= $based->disposition
l!l&&r!l&&!r
01310
MC/DC0%0/2
$disp //= $based->disposition
$disp $based->disposition
Truth table33%1/3
A //= B
A= $dispB= $based->disposition
ABresult
1X1
011
000
121 131 ▶ $descr //= $based->description;
Condition33%1/3
$descr //= $based->description
l!l&&r!l&&!r
01310
MC/DC0%0/2
$descr //= $based->description
$descr $based->description
Truth table33%1/3
A //= B
A= $descrB= $based->description
ABresult
1X1
011
000
122 131 ▶ $lang //= $based->language;
Condition33%1/3
$lang //= $based->language
l!l&&r!l&&!r
00131
MC/DC0%0/2
$lang //= $based->language
$lang $based->language
Truth table33%1/3
A //= B
A= $langB= $based->language
ABresult
1X1
011
000
123 131 ▶ $cid //= $based->contentId;
Condition33%1/3
$cid //= $based->contentId
l!l&&r!l&&!r
01310
MC/DC0%0/2
$cid //= $based->contentId
$cid $based->contentId
Truth table33%1/3
A //= B
A= $cidB= $based->contentId
ABresult
1X1
011
000
124  
125 131 ▶ $self->{MMB_checked} = exists $args->{checked} ? $args->{checked} : $based->checked;
Branch: 1 branch
BranchTrueFalseTotal
exists $args->{'checked'} ? : 46 85 131
126 }
127 else
128 177 { $transfer = $args->{transfer_encoding};
129 177 ▶ $self->{MMB_checked} = $args->{checked} || 0;
Condition100%2/2
$args->{'checked'} || 0
l!l
3174
MC/DC100%1/1
$args->{'checked'} || 0
$args->{'checked'}
Truth table100%2/2
A
A= $args->{'checked'}
Aresult
11
00
130 }
131  
132 308 ▶ $mime ||= 'text/plain';
Condition100%2/2
$mime ||= "text/plain"
l!l
21890
MC/DC100%1/1
$mime ||= "text/plain"
$mime
Truth table100%2/2
A
A= $mime
Aresult
11
00
133 308 $mime = $self->type($mime);
134  
135 308 ▶ my $default_charset = exists $args->{charset} ? $args->{charset} : 'PERL';
Branch: 1 branch
BranchTrueFalseTotal
exists $args->{'charset'} ? : 77 231 308
136 308 ▶ $mime->attribute(charset => $default_charset)
Branch: 1 branch
BranchTrueFalseTotal
if $default_charset and $mime =~ m[^text/]i and not $mime->attribute("charset") 97 211 308
Condition100%6/6
$default_charset and $mime =~ m[^text/]i and not $mime->attribute("charset")
!ll&&!rl&&r
1268597
$default_charset and $mime =~ m[^text/]i
!ll&&!rl&&r
7452182
MC/DC100%3/3
$default_charset and $mime =~ m[^text/]i and not $mime->attribute("charset")
$default_charset $mime =~ m[^text/]i not $mime->attribute("charset")
Truth table100%4/4
A and B and not(C)
A= $default_charsetB= $mime =~ m[^text/]iC= not $mime->attribute("charset")
ABCresult
0XX0
10X0
1100
1111
137 if $default_charset
138 && $mime =~ m!^text/!i
139 && !$mime->attribute('charset');
140  
141 308 ▶ $self->transferEncoding($transfer) if defined $transfer;
Branch: 1 branch
BranchTrueFalseTotal
if defined $transfer 143 165 308
142 308 ▶ $self->disposition($disp) if defined $disp;
Branch: 1 branch
BranchTrueFalseTotal
if defined $disp 131 177 308
143 308 ▶ $self->description($descr) if defined $descr;
Branch: 1 branch
BranchTrueFalseTotal
if defined $descr 131 177 308
144 308 ▶ $self->language($lang) if defined $lang;
Branch: 1 branch
BranchTrueFalseTotal
if defined $lang 0 308 308
145 308 ▶ $self->contentId($cid) if defined $cid;
Branch: 1 branch
BranchTrueFalseTotal
if defined $cid 131 177 308
146 308 $self->type($mime);
147  
148 # Set message where the body belongs to.
149  
150 $self->message($args->{message})
151 308 ▶ if defined $args->{message};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args->{"message"} 74 234 308
152  
153 308 $self->{MMB_seqnr} = $body_count++;
154 308 $self;
155 }
156  
157  
158  
159 0 ▶sub clone() { $_[0]->notImplemented }
Subroutine clone: not called CC=1 SCAR=6.9
Pod documented
160  
161 #--------------------
162  
163 sub decoded(@)
164 25 ▶{ my $self = shift;
Subroutine decoded: called CC=1 SCAR=0.0
Pod documented
165 25 $self->encode(charset => 'PERL', transfer_encoding => 'none', @_);
166 }
167  
168 #--------------------
169  
170 sub message(;$)
171 260 ▶{ my $self = shift;
Subroutine message: called CC=3 SCAR=11.0
Pod documented
172 260 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 249 11 260
173 249 ▶ { if($self->{MMB_message} = shift)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"MMB_message"} = shift()) 249 0 249
174 249 { weaken $self->{MMB_message};
175 }
176 }
177 260 $self->{MMB_message};
178 }
179  
180  
181 sub isDelayed() {0}
182  
183  
184 sub isMultipart() {0}
185  
186  
187 sub isNested() {0}
188  
189  
190 sub partNumberOf($)
191 0 ▶{ error __x"part number needs multi-part or nested.";
Subroutine partNumberOf: not called CC=1 SCAR=6.9
Pod documented
192 }
193  
194 #--------------------
195  
196 sub type(;$)
197 1231 ▶{ my $self = shift;
Subroutine type: called CC=5 SCAR=16.1
Pod documented
198 1231 ▶ return $self->{MMB_type} if !@_ && defined $self->{MMB_type};
Branch: 1 branch
BranchTrueFalseTotal
if not @_ and defined $self->{"MMB_type"} 512 719 1231
Condition66%2/3
not @_ and defined $self->{"MMB_type"}
!ll&&!rl&&r
7190512
MC/DC50%1/2
not @_ and defined $self->{"MMB_type"}
not @_ defined $self->{"MMB_type"}
Truth table66%2/3
not(A) and B
A= not @_B= defined $self->{"MMB_type"}
ABresult
0X0
100
111
199  
200 719 delete $self->{MMB_mime};
201 719 ▶ my $type = shift // 'text/plain';
Condition100%2/2
shift() // "text/plain"
l!l
70514
MC/DC100%1/1
shift() // "text/plain"
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
202  
203 719 ▶ $self->{MMB_type} = blessed $type ? $type->clone : Mail::Message::Field->new('Content-Type' => $type);
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($type) ? : 509 210 719
204 }
205  
206  
207 sub mimeType()
208 108 ▶{ my $self = shift;
Subroutine mimeType: called CC=5 SCAR=17.2
Pod documented
209 108 ▶ return $self->{MMB_mime} if exists $self->{MMB_mime};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"MMB_mime"} 39 69 108
210  
211 69 my $field = $self->{MMB_type};
212 69 ▶ my $body = defined $field ? $field->body : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $field ? : 69 0 69
213 69 ▶ $self->{MMB_mime} = length $body ? ($mime_types->type($body) || MIME::Type->new(type => $body)) : $mime_plain;
Branch: 1 branch
BranchTrueFalseTotal
length $body ? : 69 0 69
Condition33%1/3
$mime_types->type($body) or "MIME::Type"->new("type", $body)
l!l&&r!l&&!r
6900
MC/DC0%0/2
$mime_types->type($body) or "MIME::Type"->new("type", $body)
$mime_types->type($body) "MIME::Type"->new("type", $body)
Truth table33%1/3
A or B
A= $mime_types->type($body)B= "MIME::Type"->new("type", $body)
ABresult
1X1
011
000
214 }
215  
216  
217 62 ▶sub charset() { $_[0]->type->attribute('charset') }
Subroutine charset: called CC=1 SCAR=0.0
Pod documented
218  
219  
220 sub transferEncoding(;$)
221 633 ▶{ my $self = shift;
Subroutine transferEncoding: called CC=5 SCAR=16.1
Pod documented
222 633 ▶ return $self->{MMB_transfer} if !@_ && defined $self->{MMB_transfer};
Branch: 1 branch
BranchTrueFalseTotal
if not @_ and defined $self->{"MMB_transfer"} 296 337 633
Condition100%3/3
not @_ and defined $self->{"MMB_transfer"}
!ll&&!rl&&r
28453296
MC/DC100%2/2
not @_ and defined $self->{"MMB_transfer"}
not @_ defined $self->{"MMB_transfer"}
Truth table100%3/3
not(A) and B
A= not @_B= defined $self->{"MMB_transfer"}
ABresult
0X0
100
111
223  
224 337 ▶ my $set = shift // 'none';
Condition100%2/2
shift() // "none"
l!l
24691
MC/DC100%1/1
shift() // "none"
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
225 337 ▶ $self->{MMB_transfer} = blessed $set ? $set->clone : Mail::Message::Field->new('Content-Transfer-Encoding' => $set);
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($set) ? : 183 154 337
226 }
227  
228  
229 sub description(;$)
230 452 ▶{ my $self = shift;
Subroutine description: called CC=5 SCAR=16.1
Pod documented
231 452 ▶ return $self->{MMB_description} if !@_ && $self->{MMB_description};
Branch: 1 branch
BranchTrueFalseTotal
if not @_ and $self->{"MMB_description"} 161 291 452
Condition100%3/3
not @_ and $self->{"MMB_description"}
!ll&&!rl&&r
23457161
MC/DC100%2/2
not @_ and $self->{"MMB_description"}
not @_ $self->{"MMB_description"}
Truth table100%3/3
not(A) and B
A= not @_B= $self->{"MMB_description"}
ABresult
0X0
100
111
232  
233 291 ▶ my $disp = shift // 'none';
Condition100%2/2
shift() // "none"
l!l
135156
MC/DC100%1/1
shift() // "none"
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
234 291 ▶ $self->{MMB_description} = blessed $disp ? $disp->clone : Mail::Message::Field->new('Content-Description' => $disp);
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($disp) ? : 135 156 291
235 }
236  
237  
238 sub disposition(;$)
239 454 ▶{ my $self = shift;
Subroutine disposition: called CC=5 SCAR=16.1
Pod documented
240 454 ▶ return $self->{MMB_disposition} if !@_ && $self->{MMB_disposition};
Branch: 1 branch
BranchTrueFalseTotal
if not @_ and $self->{"MMB_disposition"} 163 291 454
Condition100%3/3
not @_ and $self->{"MMB_disposition"}
!ll&&!rl&&r
23457163
MC/DC100%2/2
not @_ and $self->{"MMB_disposition"}
not @_ $self->{"MMB_disposition"}
Truth table100%3/3
not(A) and B
A= not @_B= $self->{"MMB_disposition"}
ABresult
0X0
100
111
241  
242 291 ▶ my $disp = shift // 'none';
Condition100%2/2
shift() // "none"
l!l
146145
MC/DC100%1/1
shift() // "none"
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
243 291 ▶ $self->{MMB_disposition} = blessed $disp ? $disp->clone : Mail::Message::Field->new('Content-Disposition' => $disp);
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($disp) ? : 146 145 291
244 }
245  
246  
247 sub language(@)
248 321 ▶{ my $self = shift;
Subroutine language: called CC=9 SCAR=28.8
Pod documented
249 321 ▶ return $self->{MMB_lang} if !@_ && $self->{MMB_lang};
Branch: 1 branch
BranchTrueFalseTotal
if not @_ and $self->{"MMB_lang"} 0 321 321
Condition66%2/3
not @_ and $self->{"MMB_lang"}
!ll&&!rl&&r
1032180
MC/DC0%0/2
not @_ and $self->{"MMB_lang"}
not @_ $self->{"MMB_lang"}
Truth table66%2/3
not(A) and B
A= not @_B= $self->{"MMB_lang"}
ABresult
0X0
100
111
250  
251 my $langs
252 = @_ > 1 ? (join ', ', @_)
253 : blessed $_[0] ? $_[0]
254 0 ▶ : ref $_[0] eq 'ARRAY' ? (join ', ', @{$_[0]})
Branch: 3 branches
BranchTrueFalseTotal
@_ > 1 ? : 0 321 321
builtin::blessed($_[0]) ? : 0 321 321
ref $_[0] eq 'ARRAY' ? : 0 321 321
255 : $_[0];
256  
257 $self->{MMB_lang}
258 321 ▶ = ! defined $langs || ! length $langs ? undef
Branch: 2 branches
BranchTrueFalseTotal
!(defined $langs && length $langs) ? : 321 0 321
builtin::blessed($langs) ? : 0 0 0
Condition33%1/3
defined $langs && length $langs
!ll&&!rl&&r
32100
MC/DC0%0/2
defined $langs && length $langs
defined $langs length $langs
Truth table33%1/3
A && B
A= defined $langsB= length $langs
ABresult
0X0
100
111
259 : blessed $langs ? $langs->clone
260 : Mail::Message::Field->new('Content-Language' => $langs);
261 }
262  
263  
264 sub contentId(;$)
265 452 ▶{ my $self = shift;
Subroutine contentId: called CC=5 SCAR=16.1
Pod documented
266 452 ▶ return $self->{MMB_id} if !@_ && $self->{MMB_id};
Branch: 1 branch
BranchTrueFalseTotal
if not @_ and $self->{"MMB_id"} 161 291 452
Condition100%3/3
not @_ and $self->{"MMB_id"}
!ll&&!rl&&r
23457161
MC/DC100%2/2
not @_ and $self->{"MMB_id"}
not @_ $self->{"MMB_id"}
Truth table100%3/3
not(A) and B
A= not @_B= $self->{"MMB_id"}
ABresult
0X0
100
111
267  
268 291 ▶ my $cid = shift // 'none';
Condition100%2/2
shift() // "none"
l!l
131160
MC/DC100%1/1
shift() // "none"
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
269 291 ▶ $self->{MMB_id} = blessed $cid ? $cid->clone : Mail::Message::Field->new('Content-ID' => $cid);
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($cid) ? : 131 160 291
270 }
271  
272  
273 sub checked(;$)
274 113 ▶{ my $self = shift;
Subroutine checked: called CC=2 SCAR=6.9
Pod documented
275 113 ▶ @_ ? ($self->{MMB_checked} = shift) : $self->{MMB_checked};
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 1 112 113
276 }
277  
278  
279 0 ▶sub nrLines(@) { $_[0]->notImplemented }
Subroutine nrLines: not called CC=1 SCAR=6.9
Pod documented
280  
281  
282 0 ▶sub size(@) { $_[0]->notImplemented }
Subroutine size: not called CC=1 SCAR=6.9
Pod documented
283  
284 #--------------------
285  
286 0 ▶sub string() { $_[0]->notImplemented }
Subroutine string: not called CC=1 SCAR=6.9
Pod documented
287  
288 sub string_unless_carp()
289 27 ▶{ my $self = shift;
Subroutine string_unless_carp: called CC=2 SCAR=9.2
Pod undocumented
290 27 ▶ (caller)[0] eq 'Carp' or return $self->string;
Branch: 1 branch
BranchTrueFalseTotal
(caller)[0] eq "Carp" or return $self->string 0 27 27
291  
292 0 my $class = ref $self =~ s/^Mail::Message/MM/r;
293 0 "$class object";
294 }
295  
296  
297 0 ▶sub lines() { $_[0]->notImplemented }
Subroutine lines: not called CC=1 SCAR=6.9
Pod documented
298  
299  
300 0 ▶sub file(;$) { $_[0]->notImplemented }
Subroutine file: not called CC=1 SCAR=6.9
Pod documented
301  
302  
303 0 ▶sub print(;$) { $_[0]->notImplemented }
Subroutine print: not called CC=1 SCAR=6.9
Pod documented
304  
305  
306 0 ▶sub printEscapedFrom($) { $_[0]->notImplemented }
Subroutine printEscapedFrom: not called CC=1 SCAR=6.9
Pod documented
307  
308  
309 sub write(@)
310 0 ▶{ my ($self, %args) = @_;
Subroutine write: not called CC=4 SCAR=30.0
Pod documented
311 my $filename = $args{filename}
312 0 ▶ or error __x"no filename parameter for write() body.";
Branch: 1 branch
BranchTrueFalseTotal
my $filename = $args{"filename"} or &error(&__x("no filename parameter for write() body.")) 0 0 0
313  
314 #XXX encoding?
315 0 ▶ open my $out, '>', $filename
Branch: 1 branch
BranchTrueFalseTotal
open my $out, ">", $filename or &fault(&__x("cannot open {file} to write body", "file", $filename)) 0 0 0
316 or fault __x"cannot open {file} to write body", file => $filename;
317  
318 0 $self->print($out);
319 0 ▶ $out->close
Branch: 1 branch
BranchTrueFalseTotal
$out->close or &fault(&__x("error closing {file} after write body", "file", $filename)) 0 0 0
320 or fault __x"error closing {file} after write body", file => $filename;
321  
322 0 $self;
323 }
324  
325  
326 0 ▶sub endsOnNewline() { $_[0]->notImplemented }
Subroutine endsOnNewline: not called CC=1 SCAR=6.9
Pod documented
327  
328  
329 0 ▶sub stripTrailingNewline() { $_[0]->notImplemented }
Subroutine stripTrailingNewline: not called CC=1 SCAR=6.9
Pod documented
330  
331 #--------------------
332  
333 0 ▶sub read(@) { $_[0]->notImplemented }
Subroutine read: not called CC=1 SCAR=6.9
Pod documented
334  
335  
336 sub contentInfoTo($)
337 87 ▶{ my ($self, $head) = @_;
Subroutine contentInfoTo: called CC=3 SCAR=11.0
Pod documented
338 87 ▶ return unless defined $head;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $head 0 87 87
339  
340 87 my $lines = $self->nrLines;
341 87 my $size = $self->size;
342 87 ▶ $size += $lines if $Mail::Message::crlf_platform;
Branch: 1 branch
BranchTrueFalseTotal
if $Mail::Message::crlf_platform 0 87 87
343  
344 87 $head->set($self->type);
345 87 $head->set($self->transferEncoding);
346 87 $head->set($self->disposition);
347 87 $head->set($self->description);
348 87 $head->set($self->language);
349 87 $head->set($self->contentId);
350 87 $self;
351 }
352  
353  
354 sub contentInfoFrom($)
355 103 ▶{ my ($self, $head) = @_;
Subroutine contentInfoFrom: called CC=4 SCAR=13.9
Pod documented
356  
357 103 $self->type($head->get('Content-Type', 0));
358  
359 my ($te, $disp, $desc, $cid, $lang) = map {
360 103 ▶ my $x = $head->get("Content-$_") || '';
Condition100%2/2
$head->get("Content-$_") || ''
l!l
84431
MC/DC100%1/1
$head->get("Content-$_") || ''
$head->get("Content-$_")
Truth table100%2/2
A
A= $head->get("Content-$_")
Aresult
11
00
361 515 s/^\s+//,s/\s+$// for $x;
362 515 ▶ length $x ? $x : undef;
Branch: 1 branch
BranchTrueFalseTotal
length $x ? : 84 431 515
363 } qw/Transfer-Encoding Disposition Description ID Language/;
364  
365 103 $self->transferEncoding($te);
366 103 $self->disposition($disp);
367 103 $self->description($desc);
368 103 $self->language($lang);
369 103 $self->contentId($cid);
370  
371 103 delete $self->{MMB_mime};
372 103 $self;
373  
374 }
375  
376  
377 sub modified(;$)
378 13 ▶{ my $self = shift;
Subroutine modified: called CC=2 SCAR=7.1
Pod documented
379 13 ▶ @_ or return $self->isModified; # compat 2.036
Branch: 1 branch
BranchTrueFalseTotal
@_ or return $self->isModified 13 0 13
380 13 $self->{MMB_modified} = shift;
381 }
382  
383  
384 22 ▶sub isModified() { $_[0]->{MMB_modified} }
Subroutine isModified: called CC=1 SCAR=0.0
Pod documented
385  
386  
387 sub fileLocation(;@)
388 121 ▶{ my $self = shift;
Subroutine fileLocation: called CC=2 SCAR=6.9
Pod documented
389 121 ▶ @_ or return @$self{ qw/MMB_begin MMB_end/ };
Branch: 1 branch
BranchTrueFalseTotal
@_ or return @$self{"MMB_begin", "MMB_end"} 105 16 121
390 105 @$self{ qw/MMB_begin MMB_end/ } = @_;
391 }
392  
393  
394 sub moveLocation($)
395 0 ▶{ my ($self, $dist) = @_;
Subroutine moveLocation: not called CC=1 SCAR=6.9
Pod documented
396 0 $self->{MMB_begin} -= $dist;
397 0 $self->{MMB_end} -= $dist;
398 0 $self;
399 }
400  
401  
402 2 ▶sub load() { $_[0] }
Subroutine load: called CC=1 SCAR=0.0
Pod documented
403  
404 #--------------------
405  
406 37 my @in_encode = qw/check encode encoded eol isBinary isText unify dispositionFilename/;
407 37 my %in_module = map +($_ => 'encode'), @in_encode;
408  
409 sub AUTOLOAD(@)
410 16 ▶{ my $self = shift;
Subroutine AUTOLOAD: called CC=4 SCAR=13.9
411 16 our $AUTOLOAD;
412 16 my $call = $AUTOLOAD =~ s/.*\:\://gr;
413  
414 16 ▶ my $mod = $in_module{$call} || 'construct';
Condition100%2/2
$in_module{$call} || 'construct'
l!l
133
MC/DC100%1/1
$in_module{$call} || 'construct'
$in_module{$call}
Truth table100%2/2
A
A= $in_module{$call}
Aresult
11
00
415 16 ▶ if($mod eq 'encode') { require Mail::Message::Body::Encode }
Branch: 1 branch
BranchTrueFalseTotal
if ($mod eq 'encode') { } 13 3 16
416 3 else { require Mail::Message::Body::Construct }
417  
418 37 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
419 16 ▶ return $self->$call(@_) if $self->can($call); # now loaded
Branch: 1 branch
BranchTrueFalseTotal
if $self->can($call) 16 0 16
420  
421 # AUTOLOAD inheritance is a pain
422 0 panic "method $call() is not defined for a " . ref $self;
423 }
424  
425 #--------------------
426  
427 37 1;
« Box/Parser/Perl.pm ↑ Summary Message/Replace/MailInternet.pm »