Box/Thread/Node.pm

filter: Statementstmt 10.8% 17 / 157 Branchbran 0.0% 0 / 72 Conditioncond 0.0% 0 / 40 MC/DCmcdc 0.0% 0 / 23 Subroutinesub 14.2% 5 / 35 Podpod 86.3% 19 / 22 totaltotal 11.7% 41 / 349 CC 58 SCAR 39.9
CC
58
Cov
6%
threadToString
182.0
follows
132.0
message
56.0
CRAP 54.0
« Box/Net.pm ↑ Summary Box/Locker/Mutt.pm »
1 # Copyrights 2001-2020 by [Mark Overmeer].
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.02.
5 # This code is part of distribution Mail-Box. 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::Box::Thread::Node;
10 1 ▶use vars '$VERSION';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 $VERSION = '3.009';
12  
13 1 ▶use base 'Mail::Reporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20  
21 sub new(@)
22 0 ▶{ my ($class, %args) = @_;
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
23 0 (bless {}, $class)->init(\%args);
24 }
25  
26 sub init($)
27 0 ▶{ my ($self, $args) = @_;
Subroutine init: not called CC=4 SCAR=30.0
Pod undocumented
28  
29 0 ▶ if(my $message = $args->{message})
Branch: 2 branches
BranchTrueFalseTotal
if (my $message = $args->{'message'}) { } 0 0 0
elsif (my $msgid = $args->{'msgid'}) { } 0 0 0
30 0 { push @{$self->{MBTN_messages}}, $message;
31 0 ▶ $self->{MBTN_msgid} = $args->{msgid} || $message->messageId;
Condition0%0/3
$args->{'msgid'} || $message->messageId
l!l&&r!l&&!r
000
MC/DC0%0/2
$args->{'msgid'} || $message->messageId
$args->{'msgid'} $message->messageId
Truth table0%0/3
A || B
A= $args->{'msgid'}B= $message->messageId
ABresult
1X1
011
000
32 }
33 elsif(my $msgid = $args->{msgid})
34 0 { $self->{MBTN_msgid} = $msgid;
35 }
36 else
37 0 { croak "Need to specify message or message-id";
38 }
39  
40 0 $self->{MBTN_dummy_type} = $args->{dummy_type};
41 0 $self;
42 }
43  
44 #-------------------------------------------
45  
46  
47 sub message()
48 0 ▶{ my $self = shift;
Subroutine message: not called CC=7 SCAR=40.3
Pod documented
49  
50 0 ▶ unless($self->{MBTN_messages})
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"MBTN_messages"}) 0 0 0
51 0 ▶ { return () if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 0 0 0
52  
53 my $dummy = $self->{MBTN_dummy_type}->new
54 ( messageId =>$self->{MBTN_msgid}
55 0 );
56  
57 0 push @{$self->{MBTN_messages}}, $dummy;
58 0 return $dummy;
59 }
60  
61 0 my @messages = @{$self->{MBTN_messages}};
62 0 ▶ return @messages if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 0 0 0
63 0 ▶ return $messages[0] if @messages==1;
Branch: 1 branch
BranchTrueFalseTotal
if @messages == 1 0 0 0
64  
65 0 foreach (@messages)
66 0 ▶ { return $_ unless $_->isDeleted;
Branch: 1 branch
BranchTrueFalseTotal
unless $_->isDeleted 0 0 0
67 }
68  
69 0 $messages[0];
70 }
71  
72  
73 sub addMessage($)
74 0 ▶{ my ($self, $message) = @_;
Subroutine addMessage: not called CC=2 SCAR=17.9
Pod documented
75
76 0 ▶ return $self->{MBTN_messages} = [ $message ]
Branch: 1 branch
BranchTrueFalseTotal
if $self->isDummy 0 0 0
77 if $self->isDummy;
78  
79 0 push @{$self->{MBTN_messages}}, $message;
80 0 $message;
81 }
82  
83  
84 sub isDummy()
85 0 ▶{ my $self = shift;
Subroutine isDummy: not called CC=2 SCAR=17.9
Pod documented
86 0 ▶ !defined $self->{MBTN_messages} || $self->{MBTN_messages}[0]->isDummy;
Branch: 1 branch
BranchTrueFalseTotal
not defined $self->{"MBTN_messages"} or $self->{"MBTN_messages"}[0]->isDummy 0 0 0
87 }
88  
89  
90 0 ▶sub messageId() { shift->{MBTN_msgid} }
Subroutine messageId: not called CC=1 SCAR=6.9
Pod documented
91  
92  
93 sub expand(;$)
94 0 ▶{ my $self = shift;
Subroutine expand: not called CC=4 SCAR=30.0
Pod documented
95 0 ▶ return $self->message->label('folded') || 0
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
Condition0%0/2
$self->message->label('folded') || 0
l!l
00
MC/DC0%0/1
$self->message->label('folded') || 0
$self->message->label('folded')
Truth table0%0/2
A
A= $self->message->label('folded')
Aresult
11
00
96 unless @_;
97  
98 0 my $fold = not shift;
99 0 $_->label(folded => $fold) foreach $self->message;
100 0 $fold;
101 }
102  
103 sub folded(;$) # compatibility <2.0
104 0 ▶{ @_ == 1 ? shift->expand : shift->expand(not shift) }
Subroutine folded: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 0 0 0
105  
106 #-------------------------------------------
107  
108 sub repliedTo()
109 0 ▶{ my $self = shift;
Subroutine repliedTo: not called CC=2 SCAR=17.9
Pod documented
110  
111 return wantarray
112 ? ($self->{MBTN_parent}, $self->{MBTN_quality})
113 0 ▶ : $self->{MBTN_parent};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
114 }
115  
116  
117 sub follows($$)
118 0 ▶{ my ($self, $thread, $how) = @_;
Subroutine follows: not called CC=11 SCAR=48.8
Pod documented
119 0 my $quality = $self->{MBTN_quality};
120  
121 # Do not create cyclic constructs caused by erroneous refs.
122  
123 0 my $msgid = $self->messageId; # Look up for myself, upwards in thread
124 0 ▶ for(my $walker = $thread; defined $walker; $walker = $walker->repliedTo)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $walker) 0 0 0
125 0 ▶ { return undef if $walker->messageId eq $msgid;
Branch: 1 branch
BranchTrueFalseTotal
if $walker->messageId eq $msgid 0 0 0
126 }
127  
128 0 my $threadid = $thread->messageId; # a->b and b->a (ref order reversed)
129 0 foreach ($self->followUps)
130 0 ▶ { return undef if $_->messageId eq $threadid;
Branch: 1 branch
BranchTrueFalseTotal
if $_->messageId eq $threadid 0 0 0
131 }
132  
133 # Register
134  
135 0 ▶ if($how eq 'REPLY' || !defined $quality)
Branch: 1 branch
BranchTrueFalseTotal
if ($how eq "REPLY" or not defined $quality) 0 0 0
Condition0%0/3
$how eq "REPLY" or not defined $quality
l!l&&r!l&&!r
000
MC/DC0%0/2
$how eq "REPLY" or not defined $quality
$how eq "REPLY" not defined $quality
Truth table0%0/3
A or not(B)
A= $how eq "REPLY"B= not defined $quality
ABresult
1X1
011
000
136 0 { $self->{MBTN_parent} = $thread;
137 0 $self->{MBTN_quality} = $how;
138 0 return $self;
139 }
140
141 0 ▶ return $self if $quality eq 'REPLY';
Branch: 1 branch
BranchTrueFalseTotal
if $quality eq "REPLY" 0 0 0
142  
143 0 ▶ 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") 0 0 0
Condition0%0/6
$how eq "REFERENCE" or $how eq "GUESS" and $quality ne "REFERENCE"
l!l&&r!l&&!r
000
$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 table0%0/4
A or B and C
A= $how eq "REFERENCE"B= $how eq "GUESS"C= $quality ne "REFERENCE"
ABCresult
1XX1
0111
00X0
0100
144 0 { $self->{MBTN_parent} = $thread;
145 0 $self->{MBTN_quality} = $how;
146 }
147  
148 0 $self;
149 }
150  
151  
152 sub followedBy(@)
153 0 ▶{ my $self = shift;
Subroutine followedBy: not called CC=2 SCAR=17.9
Pod documented
154 0 $self->{MBTN_followUps}{$_->messageId} = $_ foreach @_;
155 0 $self;
156 }
157  
158  
159 sub followUps()
160 0 ▶{ my $self = shift;
Subroutine followUps: not called CC=2 SCAR=17.9
Pod documented
161 0 ▶ $self->{MBTN_followUps} ? values %{$self->{MBTN_followUps}} : ();
Branch: 1 branch
BranchTrueFalseTotal
$self->{'MBTN_followUps'} ? : 0 0 0
162 }
163  
164  
165 sub sortedFollowUps()
166 0 ▶{ my $self = shift;
Subroutine sortedFollowUps: not called CC=3 SCAR=24.8
Pod documented
167 0 ▶ my $prepare = shift || sub {shift->startTimeEstimate||0};
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
(shift())->startTimeEstimate or 0 0 0 0
Condition0%0/3
shift() || sub { (shift())->startTimeEstimate or 0; }
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || sub { (shift())->startTimeEstimate or 0; }
shift() sub { (shift())->startTimeEstimate or 0; }
Truth table0%0/3
A || B
A= shift()B= sub { (shift())->startTimeEstimate or 0; }
ABresult
1X1
011
000
168 0 ▶ my $compare = shift || sub {(shift) <=> (shift)};
Subroutine __ANON__: not called CC=1 SCAR=6.9
Condition0%0/3
shift() || sub { shift() <=> shift(); }
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || sub { shift() <=> shift(); }
shift() sub { shift() <=> shift(); }
Truth table0%0/3
A || B
A= shift()B= sub { shift() <=> shift(); }
ABresult
1X1
011
000
169  
170 0 my %value = map { ($prepare->($_) => $_) } $self->followUps;
171 0 map { $value{$_} } sort {$compare->($a, $b)} keys %value;
172 }
173  
174 #-------------------------------------------
175  
176 sub threadToString(;$$$) # two undocumented parameters for layout args
177 0 ▶{ my $self = shift;
Subroutine threadToString: not called CC=13 SCAR=52.0
Pod documented
178 0 ▶ my $code = shift || sub {shift->head->study('subject')};
Subroutine __ANON__: not called CC=1 SCAR=6.9
Condition0%0/3
shift() || sub { (shift())->head->study('subject'); }
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || sub { (shift())->head->study('subject'); }
shift() sub { (shift())->head->study('subject'); }
Truth table0%0/3
A || B
A= shift()B= sub { (shift())->head->study('subject'); }
ABresult
1X1
011
000
179 0 ▶ my ($first, $other) = (shift || '', shift || '');
Condition0%0/4
shift() || ''
l!l
00
shift() || ''
l!l
00
MC/DC0%0/1
shift() || ''
shift()
MC/DC0%0/1
shift() || ''
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
Truth table0%0/2
A
A= shift()
Aresult
11
00
180 0 my $message = $self->message;
181 0 my @follows = $self->sortedFollowUps;
182  
183 0 my @out;
184 0 ▶ if($self->folded)
Branch: 2 branches
BranchTrueFalseTotal
if ($self->folded) { } 0 0 0
elsif ($message->isDummy) { } 0 0 0
185 0 ▶ { my $text = $code->($message) || '';
Condition0%0/2
&$code($message) || ''
l!l
00
MC/DC0%0/1
&$code($message) || ''
&$code($message)
Truth table0%0/2
A
A= &$code($message)
Aresult
11
00
186 0 chomp $text;
187 0 return " $first [" . $self->nrMessages . "] $text\n";
188 }
189 elsif($message->isDummy)
190 0 ▶ { $first .= $first ? '-*-' : ' *-';
Branch: 1 branch
BranchTrueFalseTotal
$first ? : 0 0 0
191 0 ▶ return (shift @follows)->threadToString($code, $first, "$other " )
Branch: 1 branch
BranchTrueFalseTotal
if @follows == 1 0 0 0
192 if @follows==1;
193  
194 0 ▶ push @out, (shift @follows)->threadToString($code, $first, "$other | " )
Branch: 1 branch
BranchTrueFalseTotal
@follows > 1 and do { push @out, shift(@follows)->threadToString($code, $first, "$other | ") } 0 0 0
195 while @follows > 1;
196 }
197 else
198 0 ▶ { my $text = $code->($message) || '';
Condition0%0/2
&$code($message) || ''
l!l
00
MC/DC0%0/1
&$code($message) || ''
&$code($message)
Truth table0%0/2
A
A= &$code($message)
Aresult
11
00
199 0 chomp $text;
200 0 my $size = $message->shortSize;
201 0 @out = "$size$first $text\n";
202 0 ▶ push @out, (shift @follows)
Branch: 1 branch
BranchTrueFalseTotal
@follows > 1 and do { push @out, shift(@follows)->threadToString($code, "$other |-", "$other | ") } 0 0 0
203 ->threadToString($code, "$other |-", "$other | " )
204 while @follows > 1;
205 }
206  
207 0 ▶ push @out, (shift @follows)->threadToString($code, "$other `-","$other " )
Branch: 1 branch
BranchTrueFalseTotal
if @follows 0 0 0
208 if @follows;
209  
210 0 join '', @out;
211 }
212  
213  
214 sub startTimeEstimate()
215 0 ▶{ my $self = shift;
Subroutine startTimeEstimate: not called CC=6 SCAR=37.4
Pod documented
216  
217 0 ▶ return $self->message->timestamp
Branch: 1 branch
BranchTrueFalseTotal
unless $self->isDummy 0 0 0
218 unless $self->isDummy;
219  
220 0 my $earliest;
221 0 foreach ($self->followUps)
222 0 { my $stamp = $_->startTimeEstimate;
223  
224 0 ▶ $earliest = $stamp
Branch: 1 branch
BranchTrueFalseTotal
if not defined $earliest or defined $stamp and $stamp < $earliest 0 0 0
Condition0%0/6
not defined $earliest or defined $stamp and $stamp < $earliest
l!l&&r!l&&!r
000
defined $stamp and $stamp < $earliest
!ll&&!rl&&r
000
MC/DC0%0/3
not defined $earliest or defined $stamp and $stamp < $earliest
not defined $earliest defined $stamp $stamp < $earliest
Truth table0%0/4
not(A) or B and C
A= not defined $earliestB= defined $stampC= $stamp < $earliest
ABCresult
1XX1
0111
00X0
0100
225 if !defined $earliest || (defined $stamp && $stamp < $earliest);
226 }
227  
228 0 $earliest;
229 }
230  
231  
232 sub endTimeEstimate()
233 0 ▶{ my $self = shift;
Subroutine endTimeEstimate: not called CC=1 SCAR=6.9
Pod documented
234  
235 0 my $latest;
236 $self->recurse
237 0 ▶ ( sub { my $node = shift;
Subroutine __ANON__: not called CC=4 SCAR=30.0
238 0 ▶ unless($node->isDummy)
Branch: 1 branch
BranchTrueFalseTotal
unless ($node->isDummy) 0 0 0
239 0 { my $stamp = $node->message->timestamp;
240 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
241 }
242 }
243 0 );
244  
245 0 $latest;
246 }
247  
248  
249 sub recurse($)
250 0 ▶{ my ($self, $code) = @_;
Subroutine recurse: not called CC=4 SCAR=30.0
Pod documented
251  
252 0 ▶ $code->($self) or return $self;
Branch: 1 branch
BranchTrueFalseTotal
&$code($self) or return $self 0 0 0
253  
254 $_->recurse($code) or last
255 0 ▶ foreach $self->followUps;
Branch: 1 branch
BranchTrueFalseTotal
$_->recurse($code) or last 0 0 0
256  
257 0 $self;
258 }
259  
260  
261 sub totalSize()
262 0 ▶{ my $self = shift;
Subroutine totalSize: not called CC=1 SCAR=6.9
Pod documented
263 0 my $total = 0;
264  
265 $self->recurse
266 ( sub {
267 0 ▶ my @msgs = shift->messages;
Subroutine __ANON__: not called CC=2 SCAR=17.9
268 0 ▶ $total += $msgs[0]->size if @msgs;
Branch: 1 branch
BranchTrueFalseTotal
if @msgs 0 0 0
269 0 1;}
270 0 );
271  
272 0 $total;
273 }
274  
275  
276 sub numberOfMessages()
277 0 ▶{ my $self = shift;
Subroutine numberOfMessages: not called CC=1 SCAR=6.9
Pod documented
278 0 my $total = 0;
279 0 ▶ $self->recurse( sub {++$total unless shift->isDummy; 1} );
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
unless (shift())->isDummy 0 0 0
280 0 $total;
281 }
282  
283 0 ▶sub nrMessages() {shift->numberOfMessages} # compatibility
Subroutine nrMessages: not called CC=1 SCAR=6.9
Pod undocumented
284  
285  
286 sub threadMessages()
287 0 ▶{ my $self = shift;
Subroutine threadMessages: not called CC=1 SCAR=6.9
Pod documented
288 0 my @messages;
289 $self->recurse
290 ( sub
291 0 ▶ { my $node = shift;
Subroutine __ANON__: not called CC=2 SCAR=17.9
292 0 ▶ push @messages, $node->message unless $node->isDummy;
Branch: 1 branch
BranchTrueFalseTotal
unless $node->isDummy 0 0 0
293 0 1;
294 }
295 0 );
296  
297 0 @messages;
298 }
299  
300  
301  
302 sub ids()
303 0 ▶{ my $self = shift;
Subroutine ids: not called CC=1 SCAR=6.9
Pod documented
304 0 my @ids;
305 0 ▶ $self->recurse( sub {push @ids, shift->messageId} );
Subroutine __ANON__: not called CC=1 SCAR=6.9
306 0 @ids;
307 }
308  
309 #-------------------------------------------
310  
311  
312  
313 1 1;
« Box/Net.pm ↑ Summary Box/Locker/Mutt.pm »