File Coverage

blib/lib/Mail/Message/Body/Delayed.pm
Criterion Covered Total %
statement 48 50 96.0
branch 5 8 62.5
condition 3 6 50.0
subroutine 20 20 100.0
pod 9 11 81.8
total 85 95 89.4


line stmt bran cond sub pod time code
1             # This code is part of Perl distribution Mail-Box version 4.01.
2             # The POD got stripped from this file by OODoc version 3.05.
3             # For contributors see file ChangeLog.
4              
5             # This software is copyright (c) 2001-2025 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::Delayed;{
13             our $VERSION = '4.01';
14             }
15              
16 28     28   16592 use parent 'Mail::Reporter';
  28         61  
  28         204  
17              
18 28     28   2518 use strict;
  28         162  
  28         871  
19 28     28   603 use warnings;
  28         79  
  28         1923  
20              
21 28     28   202 use Log::Report 'mail-box', import => [ qw/__x error/ ];
  28         65  
  28         257  
22              
23             use Object::Realize::Later
24 28         250 becomes => 'Mail::Message::Body',
25             realize => 'load',
26             warn_realization => 0,
27 28     28   39018 believe_caller => 1;
  28         54704  
28              
29 28     28   135296 use Scalar::Util qw/weaken/;
  28         56  
  28         2951  
30              
31             #--------------------
32              
33             use overload
34             '""' => 'string_unless_carp',
35 4864     4864   77187 bool => sub {1},
36 28     28   205 '@{}' => sub { $_[0]->load->lines };
  28     2   78  
  28         387  
  2         1700  
37              
38             #--------------------
39              
40             sub init($)
41 1486     1486 0 936268 { my ($self, $args) = @_;
42 1486         4931 $self->SUPER::init($args);
43              
44 1486         8139 $self->{MMB_seqnr} = -1; # for overloaded body comparison
45             $self->{MMBD_message} = $args->{message}
46 1486 50       5547 or error __x"a message must be specified to a delayed body.";
47              
48 1486         3876 weaken($self->{MMBD_message});
49 1486         5032 $self;
50             }
51              
52             #--------------------
53              
54 1539     1539 1 23592 sub message() { $_[0]->{MMBD_message} }
55              
56             #--------------------
57              
58             sub modified(;$)
59 859 100 66 859 1 4982 { return 0 if @_==1 || !$_[1];
60 1         64 shift->forceRealize(shift);
61             }
62              
63              
64             sub isModified() { 0 }
65             sub isDelayed() { 1 }
66 1     1 1 6 sub isMultipart() { $_[0]->message->head->isMultipart }
67 135     135 1 46799 sub guessSize() { $_[0]->{MMBD_size} }
68              
69              
70 90   33 90 1 976 sub nrLines() { $_[0]->{MMBD_lines} // $_[0]->forceRealize->nrLines }
71              
72             sub string_unless_carp()
73 80     80 0 85993 { my $self = shift;
74 80 50       686 return $self->load->string if (caller)[0] ne 'Carp';
75              
76 0         0 my $class = ref $self =~ s/^Mail::Message/MM/gr;
77 0         0 "$class object";
78             }
79              
80             #--------------------
81              
82             sub read($$;$@)
83 749     749 1 55545 { my ($self, $parser, $head, $bodytype) = splice @_, 0, 4;
84 749         2395 $self->{MMBD_parser} = $parser;
85              
86 749         3976 @$self{ qw/MMBD_begin MMBD_end MMBD_size MMBD_lines/ } = $parser->bodyDelayed(@_);
87 749         140731 $self;
88             }
89              
90              
91             sub fileLocation(;@) {
92 346     346 1 3350 my $self = shift;
93 346 50       1758 @_ ? (@$self{ qw/MMBD_begin MMBD_end/ } = @_) : @$self{ qw/MMBD_begin MMBD_end/ };
94             }
95              
96              
97             sub moveLocation($)
98 134     134 1 782 { my ($self, $dist) = @_;
99 134         303 $self->{MMBD_begin} -= $dist;
100 134         248 $self->{MMBD_end} -= $dist;
101 134         256 $self;
102             }
103              
104              
105 176     176 1 13040 sub load() { $_[0] = $_[0]->message->loadBody }
106              
107             1;