Message/Body/String.pm

filter: Statementstmt 62.3% 38 / 61 Branchbran 42.8% 6 / 14 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 70.5% 12 / 17 Podpod 100% 9 / 9 totaltotal 62.2% 66 / 106 CC 9 SCAR 9.7
CC
9
Cov
58%
_data_from_filename
6.0
nrLines
5.7
_data_from_lines
3.1
CRAP 2.6
« Message/Body/Nested.pm ↑ Summary Box/Parser.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::String;{
13 8 our $VERSION = '4.05';
14 }
15  
16 8 ▶use parent 'Mail::Message::Body';
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 8 ▶use Log::Report 'mail-message', import => [ qw/__x fault/ ];
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 8 ▶use Mail::Box::FastScalar ();
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 #--------------------
26  
27 # The scalar is stored as reference to avoid a copy during creation of
28 # a string object.
29  
30 sub _data_from_filename(@)
31 0 ▶{ my ($self, $filename) = @_;
Subroutine _data_from_filename: not called CC=2 SCAR=17.9
32  
33 0 delete $self->{MMBS_nrlines};
34 0 ▶ open my $in, '<:raw', $filename
Branch: 1 branch
BranchTrueFalseTotal
open my $in, "<:raw", $filename or &fault(&__x("unable to read file {name} for message body scalar", "name", $filename)) 0 0 0
35 or fault __x"unable to read file {name} for message body scalar", name => $filename;
36  
37 0 my @lines = $in->getlines;
38 0 $in->close;
39  
40 0 $self->{MMBS_nrlines} = @lines;
41 0 $self->{MMBS_scalar} = join '', @lines;
42 0 $self;
43 }
44  
45 sub _data_from_filehandle(@)
46 1 ▶{ my ($self, $fh) = @_;
Subroutine _data_from_filehandle: called CC=2 SCAR=7.8
47 1 ▶ if(ref $fh eq 'Mail::Box::FastScalar')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $fh eq 'Mail::Box::FastScalar') { } 0 1 1
48 0 { my $lines = $fh->getlines;
49 0 $self->{MMBS_nrlines} = @$lines;
50 0 $self->{MMBS_scalar} = join '', @$lines;
51 }
52 else
53 1 { my @lines = $fh->getlines;
54 1 $self->{MMBS_nrlines} = @lines;
55 1 $self->{MMBS_scalar} = join '', @lines;
56 }
57 1 $self;
58 }
59  
60 sub _data_from_lines(@)
61 1 ▶{ my ($self, $lines) = @_;
Subroutine _data_from_lines: called CC=3 SCAR=11.4
62 1 ▶ $self->{MMBS_nrlines} = @$lines unless @$lines==1;
Branch: 1 branch
BranchTrueFalseTotal
unless @$lines == 1 1 0 1
63 1 ▶ $self->{MMBS_scalar} = @$lines==1 ? shift @$lines : join('', @$lines);
Branch: 1 branch
BranchTrueFalseTotal
@$lines == 1 ? : 0 1 1
64 1 $self;
65 }
66  
67 sub clone()
68 0 ▶{ my $self = shift;
Subroutine clone: not called CC=1 SCAR=6.9
Pod documented
69 0 (ref $self)->new(data => $self->string, based_on => $self);
70 }
71  
72 sub nrLines()
73 2 ▶{ my $self = shift;
Subroutine nrLines: called CC=3 SCAR=17.3
Pod documented
74 2 ▶ return $self->{MMBS_nrlines} if defined $self->{MMBS_nrlines};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"MMBS_nrlines"} 2 0 2
75  
76 0 my $lines = $self->{MMBS_scalar} =~ tr/\n/\n/;
77 0 ▶ $lines++ if $self->{MMBS_scalar} !~ m/\n\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"MMBS_scalar"} =~ /\n\z/ 0 0 0
78 0 $self->{MMBS_nrlines} = $lines;
79 }
80  
81 2 ▶sub size() { length $_[0]->{MMBS_scalar} }
Subroutine size: called CC=1 SCAR=0.0
Pod documented
82 3 ▶sub string() { $_[0]->{MMBS_scalar} }
Subroutine string: called CC=1 SCAR=0.0
Pod documented
83  
84 sub lines()
85 3 ▶{ my @lines = split /^/, shift->{MMBS_scalar};
Subroutine lines: called CC=2 SCAR=6.9
Pod documented
86 3 ▶ wantarray ? @lines : \@lines;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 2 1 3
87 }
88  
89 0 ▶sub file() { Mail::Box::FastScalar->new(\shift->{MMBS_scalar}) }
Subroutine file: not called CC=1 SCAR=6.9
Pod documented
90  
91 sub print(;$)
92 2 ▶{ my $self = shift;
Subroutine print: called CC=2 SCAR=7.4
Pod documented
93 2 ▶ my $fh = shift || select;
Condition33%1/3
shift() || select()
l!l&&r!l&&!r
200
MC/DC0%0/2
shift() || select()
shift() select()
Truth table33%1/3
A || B
A= shift()B= select()
ABresult
1X1
011
000
94 2 $fh->print($self->{MMBS_scalar});
95 2 $self;
96 }
97  
98 sub read($$;$@)
99 0 ▶{ my ($self, $parser, $head, $bodytype) = splice @_, 0, 4;
Subroutine read: not called CC=1 SCAR=6.9
Pod documented
100 0 delete $self->{MMBS_nrlines};
101  
102 0 (my $begin, my $end, $self->{MMBS_scalar}) = $parser->bodyAsString(@_);
103 0 $self->fileLocation($begin, $end);
104  
105 0 $self;
106 }
107  
108 0 ▶sub endsOnNewline() { $_[0]->{MMBS_scalar} =~ m/\A\z|\n\z/ }
Subroutine endsOnNewline: not called CC=1 SCAR=6.9
Pod documented
109  
110 8 1;
« Message/Body/Nested.pm ↑ Summary Box/Parser.pm »