File Coverage

blib/lib/Mail/Message/Body/Lines.pm
Criterion Covered Total %
statement 52 57 91.2
branch 9 14 64.2
condition 1 3 33.3
subroutine 17 18 94.4
pod 9 9 100.0
total 88 101 87.1


line stmt bran cond sub pod time code
1             # This code is part of Perl distribution Mail-Message version 4.04.
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             our $VERSION = '4.04';
14             }
15              
16 37     37   8740 use parent 'Mail::Message::Body';
  37         81  
  37         347  
17              
18 37     37   3546 use strict;
  37         88  
  37         1316  
19 37     37   216 use warnings;
  37         81  
  37         3139  
20              
21 37     37   333 use Log::Report 'mail-message', import => [ qw/__x fault/ ];
  37         76  
  37         417  
22              
23 37     37   13909 use Mail::Box::Parser ();
  37         130  
  37         1090  
24 37     37   22294 use IO::Lines ();
  37         231880  
  37         31993  
25              
26             #--------------------
27              
28             sub _data_from_filename(@)
29 0     0   0 { my ($self, $filename) = @_;
30              
31 0 0       0 open my $in, '<:raw', $filename
32             or fault __x"unable to read file {name} for message body lines", name => $filename;
33              
34 0         0 $self->{MMBL_array} = [ $in->getlines ];
35 0         0 $in->close;
36 0         0 $self;
37             }
38              
39             sub _data_from_filehandle(@)
40 1     1   3 { my ($self, $fh) = @_;
41 1 50       10 $self->{MMBL_array} = ref $fh eq 'Mail::Box::FastScalar' ? $fh->getlines : [ $fh->getlines ];
42 1         404 $self;
43             }
44              
45             sub _data_from_lines(@)
46 242     242   599 { my ($self, $lines) = @_;
47              
48 242 100       1033 $lines = [ split /^/, $lines->[0] ] # body passed in one string.
49             if @$lines==1;
50              
51 242         737 $self->{MMBL_array} = $lines;
52 242         921 $self;
53             }
54              
55             sub clone()
56 13     13 1 28 { my $self = shift;
57 13         43 (ref $self)->new(data => [ $self->lines ], based_on => $self);
58             }
59              
60 139     139 1 18014 sub nrLines() { scalar @{ $_[0]->{MMBL_array}} }
  139         676  
61              
62             # Optimized to be computed only once.
63              
64             sub size()
65 121     121 1 237 { my $self = shift;
66 121 100       514 return $self->{MMBL_size} if exists $self->{MMBL_size};
67              
68 61         114 my $size = 0;
69 61         102 $size += length $_ for @{$self->{MMBL_array}};
  61         288  
70 61         208 $self->{MMBL_size} = $size;
71             }
72              
73 153     153 1 3723 sub string() { join '', @{$_[0]->{MMBL_array}} }
  153         1164  
74 96 100   96 1 9313 sub lines() { wantarray ? @{$_[0]->{MMBL_array}} : $_[0]->{MMBL_array} }
  62         426  
75 3     3 1 60 sub file() { IO::Lines->new($_[0]->{MMBL_array}) }
76              
77             sub print(;$)
78 35     35 1 126 { my $self = shift;
79 35   33     162 (shift || select)->print(@{$self->{MMBL_array}});
  35         228  
80 35         557 $self;
81             }
82              
83             sub endsOnNewline()
84 39     39 1 122 { my $last = $_[0]->{MMBL_array}[-1];
85 39 50       355 !defined $last || $last =~ /[\r\n]$/;
86             }
87              
88             sub read($$;$@)
89 89     89 1 352 { my ($self, $parser, $head, $bodytype) = splice @_, 0, 4;
90 89         357 my ($begin, $end, $lines) = $parser->bodyAsList(@_);
91 89 50       2130 $lines or return undef;
92              
93 89         415 $self->fileLocation($begin, $end);
94 89         230 $self->{MMBL_array} = $lines;
95 89         570 $self;
96             }
97              
98             1;