Box/Thread/Node.pm

filter: Statementstmt 82.5% 128 / 155 Branchbran 72.0% 49 / 68 Conditioncond 54.1% 26 / 48 MC/DCmcdc 32.1% 9 / 28 Subroutinesub 80.5% 29 / 36 Podpod 86.3% 19 / 22 totaltotal 72.8% 260 / 357 CC 58 SCAR 18.6
CC
58
Cov
75%
__ANON__
20.0
threadToString
13.0
follows
12.1
CRAP 6.4
« Box/Thread/Manager.pm ↑ Summary Box/Dir/Message.pm »
1 # This code is part of Perl distribution Mail-Box version 4.02.
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::Box::Thread::Node;{
13 4 our $VERSION = '4.02';
14 }
15  
16 4 ▶use parent 'Mail::Reporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 4 ▶use Log::Report 'mail-box', import => [ qw/__x error/ ];
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 4 ▶use List::Util qw/first/;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 #--------------------
26  
27 sub new(@)
28 150 ▶{ my ($class, %args) = @_;
Subroutine new: called CC=1 SCAR=0.0
Pod documented
29 150 (bless {}, $class)->init(\%args);
30 }
31  
32 sub init($)
33 150 ▶{ my ($self, $args) = @_;
Subroutine init: called CC=4 SCAR=14.5
Pod undocumented
34  
35 150 ▶ if(my $message = $args->{message})
Branch: 2 branches
BranchTrueFalseTotal
if (my $message = $args->{'message'}) { } 135 15 150
elsif (my $msgid = $args->{'msgid'}) { } 15 0 15
36 135 { push @{$self->{MBTN_messages}}, $message;
37 135 ▶ $self->{MBTN_msgid} = $args->{msgid} || $message->messageId;
Condition33%1/3
$args->{'msgid'} || $message->messageId
l!l&&r!l&&!r
13500
MC/DC0%0/2
$args->{'msgid'} || $message->messageId
$args->{'msgid'} $message->messageId
Truth table33%1/3
A || B
A= $args->{'msgid'}B= $message->messageId
ABresult
1X1
011
000
38 }
39 elsif(my $msgid = $args->{msgid})
40 15 { $self->{MBTN_msgid} = $msgid;
41 }
42 else
43 0 { error __x"thread node needs a message object or msgid.";
44 }
45  
46 150 $self->{MBTN_dummy_type} = $args->{dummy_type};
47 150 $self;
48 }
49  
50 #--------------------
51  
52 sub isDummy()
53 202 ▶{ my $self = shift;
Subroutine isDummy: called CC=3 SCAR=11.0
Pod documented
54 202 my $msgs = $self->{MBTN_messages};
55 202 ▶ ! defined $msgs || ! @$msgs || $msgs->[0]->isDummy;
Branch: 1 branch
BranchTrueFalseTotal
not defined $msgs && @$msgs or $msgs->[0]->isDummy 15 187 202
Condition66%2/3
defined $msgs && @$msgs
!ll&&!rl&&r
150187
MC/DC50%1/2
defined $msgs && @$msgs
defined $msgs @$msgs
Truth table66%2/3
A && B
A= defined $msgsB= @$msgs
ABresult
0X0
100
111
56 }
57  
58  
59 659 ▶sub messageId() { $_[0]->{MBTN_msgid} }
Subroutine messageId: called CC=1 SCAR=0.0
Pod documented
60  
61 #--------------------
62  
63 sub message()
64 504 ▶{ my $self = shift;
Subroutine message: called CC=6 SCAR=18.1
Pod documented
65 504 ▶ my $messages = $self->{MBTN_messages} ||= [];
Condition100%2/2
$self->{"MBTN_messages"} ||= []
l!l
49410
MC/DC100%1/1
$self->{"MBTN_messages"} ||= []
$self->{"MBTN_messages"}
Truth table100%2/2
A
A= $self->{"MBTN_messages"}
Aresult
11
00
66  
67 504 ▶ unless(@$messages)
Branch: 1 branch
BranchTrueFalseTotal
unless (@$messages) 10 494 504
68 10 ▶ { return () if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 0 10 10
69  
70 10 my $dummy = $self->{MBTN_dummy_type}->new(messageId => $self->{MBTN_msgid});
71 10 push @$messages, $dummy;
72 10 return $dummy;
73 }
74  
75 494 ▶ return @$messages if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 143 351 494
76 351 ▶ (first { ! $_->isDeleted } @$messages) // $messages->[0];
Subroutine __ANON__: called CC=1 SCAR=0.6
Condition33%1/3
&first(sub { not $_->isDeleted; } , @$messages) // $messages->[0]
l!l&&r!l&&!r
35100
MC/DC0%0/2
&first(sub { not $_->isDeleted; } , @$messages) // $messages->[0]
&first(sub { not $_->isDeleted; } , @$messages) $messages->[0]
Truth table33%1/3
A // B
A= &first(sub { not $_->isDeleted; } , @$messages)B= $messages->[0]
ABresult
1X1
011
000
77 }
78  
79  
80 sub addMessage($)
81 0 ▶{ my ($self, $message) = @_;
Subroutine addMessage: not called CC=2 SCAR=17.9
Pod documented
82  
83 0 ▶ return $self->{MBTN_messages} = [ $message ]
Branch: 1 branch
BranchTrueFalseTotal
if $self->isDummy 0 0 0
84 if $self->isDummy;
85  
86 0 push @{$self->{MBTN_messages}}, $message;
87 0 $message;
88 }
89  
90  
91 sub expand(;$)
92 121 ▶{ my $self = shift;
Subroutine expand: called CC=4 SCAR=13.9
Pod documented
93 121 ▶ @_ or return $self->message->label('folded') || 0;
Branch: 1 branch
BranchTrueFalseTotal
@_ or return $self->message->label("folded") || 0 2 119 121
Condition100%2/2
$self->message->label('folded') || 0
l!l
1118
MC/DC100%1/1
$self->message->label('folded') || 0
$self->message->label('folded')
Truth table100%2/2
A
A= $self->message->label('folded')
Aresult
11
00
94  
95 2 my $fold = not shift;
96 2 $_->label(folded => $fold) for $self->message;
97 2 $fold;
98 }
99  
100 # compatibility <2.0
101 121 ▶sub folded(;$) { my $s = shift; @_ ? $s->expand(not $_[0]) : $s->expand }
Subroutine folded: called CC=2 SCAR=6.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 2 119 121
102  
103 #--------------------
104  
105 sub repliedTo()
106 310 ▶{ my $self = shift;
Subroutine repliedTo: called CC=2 SCAR=7.2
Pod documented
107 310 ▶ wantarray ? ($self->{MBTN_parent}, $self->{MBTN_quality}) : $self->{MBTN_parent};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 310 310
108 }
109  
110  
111 sub follows($$)
112 138 ▶{ my ($self, $thread, $how) = @_;
Subroutine follows: called CC=11 SCAR=25.0
Pod documented
113 138 my $quality = $self->{MBTN_quality};
114  
115 # Do not create cyclic constructs caused by erroneous refs.
116  
117 138 my $msgid = $self->messageId; # Look up for myself, upwards in thread
118 138 ▶ for(my $walker = $thread; defined $walker; $walker = $walker->repliedTo)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $walker) 205 138 343
119 205 ▶ { return undef if $walker->messageId eq $msgid;
Branch: 1 branch
BranchTrueFalseTotal
if $walker->messageId eq $msgid 0 205 205
120 }
121  
122 138 my $threadid = $thread->messageId; # a->b and b->a (ref order reversed)
123 138 foreach ($self->followUps)
124 38 ▶ { return undef if $_->messageId eq $threadid;
Branch: 1 branch
BranchTrueFalseTotal
if $_->messageId eq $threadid 0 38 38
125 }
126  
127 # Register
128  
129 138 ▶ if($how eq 'REPLY' || !defined $quality)
Branch: 1 branch
BranchTrueFalseTotal
if ($how eq "REPLY" or not defined $quality) 74 64 138
Condition100%3/3
$how eq "REPLY" or not defined $quality
l!l&&r!l&&!r
542064
MC/DC100%2/2
$how eq "REPLY" or not defined $quality
$how eq "REPLY" not defined $quality
Truth table100%3/3
A or not(B)
A= $how eq "REPLY"B= not defined $quality
ABresult
1X1
011
000
130 74 { $self->{MBTN_parent} = $thread;
131 74 $self->{MBTN_quality} = $how;
132 74 return $self;
133 }
134  
135 64 ▶ return $self if $quality eq 'REPLY';
Branch: 1 branch
BranchTrueFalseTotal
if $quality eq "REPLY" 56 8 64
136  
137 8 ▶ if($how eq 'REFERENCE' || ($how eq 'GUESS' && $quality ne 'REFERENCE'))
Branch: 1 branch
BranchTrueFalseTotal
if ($how eq "REFERENCE" or $how eq "GUESS" and $quality ne "REFERENCE") 8 0 8
Condition16%1/6
$how eq "REFERENCE" or $how eq "GUESS" and $quality ne "REFERENCE"
l!l&&r!l&&!r
800
$how eq "GUESS" and $quality ne "REFERENCE"
!ll&&!rl&&r
000
MC/DC0%0/3
$how eq "REFERENCE" or $how eq "GUESS" and $quality ne "REFERENCE"
$how eq "REFERENCE" $how eq "GUESS" $quality ne "REFERENCE"
Truth table25%1/4
A or B and C
A= $how eq "REFERENCE"B= $how eq "GUESS"C= $quality ne "REFERENCE"
ABCresult
1XX1
0111
00X0
0100
138 8 { $self->{MBTN_parent} = $thread;
139 8 $self->{MBTN_quality} = $how;
140 }
141  
142 8 $self;
143 }
144  
145  
146 sub followedBy(@)
147 138 ▶{ my $self = shift;
Subroutine followedBy: called CC=2 SCAR=6.9
Pod documented
148 138 $self->{MBTN_followUps}{$_->messageId} = $_ for @_;
149 138 $self;
150 }
151  
152  
153 sub followUps()
154 337 ▶{ my $self = shift;
Subroutine followUps: called CC=2 SCAR=6.9
Pod documented
155 337 ▶ $self->{MBTN_followUps} ? values %{$self->{MBTN_followUps}} : ();
Branch: 1 branch
BranchTrueFalseTotal
$self->{'MBTN_followUps'} ? : 133 204 337
156 }
157  
158  
159 sub sortedFollowUps()
160 119 ▶{ my $self = shift;
Subroutine sortedFollowUps: called CC=3 SCAR=11.9
Pod documented
161 119 ▶ my $prepare = shift || sub { $_[0]->startTimeEstimate || 0 };
Subroutine __ANON__: called CC=2 SCAR=8.4
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->startTimeEstimate or 0 60 0 60
Condition33%1/3
shift() || sub { $_[0]->startTimeEstimate or 0; }
l!l&&r!l&&!r
01190
MC/DC0%0/2
shift() || sub { $_[0]->startTimeEstimate or 0; }
shift() sub { $_[0]->startTimeEstimate or 0; }
Truth table33%1/3
A || B
A= shift()B= sub { $_[0]->startTimeEstimate or 0; }
ABresult
1X1
011
000
162 119 ▶ my $compare = shift || sub { $_[0] <=> $_[1]};
Subroutine __ANON__: called CC=1 SCAR=0.6
Condition33%1/3
shift() || sub { $_[0] <=> $_[1]; }
l!l&&r!l&&!r
01190
MC/DC0%0/2
shift() || sub { $_[0] <=> $_[1]; }
shift() sub { $_[0] <=> $_[1]; }
Truth table33%1/3
A || B
A= shift()B= sub { $_[0] <=> $_[1]; }
ABresult
1X1
011
000
163  
164 119 my %value = map +($prepare->($_) => $_), $self->followUps;
165 119 map $value{$_}, sort { $compare->($a, $b) } keys %value;
166 }
167  
168 #--------------------
169  
170 sub threadToString(;$$$) # two undocumented parameters for layout args
171 119 ▶{ my $self = shift;
Subroutine threadToString: called CC=13 SCAR=25.7
Pod documented
172 119 ▶ my $code = shift || sub { $_[0]->head->study('subject') };
Subroutine __ANON__: called CC=1 SCAR=0.1
Condition66%2/3
shift() || sub { $_[0]->head->study('subject'); }
l!l&&r!l&&!r
59600
MC/DC0%0/2
shift() || sub { $_[0]->head->study('subject'); }
shift() sub { $_[0]->head->study('subject'); }
Truth table66%2/3
A || B
A= shift()B= sub { $_[0]->head->study('subject'); }
ABresult
1X1
011
000
173 119 ▶ my ($first, $other) = (shift || '', shift || '');
Condition100%4/4
shift() || ''
l!l
5960
shift() || ''
l!l
5960
MC/DC100%1/1
shift() || ''
shift()
MC/DC100%1/1
shift() || ''
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
Truth table100%2/2
A
A= shift()
Aresult
11
00
174 119 my $message = $self->message;
175 119 my @follows = $self->sortedFollowUps;
176  
177 119 my @out;
178 119 ▶ if($self->folded)
Branch: 2 branches
BranchTrueFalseTotal
if ($self->folded) { } 1 118 119
elsif ($message->isDummy) { } 13 105 118
179 1 ▶ { my $text = $code->($message) || '';
Condition50%1/2
&$code($message) || ''
l!l
10
MC/DC0%0/1
&$code($message) || ''
&$code($message)
Truth table50%1/2
A
A= &$code($message)
Aresult
11
00
180 1 chomp $text;
181 1 return " $first [" . $self->nrMessages . "] $text\n";
182 }
183 elsif($message->isDummy)
184 13 ▶ { $first .= $first ? '-*-' : ' *-';
Branch: 1 branch
BranchTrueFalseTotal
$first ? : 2 11 13
185 13 ▶ return (shift @follows)->threadToString($code, $first, "$other " )
Branch: 1 branch
BranchTrueFalseTotal
if @follows == 1 6 7 13
186 if @follows==1;
187  
188 7 ▶ push @out, (shift @follows)->threadToString($code, $first, "$other | " )
Branch: 1 branch
BranchTrueFalseTotal
@follows > 1 and do { push @out, shift(@follows)->threadToString($code, $first, "$other | ") } 7 7 14
189 while @follows > 1;
190 }
191 else
192 105 ▶ { my $text = $code->($message) || '';
Condition100%2/2
&$code($message) || ''
l!l
1014
MC/DC100%1/1
&$code($message) || ''
&$code($message)
Truth table100%2/2
A
A= &$code($message)
Aresult
11
00
193 105 chomp $text;
194 105 my $size = $message->shortSize;
195 105 @out = "$size$first $text\n";
196 105 ▶ push @out, (shift @follows)->threadToString($code, "$other |-", "$other | " )
Branch: 1 branch
BranchTrueFalseTotal
@follows > 1 and do { push @out, shift(@follows)->threadToString($code, "$other |-", "$other | ") } 0 105 105
197 while @follows > 1;
198 }
199  
200 112 ▶ push @out, (shift @follows)->threadToString($code, "$other `-","$other " )
Branch: 1 branch
BranchTrueFalseTotal
if @follows 46 66 112
201 if @follows;
202  
203 112 join '', @out;
204 }
205  
206  
207 sub startTimeEstimate()
208 130 ▶{ my $self = shift;
Subroutine startTimeEstimate: called CC=6 SCAR=18.2
Pod documented
209 130 ▶ $self->isDummy or return $self->message->timestamp;
Branch: 1 branch
BranchTrueFalseTotal
$self->isDummy or return $self->message->timestamp 10 120 130
210  
211 10 my $earliest;
212 10 foreach ($self->followUps)
213 14 { my $stamp = $_->startTimeEstimate;
214 14 ▶ $earliest = $stamp if !defined $earliest || (defined $stamp && $stamp < $earliest);
Branch: 1 branch
BranchTrueFalseTotal
if not defined $earliest or defined $stamp and $stamp < $earliest 10 4 14
Condition50%3/6
not defined $earliest or defined $stamp and $stamp < $earliest
l!l&&r!l&&!r
1004
defined $stamp and $stamp < $earliest
!ll&&!rl&&r
040
MC/DC33%1/3
not defined $earliest or defined $stamp and $stamp < $earliest
not defined $earliest defined $stamp $stamp < $earliest
Truth table50%2/4
not(A) or B and C
A= not defined $earliestB= defined $stampC= $stamp < $earliest
ABCresult
1XX1
0111
00X0
0100
215 }
216  
217 10 $earliest;
218 }
219  
220  
221 sub endTimeEstimate()
222 0 ▶{ my $self = shift;
Subroutine endTimeEstimate: not called CC=1 SCAR=6.9
Pod documented
223  
224 0 my $latest;
225 0 ▶ $self->recurse( sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
226 0 my $node = shift;
227 0 ▶ return 1 if $node->isDummy;
Branch: 1 branch
BranchTrueFalseTotal
if $node->isDummy 0 0 0
228 0 my $stamp = $node->message->timestamp;
229 0 ▶ $latest = $stamp if !$latest || $stamp > $latest;
Branch: 1 branch
BranchTrueFalseTotal
if not $latest or $stamp > $latest 0 0 0
Condition0%0/3
not $latest or $stamp > $latest
l!l&&r!l&&!r
000
MC/DC0%0/2
not $latest or $stamp > $latest
not $latest $stamp > $latest
Truth table0%0/3
not(A) or B
A= not $latestB= $stamp > $latest
ABresult
1X1
011
000
230 0 1;
231 0 });
232  
233 0 $latest;
234 }
235  
236  
237 sub recurse($)
238 70 ▶{ my ($self, $code) = @_;
Subroutine recurse: called CC=4 SCAR=14.5
Pod documented
239  
240 70 ▶ $code->($self) or return $self;
Branch: 1 branch
BranchTrueFalseTotal
&$code($self) or return $self 70 0 70
241  
242 $_->recurse($code) or last
243 70 ▶ for $self->followUps;
Branch: 1 branch
BranchTrueFalseTotal
$_->recurse($code) or last 34 0 34
244  
245 70 $self;
246 }
247  
248  
249 sub totalSize()
250 0 ▶{ my $self = shift;
Subroutine totalSize: not called CC=1 SCAR=6.9
Pod documented
251 0 my $total = 0;
252  
253 0 ▶ $self->recurse(sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
254 0 my @msgs = shift->messages;
255 0 ▶ $total += $msgs[0]->size if @msgs;
Branch: 1 branch
BranchTrueFalseTotal
if @msgs 0 0 0
256 0 1;
257 0 });
258  
259 0 $total;
260 }
261  
262  
263 sub numberOfMessages()
264 29 ▶{ my $self = shift;
Subroutine numberOfMessages: called CC=1 SCAR=0.0
Pod documented
265 29 my $total = 0;
266 29 ▶ $self->recurse( sub { $_[0]->isDummy or ++$total; 1 } );
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->isDummy or ++$total 5 49 54
267 29 $total;
268 }
269  
270 1 ▶sub nrMessages() { $_[0]->numberOfMessages } # compatibility
Subroutine nrMessages: called CC=1 SCAR=0.0
Pod undocumented
271  
272  
273 sub threadMessages()
274 3 ▶{ my $self = shift;
Subroutine threadMessages: called CC=1 SCAR=0.0
Pod documented
275 3 my @messages;
276 6 ▶ $self->recurse( sub {
Subroutine __ANON__: called CC=2 SCAR=7.1
277 6 my $node = shift;
278 6 ▶ push @messages, $node->message unless $node->isDummy;
Branch: 1 branch
BranchTrueFalseTotal
unless $node->isDummy 6 0 6
279 6 1;
280 3 });
281  
282 3 @messages;
283 }
284  
285  
286 sub ids()
287 0 ▶{ my $self = shift;
Subroutine ids: not called CC=1 SCAR=6.9
Pod documented
288 0 my @ids;
289 0 ▶ $self->recurse( sub { push @ids, $_[0]->messageId } );
Subroutine __ANON__: not called CC=1 SCAR=6.9
290 0 @ids;
291 }
292  
293 4 1;
« Box/Thread/Manager.pm ↑ Summary Box/Dir/Message.pm »