File Coverage

blib/lib/Mail/Box/Message/Destructed.pm
Criterion Covered Total %
statement 29 40 72.5
branch 6 22 27.2
condition 2 6 33.3
subroutine 7 11 63.6
pod 7 7 100.0
total 51 86 59.3


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::Box::Message::Destructed;{
13             our $VERSION = '4.01';
14             }
15              
16 34     34   228 use parent 'Mail::Box::Message';
  34         68  
  34         336  
17              
18 34     34   2999 use strict;
  34         82  
  34         913  
19 34     34   157 use warnings;
  34         65  
  34         2149  
20              
21 34     34   201 use Log::Report 'mail-box', import => [ qw/__x error/ ];
  34         62  
  34         299  
22              
23             #--------------------
24              
25 0     0 1 0 sub new(@) { error __x"you cannot instantiate a destructed message." }
26              
27             sub isDummy() { 1 }
28              
29              
30             sub head(;$)
31 0     0 1 0 { my ($self, $head) = @_;
32 0 0       0 @_==1 and error __x"you cannot take the head of a destructed message.";
33 0 0       0 defined $head and error __x"you cannot set the head on a destructed message.";
34 0         0 undef;
35             }
36              
37              
38             sub body(;$)
39 0     0 1 0 { my ($self, $body) = @_;
40 0 0       0 @_==1 and error __x"you cannot take the body of a destructed message.";
41 0 0       0 defined $body and error __x"you cannot set the body on a destructed message.";
42 0         0 undef;
43             }
44              
45              
46             sub coerce($)
47 55     55 1 176 { my ($class, $message) = @_;
48              
49 55 50       295 $message->isa('Mail::Box::Message')
50             or error __x"you cannot coerce a {class} into destruction.", class => ref $message;
51              
52 55         245 $message->body(undef);
53 55         7718 $message->head(undef);
54 55         743 $message->modified(0);
55              
56 55         1078 bless $message, $class;
57             }
58              
59              
60             sub modified(;$)
61 1     1 1 3 { my $self = shift;
62              
63 1 0 33     5 ! @_ || ! $_[0]
64             or error __x"you cannot set the modified flag on a destructed message.";
65              
66 1         11 0;
67             }
68              
69             sub isModified() { 0 }
70              
71              
72             sub label($;@)
73 3     3 1 437 { my $self = shift;
74              
75 3 100       13 if(@_==1)
76 2         4 { my $label = shift;
77 2 50       16 return $self->SUPER::label('deleted') if $label eq 'deleted';
78              
79 0         0 error __x"destructed message has no labels except 'deleted', requested is {label}.", label => $label;
80             }
81              
82 1         4 my %flags = @_;
83             keys %flags==1 && exists $flags{deleted}
84 1 50 33     69 or error __x"destructed message has no labels except 'deleted', trying to set {labels}.", labels => [keys %flags];
85              
86             $flags{deleted}
87 1 50       5 or error __x"destructed message can not be undeleted.";
88              
89 1         8 1;
90             }
91              
92 0 0   0 1   sub labels() { wantarray ? ('deleted') : +{deleted => 1} }
93              
94             1;