| 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::Lines; | ||||||||||||||||||||
| 10 | 34 | ▶ | use vars '$VERSION'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 34 | $VERSION = '3.013'; | |||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 34 | ▶ | use base 'Mail::Message::Body'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | 34 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 16 | 34 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | 34 | ▶ | use Mail::Box::Parser; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 19 | 34 | ▶ | use IO::Lines; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 34 | ▶ | use Carp; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | sub _data_from_filename(@) | ||||||||||||||||||||
| 25 | 0 | ▶ | { my ($self, $filename) = @_; | ||||||||||||||||||
|
Subroutine
_data_from_filename: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | 0 | local *IN; | |||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | 0 | ▶ | unless(open IN, '<', $filename) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 30 | 0 | { $self->log(ERROR => | |||||||||||||||||||
| 31 | "Unable to read file $filename for message body lines: $!"); | ||||||||||||||||||||
| 32 | 0 | return; | |||||||||||||||||||
| 33 | } | ||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | 0 | $self->{MMBL_array} = [ <IN> ]; | |||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | 0 | close IN; | |||||||||||||||||||
| 38 | 0 | $self; | |||||||||||||||||||
| 39 | } | ||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | sub _data_from_filehandle(@) | ||||||||||||||||||||
| 42 | 1 | ▶ | { my ($self, $fh) = @_; | ||||||||||||||||||
|
Subroutine
_data_from_filehandle: called CC=2 SCAR=7.1
| |||||||||||||||||||||
| 43 | $self->{MMBL_array} = | ||||||||||||||||||||
| 44 | 1 | ▶ | ref $fh eq 'Mail::Box::FastScalar' ? $fh->getlines : [ $fh->getlines ]; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 45 | 1 | $self | |||||||||||||||||||
| 46 | } | ||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | sub _data_from_glob(@) | ||||||||||||||||||||
| 49 | 0 | ▶ | { my ($self, $fh) = @_; | ||||||||||||||||||
|
Subroutine
_data_from_glob: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 50 | 0 | $self->{MMBL_array} = [ <$fh> ]; | |||||||||||||||||||
| 51 | 0 | $self; | |||||||||||||||||||
| 52 | } | ||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | sub _data_from_lines(@) | ||||||||||||||||||||
| 55 | 184 | ▶ | { my ($self, $lines) = @_; | ||||||||||||||||||
|
Subroutine
_data_from_lines: called CC=2 SCAR=6.9
| |||||||||||||||||||||
| 56 | 184 | ▶ | $lines = [ split /^/, $lines->[0] ] # body passed in one string. | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 57 | if @$lines==1; | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | 184 | $self->{MMBL_array} = $lines; | |||||||||||||||||||
| 60 | 184 | $self; | |||||||||||||||||||
| 61 | } | ||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | #------------------------------------------ | ||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | sub clone() | ||||||||||||||||||||
| 66 | 13 | ▶ | { my $self = shift; | ||||||||||||||||||
|
Subroutine
clone: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 67 | 13 | ref($self)->new(data => [ $self->lines ], based_on => $self); | |||||||||||||||||||
| 68 | } | ||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | #------------------------------------------ | ||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | 133 | ▶ | sub nrLines() { scalar @{shift->{MMBL_array}} } | ||||||||||||||||||
|
Subroutine
nrLines: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | #------------------------------------------ | ||||||||||||||||||||
| 75 | # Optimized to be computed only once. | ||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | sub size() | ||||||||||||||||||||
| 78 | 127 | ▶ | { my $self = shift; | ||||||||||||||||||
|
Subroutine
size: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||
| 79 | 127 | ▶ | return $self->{MMBL_size} if exists $self->{MMBL_size}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | 61 | my $size = 0; | |||||||||||||||||||
| 82 | 61 | $size += length $_ foreach @{$self->{MMBL_array}}; | |||||||||||||||||||
| 83 | 61 | $self->{MMBL_size} = $size; | |||||||||||||||||||
| 84 | } | ||||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | #------------------------------------------ | ||||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | 128 | ▶ | sub string() { join '', @{shift->{MMBL_array}} } | ||||||||||||||||||
|
Subroutine
string: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | #------------------------------------------ | ||||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | 92 | ▶ | sub lines() { wantarray ? @{shift->{MMBL_array}} : shift->{MMBL_array} } | ||||||||||||||||||
|
Subroutine
lines: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | #------------------------------------------ | ||||||||||||||||||||
| 95 | |||||||||||||||||||||
| 96 | 3 | ▶ | sub file() { IO::Lines->new(shift->{MMBL_array}) } | ||||||||||||||||||
|
Subroutine
file: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | #------------------------------------------ | ||||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | sub print(;$) | ||||||||||||||||||||
| 101 | 30 | ▶ | { my $self = shift; | ||||||||||||||||||
|
Subroutine
print: called CC=3 SCAR=12.6
Pod
documented
| |||||||||||||||||||||
| 102 | 30 | ▶ | my $fh = shift || select; | ||||||||||||||||||
|
Condition33%1/3
shift() || select()
MC/DC0%0/2
shift() || select()
shift()
select()
Truth table33%1/3
A || B
A= shift()B= select()
| |||||||||||||||||||||
| 103 | 30 | ▶ | if(ref $fh eq 'GLOB') { print $fh @{$self->{MMBL_array}} } | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 104 | 30 | else { $fh->print(@{$self->{MMBL_array}}) } | |||||||||||||||||||
| 105 | 30 | $self; | |||||||||||||||||||
| 106 | } | ||||||||||||||||||||
| 107 | |||||||||||||||||||||
| 108 | #------------------------------------------ | ||||||||||||||||||||
| 109 | |||||||||||||||||||||
| 110 | sub read($$;$@) | ||||||||||||||||||||
| 111 | 32 | ▶ | { my ($self, $parser, $head, $bodytype) = splice @_, 0, 4; | ||||||||||||||||||
|
Subroutine
read: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||
| 112 | 32 | my ($begin, $end, $lines) = $parser->bodyAsList(@_); | |||||||||||||||||||
| 113 | 32 | ▶ | $lines or return undef; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 114 | |||||||||||||||||||||
| 115 | 32 | $self->fileLocation($begin, $end); | |||||||||||||||||||
| 116 | 32 | $self->{MMBL_array} = $lines; | |||||||||||||||||||
| 117 | 32 | $self; | |||||||||||||||||||
| 118 | } | ||||||||||||||||||||
| 119 | |||||||||||||||||||||
| 120 | #------------------------------------------ | ||||||||||||||||||||
| 121 | |||||||||||||||||||||
| 122 | sub endsOnNewline() | ||||||||||||||||||||
| 123 | 38 | ▶ | { my $last = shift->{MMBL_array}[-1]; | ||||||||||||||||||
|
Subroutine
endsOnNewline: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||||
| 124 | 38 | ▶ | !defined $last || $last =~ m/\n$/; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 125 | } | ||||||||||||||||||||
| 126 | |||||||||||||||||||||
| 127 | #------------------------------------------ | ||||||||||||||||||||
| 128 | |||||||||||||||||||||
| 129 | 34 | 1; | |||||||||||||||||||