Message/Body/Lines.pm

filter: Statementstmt 91.6% 55 / 60 Branchbran 64.2% 9 / 14 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 94.4% 17 / 18 Podpod 100% 9 / 9 totaltotal 85.8% 91 / 106 CC 10 SCAR 7.2
CC
10
Cov
84%
_data_from_filename
6.0
size
3.0
print
2.1
CRAP 2.1
« Message/Construct.pm ↑ Summary Message/Convert/EmailSimple.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::Lines;{
13 37 our $VERSION = '4.05';
14 }
15  
16 37 ▶use parent 'Mail::Message::Body';
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 fault/ ];
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 37 ▶use Mail::Box::Parser ();
Subroutine BEGIN: called CC=1 SCAR=0.0
24 37 ▶use IO::Lines ();
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 #--------------------
27  
28 sub _data_from_filename(@)
29 0 ▶{ my ($self, $filename) = @_;
Subroutine _data_from_filename: not called CC=2 SCAR=17.9
30  
31 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 lines", "name", $filename)) 0 0 0
32 or fault __x"unable to read file {name} for message body lines", name => $filename;
33  
34 0 $self->{MMBL_array} = [ $in->getlines ];
35 0 $in->close;
36 0 $self;
37 }
38  
39 sub _data_from_filehandle(@)
40 1 ▶{ my ($self, $fh) = @_;
Subroutine _data_from_filehandle: called CC=2 SCAR=7.1
41 1 ▶ $self->{MMBL_array} = ref $fh eq 'Mail::Box::FastScalar' ? $fh->getlines : [ $fh->getlines ];
Branch: 1 branch
BranchTrueFalseTotal
ref $fh eq 'Mail::Box::FastScalar' ? : 0 1 1
42 1 $self;
43 }
44  
45 sub _data_from_lines(@)
46 242 ▶{ my ($self, $lines) = @_;
Subroutine _data_from_lines: called CC=2 SCAR=6.9
47  
48 242 ▶ $lines = [ split /^/, $lines->[0] ] # body passed in one string.
Branch: 1 branch
BranchTrueFalseTotal
if @$lines == 1 51 191 242
49 if @$lines==1;
50  
51 242 $self->{MMBL_array} = $lines;
52 242 $self;
53 }
54  
55 sub clone()
56 13 ▶{ my $self = shift;
Subroutine clone: called CC=1 SCAR=0.0
Pod documented
57 13 (ref $self)->new(data => [ $self->lines ], based_on => $self);
58 }
59  
60 139 ▶sub nrLines() { scalar @{ $_[0]->{MMBL_array}} }
Subroutine nrLines: called CC=1 SCAR=0.0
Pod documented
61  
62 # Optimized to be computed only once.
63  
64 sub size()
65 121 ▶{ my $self = shift;
Subroutine size: called CC=3 SCAR=11.0
Pod documented
66 121 ▶ return $self->{MMBL_size} if exists $self->{MMBL_size};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"MMBL_size"} 60 61 121
67  
68 61 my $size = 0;
69 61 $size += length $_ for @{$self->{MMBL_array}};
70 61 $self->{MMBL_size} = $size;
71 }
72  
73 153 ▶sub string() { join '', @{$_[0]->{MMBL_array}} }
Subroutine string: called CC=1 SCAR=0.0
Pod documented
74 96 ▶sub lines() { wantarray ? @{$_[0]->{MMBL_array}} : $_[0]->{MMBL_array} }
Subroutine lines: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 62 34 96
75 3 ▶sub file() { IO::Lines->new($_[0]->{MMBL_array}) }
Subroutine file: called CC=1 SCAR=0.0
Pod documented
76  
77 sub print(;$)
78 35 ▶{ my $self = shift;
Subroutine print: called CC=2 SCAR=7.4
Pod documented
79 35 ▶ (shift || select)->print(@{$self->{MMBL_array}});
Condition33%1/3
shift() || select()
l!l&&r!l&&!r
3500
MC/DC0%0/2
shift() || select()
shift() select()
Truth table33%1/3
A || B
A= shift()B= select()
ABresult
1X1
011
000
80 35 $self;
81 }
82  
83 sub endsOnNewline()
84 40 ▶{ my $last = $_[0]->{MMBL_array}[-1];
Subroutine endsOnNewline: called CC=2 SCAR=7.2
Pod documented
85 40 ▶ !defined $last || $last =~ /[\r\n]$/;
Branch: 1 branch
BranchTrueFalseTotal
not defined $last or $last =~ /[\r\n]$/ 0 40 40
86 }
87  
88 sub read($$;$@)
89 89 ▶{ my ($self, $parser, $head, $bodytype) = splice @_, 0, 4;
Subroutine read: called CC=2 SCAR=7.0
Pod documented
90 89 my ($begin, $end, $lines) = $parser->bodyAsList(@_);
91 89 ▶ $lines or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$lines or return undef 89 0 89
92  
93 89 $self->fileLocation($begin, $end);
94 89 $self->{MMBL_array} = $lines;
95 89 $self;
96 }
97  
98 37 1;
« Message/Construct.pm ↑ Summary Message/Convert/EmailSimple.pm »