Message/Part.pm

filter: Statementstmt 82.5% 52 / 63 Branchbran 54.5% 12 / 22 Conditioncond 44.4% 4 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 78.5% 11 / 14 Podpod 88.8% 8 / 9 totaltotal 70.7% 87 / 123 CC 15 SCAR 13.4
CC
15
Cov
72%
toplevel
12.0
init
4.1
coerce
4.0
CRAP 3.8
« Message/Field/Unstructured.pm ↑ Summary Message/Head.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::Part;{
13 37 our $VERSION = '4.05';
14 }
15  
16 37 ▶use parent 'Mail::Message';
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 panic/ ];
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 37 ▶use Scalar::Util qw/weaken/;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 #--------------------
26  
27 sub init($)
28 75 ▶{ my ($self, $args) = @_;
Subroutine init: called CC=4 SCAR=14.0
Pod undocumented
29 75 ▶ $args->{head} ||= Mail::Message::Head::Complete->new;
Condition66%2/3
$args->{"head"} ||= "Mail::Message::Head::Complete"->new
l!l&&r!l&&!r
26490
MC/DC0%0/2
$args->{"head"} ||= "Mail::Message::Head::Complete"->new
$args->{"head"} "Mail::Message::Head::Complete"->new
Truth table66%2/3
A ||= B
A= $args->{"head"}B= "Mail::Message::Head::Complete"->new
ABresult
1X1
011
000
30  
31 75 $self->SUPER::init($args);
32  
33 exists $args->{container}
34 75 ▶ or error __x"no container specified for part.";
Branch: 1 branch
BranchTrueFalseTotal
exists $args->{"container"} or &error(&__x("no container specified for part.")) 75 0 75
35  
36 weaken($self->{MMP_container})
37 75 ▶ if $self->{MMP_container} = $args->{container};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"MMP_container"} = $args->{"container"} 46 29 75
38  
39 75 $self;
40 }
41  
42  
43 sub coerce($@)
44 65 ▶{ my ($class, $thing, $container) = (shift, shift, shift);
Subroutine coerce: called CC=4 SCAR=13.9
Pod documented
45 65 ▶ if($thing->isa($class))
Branch: 1 branch
BranchTrueFalseTotal
if ($thing->isa($class)) 34 31 65
46 34 { $thing->container($container);
47 34 return $thing;
48 }
49  
50 31 ▶ return $class->buildFromBody($thing, $container, @_)
Branch: 1 branch
BranchTrueFalseTotal
if $thing->isa("Mail::Message::Body") 18 13 31
51 if $thing->isa('Mail::Message::Body');
52  
53 # Although cloning is a Bad Thing(tm), we must avoid modifying
54 # header fields of messages which reside in a folder.
55 13 ▶ my $message = $thing->isa('Mail::Box::Message') ? $thing->clone : $thing;
Branch: 1 branch
BranchTrueFalseTotal
$thing->isa('Mail::Box::Message') ? : 0 13 13
56  
57 13 my $part = $class->SUPER::coerce($message);
58 13 $part->container($container);
59 13 $part;
60 }
61  
62  
63 sub buildFromBody($$;@)
64 18 ▶{ my ($class, $body, $container) = (shift, shift, shift);
Subroutine buildFromBody: called CC=3 SCAR=13.6
Pod documented
65  
66 18 my $head = Mail::Message::Head::Complete->new;
67 18 ▶ while(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 18 18
68 0 ▶ { if(ref $_[0]) {$head->add(shift)}
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0]) { } 0 0 0
69 0 else {$head->add(shift, shift)}
70 }
71  
72 18 my $part = $class->new(head => $head, container => $container);
73  
74 18 $part->body($body);
75 18 $part;
76 }
77  
78 sub container(;$)
79 83 ▶{ my $self = shift;
Subroutine container: called CC=2 SCAR=6.9
Pod documented
80 83 ▶ @_ or return $self->{MMP_container};
Branch: 1 branch
BranchTrueFalseTotal
@_ or return $self->{"MMP_container"} 70 13 83
81  
82 70 $self->{MMP_container} = shift;
83 70 weaken($self->{MMP_container});
84 }
85  
86 sub toplevel()
87 0 ▶{ my $body = shift->container or return;
Subroutine toplevel: not called CC=3 SCAR=24.8
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
my $body = (shift())->container or return 0 0 0
88 0 ▶ my $msg = $body->message or return;
Branch: 1 branch
BranchTrueFalseTotal
my $msg = $body->message or return 0 0 0
89 0 $msg->toplevel;
90 }
91  
92 sub isPart() { 1 }
93  
94 sub partNumber()
95 11 ▶{ my $self = shift;
Subroutine partNumber: called CC=2 SCAR=7.1
Pod documented
96 11 ▶ my $body = $self->container or panic 'no container';
Branch: 1 branch
BranchTrueFalseTotal
my $body = $self->container or &panic("no container") 11 0 11
97 11 $body->partNumberOf($self);
98 }
99  
100 sub readFromParser($;$)
101 29 ▶{ my ($self, $parser, $bodytype) = @_;
Subroutine readFromParser: called CC=3 SCAR=12.0
Pod documented
102  
103 my $head = $self->readHead($parser) //
104 29 ▶ Mail::Message::Head::Complete->new(message => $self, field_type => $self->{MM_field_type});
Condition33%1/3
$self->readHead($parser) // "Mail::Message::Head::Complete"->new("message", $self, "field_type", $self->{"MM_field_type"})
l!l&&r!l&&!r
2900
MC/DC0%0/2
$self->readHead($parser) // "Mail::Message::Head::Complete"->new("message", $self, "field_type", $self->{"MM_field_type"})
$self->readHead($parser) "Mail::Message::Head::Complete"->new("message", $self, "field_type", $self->{"MM_field_type"})
Truth table33%1/3
A // B
A= $self->readHead($parser)B= "Mail::Message::Head::Complete"->new("message", $self, "field_type", $self->{"MM_field_type"})
ABresult
1X1
011
000
105  
106 29 ▶ my $body = $self->readBody($parser, $head, $bodytype) //
Condition33%1/3
$self->readBody($parser, $head, $bodytype) // "Mail::Message::Body::Lines"->new("data", [])
l!l&&r!l&&!r
2900
MC/DC0%0/2
$self->readBody($parser, $head, $bodytype) // "Mail::Message::Body::Lines"->new("data", [])
$self->readBody($parser, $head, $bodytype) "Mail::Message::Body::Lines"->new("data", [])
Truth table33%1/3
A // B
A= $self->readBody($parser, $head, $bodytype)B= "Mail::Message::Body::Lines"->new("data", [])
ABresult
1X1
011
000
107 Mail::Message::Body::Lines->new(data => []);
108  
109 29 $self->head($head);
110 29 $self->storeBody($body->contentInfoFrom($head));
111 29 $self;
112 }
113  
114 #--------------------
115  
116 sub printEscapedFrom($)
117 0 ▶{ my ($self, $out) = @_;
Subroutine printEscapedFrom: not called CC=1 SCAR=6.9
Pod documented
118 0 $self->head->print($out);
119 0 $self->body->printEscapedFrom($out);
120 }
121  
122 #--------------------
123  
124 sub destruct()
125 0 ▶{ my $self = shift;
Subroutine destruct: not called CC=1 SCAR=6.9
Pod documented
126 0 error __x"you cannot destruct message parts, only whole messages.";
127 }
128  
129 37 1;
« Message/Field/Unstructured.pm ↑ Summary Message/Head.pm »