Message/Body/Construct.pm

filter: Statementstmt 89.3% 59 / 66 Branchbran 65.3% 34 / 52 Conditioncond 16.6% 1 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 90.0% 9 / 10 Podpod 100% 4 / 4 totaltotal 75.3% 107 / 142 CC 31 SCAR 28.7
CC
31
Cov
76%
attach
56.0
stripSignature
15.1
concatenate
7.3
CRAP 17.6
« Message/Head/Partial.pm ↑ Summary Box/Parser/Lines.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 5 our $VERSION = '4.05';
14 }
15  
16 # Mail::Message::Body::Construct adds functionality to Mail::Message::Body
17  
18 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 5 ▶use Log::Report 'mail-message', import => [ qw/__x error/ ];
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 5 ▶use Scalar::Util qw/blessed/;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 5 ▶use Mail::Message::Body::String ();
Subroutine BEGIN: called CC=1 SCAR=0.0
26 5 ▶use Mail::Message::Body::Lines ();
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 #--------------------
29  
30 sub foreachLine($)
31 4 ▶{ my ($self, $code) = @_;
Subroutine foreachLine: called CC=5 SCAR=16.8
Pod documented
32 4 my $changes = 0;
33 4 my @result;
34  
35 4 foreach ($self->lines)
36 8 { my $becomes = $code->();
37 8 ▶ if(defined $becomes)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $becomes) { } 8 0 8
38 8 { push @result, $becomes;
39 8 ▶ $changes++ if $becomes ne $_;
Branch: 1 branch
BranchTrueFalseTotal
if $becomes ne $_ 8 0 8
40 }
41 0 else { $changes++ }
42 }
43  
44 4 ▶ $changes ? (ref $self)->new(based_on => $self, data => \@result) : $self;
Branch: 1 branch
BranchTrueFalseTotal
$changes ? : 4 0 4
45 }
46  
47  
48 sub concatenate(@)
49 9 ▶{ my $self = shift;
Subroutine concatenate: called CC=7 SCAR=19.9
Pod documented
50 9 ▶ return $self if @_==1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 0 9 9
51  
52 9 my @unified;
53 9 foreach (grep defined, @_)
54 21 ▶ { push @unified,
Branch: 4 branches
BranchTrueFalseTotal
!ref($_) ? : 4 17 21
ref $_ eq 'ARRAY' ? : 1 16 17
$_->isa('Mail::Message') ? : 0 16 16
$_->isa('Mail::Message::Body') ? : 16 0 16
55 ! ref $_ ? $_
56 : ref $_ eq 'ARRAY' ? @$_
57 : $_->isa('Mail::Message') ? $_->body->decoded
58 : $_->isa('Mail::Message::Body') ? $_->decoded
59 : error(__x"cannot concatenate element {which}", which => $_);
60 }
61  
62 9 (ref $self)->new(
63 based_on => $self,
64 mime_type => 'text/plain',
65 data => join('', @unified),
66 );
67 }
68  
69  
70 sub attach(@)
71 0 ▶{ my $self = shift;
Subroutine attach: not called CC=7 SCAR=40.3
Pod documented
72  
73 0 my @parts;
74 0 ▶ push @parts, shift while @_ && blessed $_[0];
Branch: 1 branch
BranchTrueFalseTotal
@_ and builtin::blessed($_[0]) and do { push @parts, shift() } 0 0 0
Condition0%0/3
@_ and builtin::blessed($_[0])
!ll&&!rl&&r
000
MC/DC0%0/2
@_ and builtin::blessed($_[0])
@_ builtin::blessed($_[0])
Truth table0%0/3
A and B
A= @_B= builtin::blessed($_[0])
ABresult
0X0
100
111
75 0 ▶ @parts or return $self;
Branch: 1 branch
BranchTrueFalseTotal
@parts or return $self 0 0 0
76  
77 0 ▶ unshift @parts, $self->isNested ? $self->nested : $self->isMultipart ? $self->parts : $self;
Branch: 2 branches
BranchTrueFalseTotal
$self->isNested ? : 0 0 0
$self->isMultipart ? : 0 0 0
78  
79 0 ▶ @parts==1 ? $parts[0] : Mail::Message::Body::Multipart->new(parts => \@parts, @_);
Branch: 1 branch
BranchTrueFalseTotal
@parts == 1 ? : 0 0 0
80 }
81  
82  
83 # tests in t/51stripsig.t
84  
85 sub stripSignature($@)
86 14 ▶{ my ($self, %args) = @_;
Subroutine stripSignature: called CC=15 SCAR=27.1
Pod documented
87  
88 14 ▶ return $self if $self->mimeType->isBinary;
Branch: 1 branch
BranchTrueFalseTotal
if $self->mimeType->isBinary 0 14 14
89  
90 14 my $p = $args{pattern};
91 14 ▶ my $pattern = ! defined $p ? qr/^--\s?$/
Branch: 2 branches
BranchTrueFalseTotal
!defined($p) ? : 10 4 14
!ref($p) ? : 2 2 4
92 : ! ref $p ? qr/^\Q$p/
93 : $p;
94  
95 14 my $lines = $self->lines; # no copy!
96 my $stop = defined $args{max_lines} ? @$lines - $args{max_lines}
97 14 ▶ : exists $args{max_lines} ? 0
Branch: 2 branches
BranchTrueFalseTotal
defined $args{'max_lines'} ? : 3 11 14
exists $args{'max_lines'} ? : 4 7 11
98 : @$lines-10;
99  
100 14 ▶ $stop = 0 if $stop < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $stop < 0 8 6 14
101 14 my ($sigstart, $found);
102  
103 14 ▶ if(ref $pattern eq 'CODE')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $pattern eq 'CODE') { } 1 13 14
104 1 ▶ { for($sigstart = $#$lines; $sigstart >= $stop; $sigstart--)
Branch: 1 branch
BranchTrueFalseTotal
if ($sigstart >= $stop) 4 0 4
105 4 ▶ { $pattern->($lines->[$sigstart]) or next;
Branch: 1 branch
BranchTrueFalseTotal
&$pattern($lines->[$sigstart]) or next 1 3 4
106 1 $found = 1;
107 1 last;
108 }
109 }
110 else
111 13 ▶ { for($sigstart = $#$lines; $sigstart >= $stop; $sigstart--)
Branch: 1 branch
BranchTrueFalseTotal
if ($sigstart >= $stop) 76 4 80
112 76 ▶ { $lines->[$sigstart] =~ $pattern or next;
Branch: 1 branch
BranchTrueFalseTotal
$lines->[$sigstart] =~ /$pattern/ or next 9 67 76
113 9 $found = 1;
114 9 last;
115 }
116 }
117  
118 14 ▶ $found or return $self;
Branch: 1 branch
BranchTrueFalseTotal
$found or return $self 10 4 14
119  
120 10 ▶ my $bodytype = $args{result_type} || ref $self;
Condition33%1/3
$args{'result_type'} || ref $self
l!l&&r!l&&!r
0100
MC/DC0%0/2
$args{'result_type'} || ref $self
$args{'result_type'} ref $self
Truth table33%1/3
A || B
A= $args{'result_type'}B= ref $self
ABresult
1X1
011
000
121 10 my $stripped = $bodytype->new(based_on => $self, data => [ @$lines[0..$sigstart-1] ]);
122  
123 10 ▶ wantarray or return $stripped;
Branch: 1 branch
BranchTrueFalseTotal
wantarray or return $stripped 6 4 10
124  
125 6 my $sig = $bodytype->new(based_on => $self, data => [ @$lines[$sigstart..$#$lines] ]);
126 6 ($stripped, $sig);
127 }
128  
129 5 1;
« Message/Head/Partial.pm ↑ Summary Box/Parser/Lines.pm »