Message/Body/Construct.pm

filter: Statementstmt 88.0% 59 / 67 Branchbran 66.6% 36 / 54 Conditioncond 16.6% 1 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 90.0% 9 / 10 Podpod 100% 4 / 4 totaltotal 75.1% 109 / 145 SCAR 38.5
CC
32
Cov
76%
attach
56.0
stripSignature
15.1
concatenate
8.3
CRAP 46.9
« Message/Field/AuthResults.pm ↑ Summary Message/Field/Attribute.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::Body;
10 5 ▶use vars '$VERSION';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 $VERSION = '3.013';
12  
13 # Mail::Message::Body::Construct adds functionality to Mail::Message::Body
14  
15 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 5 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 5 ▶use Mail::Message::Body::String;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 5 ▶use Mail::Message::Body::Lines;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22  
23 sub foreachLine($)
24 4 ▶{ my ($self, $code) = @_;
Subroutine foreachLine: called CC=5 SCAR=16.7
Pod documented
25 4 my $changes = 0;
26 4 my @result;
27  
28 4 foreach ($self->lines)
29 8 { my $becomes = $code->();
30 8 ▶ if(defined $becomes)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $becomes) { } 8 0 8
31 8 { push @result, $becomes;
32 8 ▶ $changes++ if $becomes ne $_;
Branch: 1 branch
BranchTrueFalseTotal
if $becomes ne $_ 8 0 8
33 }
34 0 else {$changes++}
35 }
36
37 $changes
38 4 ▶ or return $self;
Branch: 1 branch
BranchTrueFalseTotal
$changes or return $self 0 4 4
39  
40 4 ref($self)->new
41 ( based_on => $self
42 , data => \@result
43 );
44 }
45  
46 #------------------------------------------
47  
48  
49 sub concatenate(@)
50 9 ▶{ my $self = shift;
Subroutine concatenate: called CC=8 SCAR=21.1
Pod documented
51  
52 9 ▶ return $self
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 0 9 9
53 if @_==1;
54  
55 9 my @unified;
56 9 foreach (@_)
57 39 ▶ { next unless defined $_;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_ 18 21 39
58 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
59 , !ref $_ ? $_
60 : ref $_ eq 'ARRAY' ? @$_
61 : $_->isa('Mail::Message') ? $_->body->decoded
62 : $_->isa('Mail::Message::Body') ? $_->decoded
63 : carp "Cannot concatenate element ".$_;
64 }
65  
66 9 ref($self)->new
67 ( based_on => $self
68 , mime_type => 'text/plain'
69 , data => join('', @unified)
70 );
71 }
72  
73 #------------------------------------------
74  
75  
76 sub attach(@)
77 0 ▶{ my $self = shift;
Subroutine attach: not called CC=7 SCAR=40.3
Pod documented
78  
79 0 my @parts;
80 0 ▶ push @parts, shift while @_ && ref $_[0];
Branch: 1 branch
BranchTrueFalseTotal
@_ and ref $_[0] and do { push @parts, shift() } 0 0 0
Condition0%0/3
@_ and ref $_[0]
!ll&&!rl&&r
000
MC/DC0%0/2
@_ and ref $_[0]
@_ ref $_[0]
Truth table0%0/3
A and B
A= @_B= ref $_[0]
ABresult
0X0
100
111
81  
82 0 ▶ return $self unless @parts;
Branch: 1 branch
BranchTrueFalseTotal
unless @parts 0 0 0
83 0 ▶ unshift @parts,
Branch: 2 branches
BranchTrueFalseTotal
$self->isNested ? : 0 0 0
$self->isMultipart ? : 0 0 0
84 ( $self->isNested ? $self->nested
85 : $self->isMultipart ? $self->parts
86 : $self
87 );
88  
89 0 ▶ return $parts[0] if @parts==1;
Branch: 1 branch
BranchTrueFalseTotal
if @parts == 1 0 0 0
90 0 Mail::Message::Body::Multipart->new(parts => \@parts, @_);
91 }
92  
93 #------------------------------------------
94  
95  
96 # tests in t/51stripsig.t
97  
98 sub stripSignature($@)
99 14 ▶{ my ($self, %args) = @_;
Subroutine stripSignature: called CC=15 SCAR=27.2
Pod documented
100  
101 14 ▶ return $self if $self->mimeType->isBinary;
Branch: 1 branch
BranchTrueFalseTotal
if $self->mimeType->isBinary 0 14 14
102  
103 my $pattern = !defined $args{pattern} ? qr/^--\s?$/
104 : !ref $args{pattern} ? qr/^\Q${args{pattern}}/
105 14 ▶ : $args{pattern};
Branch: 2 branches
BranchTrueFalseTotal
!defined($args{'pattern'}) ? : 10 4 14
!ref($args{'pattern'}) ? : 2 2 4
106
107 14 my $lines = $self->lines; # no copy!
108 my $stop = defined $args{max_lines}? @$lines - $args{max_lines}
109 14 ▶ : exists $args{max_lines} ? 0
Branch: 2 branches
BranchTrueFalseTotal
defined $args{'max_lines'} ? : 3 11 14
exists $args{'max_lines'} ? : 4 7 11
110 : @$lines-10;
111  
112 14 ▶ $stop = 0 if $stop < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $stop < 0 8 6 14
113 14 my ($sigstart, $found);
114
115 14 ▶ if(ref $pattern eq 'CODE')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $pattern eq 'CODE') { } 1 13 14
116 1 ▶ { for($sigstart = $#$lines; $sigstart >= $stop; $sigstart--)
Branch: 1 branch
BranchTrueFalseTotal
if ($sigstart >= $stop) 4 0 4
117 4 ▶ { next unless $pattern->($lines->[$sigstart]);
Branch: 1 branch
BranchTrueFalseTotal
unless &$pattern($lines->[$sigstart]) 3 1 4
118 1 $found = 1;
119 1 last;
120 }
121 }
122 else
123 13 ▶ { for($sigstart = $#$lines; $sigstart >= $stop; $sigstart--)
Branch: 1 branch
BranchTrueFalseTotal
if ($sigstart >= $stop) 76 4 80
124 76 ▶ { next unless $lines->[$sigstart] =~ $pattern;
Branch: 1 branch
BranchTrueFalseTotal
unless $lines->[$sigstart] =~ /$pattern/ 67 9 76
125 9 $found = 1;
126 9 last;
127 }
128 }
129
130 14 ▶ return $self unless $found;
Branch: 1 branch
BranchTrueFalseTotal
unless $found 4 10 14
131
132 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
133  
134 10 my $stripped = $bodytype->new
135 ( based_on => $self
136 , data => [ @$lines[0..$sigstart-1] ]
137 );
138  
139 10 ▶ return $stripped unless wantarray;
Branch: 1 branch
BranchTrueFalseTotal
unless wantarray 4 6 10
140  
141 6 my $sig = $bodytype->new
142 ( based_on => $self
143 , data => [ @$lines[$sigstart..$#$lines] ]
144 );
145
146 6 ($stripped, $sig);
147 }
148  
149 #------------------------------------------
150  
151 5 1;
« Message/Field/AuthResults.pm ↑ Summary Message/Field/Attribute.pm »