Message/Part.pm

filter: Statementstmt 82.0% 55 / 67 Branchbran 54.5% 12 / 22 Conditioncond 44.4% 4 / 9 MC/DCmcdc 16.6% 1 / 6 Subroutinesub 80.0% 12 / 15 Podpod 88.8% 8 / 9 totaltotal 71.8% 92 / 128 SCAR 29.8
CC
15
Cov
72%
toplevel
12.0
init
4.1
coerce
4.0
CRAP 19.7
« Message/Body/Nested.pm ↑ Summary Message/Construct/Text.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::Part;
10 34 ▶use vars '$VERSION';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 34 $VERSION = '3.013';
12  
13 34 ▶use base 'Mail::Message';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 34 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 34 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 34 ▶use Scalar::Util 'weaken';
Subroutine BEGIN: called CC=1 SCAR=0.0
19 34 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21  
22 sub init($)
23 63 ▶{ my ($self, $args) = @_;
Subroutine init: called CC=4 SCAR=14.0
Pod undocumented
24 63 ▶ $args->{head} ||= Mail::Message::Head::Complete->new;
Condition66%2/3
$args->{"head"} ||= "Mail::Message::Head::Complete"->new
l!l&&r!l&&!r
29034
MC/DC50%1/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
25  
26 63 $self->SUPER::init($args);
27  
28 confess "No container specified for part.\n"
29 63 ▶ unless exists $args->{container};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $args->{"container"} 0 63 63
30  
31 weaken($self->{MMP_container})
32 63 ▶ if $self->{MMP_container} = $args->{container};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"MMP_container"} = $args->{"container"} 31 32 63
33  
34 63 $self;
35 }
36  
37  
38 sub coerce($@)
39 68 ▶{ my ($class, $thing, $container) = (shift, shift, shift);
Subroutine coerce: called CC=4 SCAR=13.9
Pod documented
40 68 ▶ if($thing->isa($class))
Branch: 1 branch
BranchTrueFalseTotal
if ($thing->isa($class)) 37 31 68
41 37 { $thing->container($container);
42 37 return $thing;
43 }
44  
45 31 ▶ return $class->buildFromBody($thing, $container, @_)
Branch: 1 branch
BranchTrueFalseTotal
if $thing->isa("Mail::Message::Body") 18 13 31
46 if $thing->isa('Mail::Message::Body');
47  
48 # Although cloning is a Bad Thing(tm), we must avoid modifying
49 # header fields of messages which reside in a folder.
50 13 ▶ my $message = $thing->isa('Mail::Box::Message') ? $thing->clone : $thing;
Branch: 1 branch
BranchTrueFalseTotal
$thing->isa('Mail::Box::Message') ? : 0 13 13
51  
52 13 my $part = $class->SUPER::coerce($message);
53 13 $part->container($container);
54 13 $part;
55 }
56  
57  
58 sub buildFromBody($$;@)
59 18 ▶{ my ($class, $body, $container) = (shift, shift, shift);
Subroutine buildFromBody: called CC=3 SCAR=13.1
Pod documented
60 18 my @log = $body->logSettings;
61  
62 18 my $head = Mail::Message::Head::Complete->new(@log);
63 18 ▶ while(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 18 18
64 0 ▶ { if(ref $_[0]) {$head->add(shift)}
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0]) { } 0 0 0
65 0 else {$head->add(shift, shift)}
66 }
67  
68 18 my $part = $class->new
69 ( head => $head
70 , container => $container
71 , @log
72 );
73  
74 18 $part->body($body);
75 18 $part;
76 }
77  
78 sub container(;$)
79 89 ▶{ my $self = shift;
Subroutine container: called CC=2 SCAR=6.9
Pod documented
80 89 ▶ return $self->{MMP_container} unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 13 76 89
81  
82 76 $self->{MMP_container} = shift;
83 76 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 confess 'no container';
Branch: 1 branch
BranchTrueFalseTotal
my $body = $self->container or confess("no container") 0 11 11
97 11 $body->partNumberOf($self);
98 }
99  
100 sub readFromParser($;$)
101 14 ▶{ my ($self, $parser, $bodytype) = @_;
Subroutine readFromParser: called CC=3 SCAR=12.0
Pod documented
102  
103 my $head = $self->readHead($parser)
104 || Mail::Message::Head::Complete->new
105 ( message => $self
106 , field_type => $self->{MM_field_type}
107 14 ▶ , $self->logSettings
Condition33%1/3
$self->readHead($parser) || 'Mail::Message::Head::Complete'->new('message', $self, 'field_type', $self->{'MM_field_type'}, $self->logSettings)
l!l&&r!l&&!r
1400
MC/DC0%0/2
$self->readHead($parser) || 'Mail::Message::Head::Complete'->new('message', $self, 'field_type', $self->{'MM_field_type'}, $self->logSettings)
$self->readHead($parser) 'Mail::Message::Head::Complete'->new('message', $self, 'field_type', $self->{'MM_field_type'}, $self->logSettings)
Truth table33%1/3
A || B
A= $self->readHead($parser)B= 'Mail::Message::Head::Complete'->new('message', $self, 'field_type', $self->{'MM_field_type'}, $self->logSettings)
ABresult
1X1
011
000
108 );
109  
110 14 ▶ 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
1400
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
111 || Mail::Message::Body::Lines->new(data => []);
112  
113 14 $self->head($head);
114 14 $self->storeBody($body->contentInfoFrom($head));
115 14 $self;
116 }
117  
118 #-----------------
119  
120 sub printEscapedFrom($)
121 0 ▶{ my ($self, $out) = @_;
Subroutine printEscapedFrom: not called CC=1 SCAR=6.9
Pod documented
122 0 $self->head->print($out);
123 0 $self->body->printEscapedFrom($out);
124 }
125  
126  
127 sub destruct()
128 0 ▶{ my $self = shift;
Subroutine destruct: not called CC=1 SCAR=6.9
Pod documented
129 0 $self->log(ERROR =>'You cannot destruct message parts, only whole messages');
130 0 undef;
131 }
132  
133 34 1;
« Message/Body/Nested.pm ↑ Summary Message/Construct/Text.pm »