Box/MH/Labels.pm

filter: Statementstmt 24.7% 23 / 93 Branchbran 0.0% 0 / 36 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 50.0% 7 / 14 Podpod 85.7% 6 / 7 totaltotal 23.2% 36 / 155 CC 25 SCAR 43.6
CC
25
Cov
17%
read
132.0
print
132.0
write
12.0
CRAP 78.3
« Box/Maildir.pm ↑ Summary Box.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::MH::Labels;
10 9 ▶use vars '$VERSION';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 9 $VERSION = '3.009';
12  
13 9 ▶use base 'Mail::Reporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 9 ▶use Mail::Message::Head::Subset;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 9 ▶use File::Copy;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 9 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23  
24 #-------------------------------------------
25  
26  
27 sub init($)
28 0 ▶{ my ($self, $args) = @_;
Subroutine init: not called CC=2 SCAR=17.9
Pod undocumented
29 0 $self->SUPER::init($args);
30 $self->{MBML_filename} = $args->{filename}
31 0 ▶ or croak "No label filename specified.";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"MBML_filename"} = $args->{"filename"} or croak("No label filename specified.") 0 0 0
32  
33 0 $self;
34 }
35  
36 #-------------------------------------------
37  
38  
39 0 ▶sub filename() {shift->{MBML_filename}}
Subroutine filename: not called CC=1 SCAR=6.9
Pod documented
40  
41 #-------------------------------------------
42  
43  
44 sub get($)
45 0 ▶{ my ($self, $msgnr) = @_;
Subroutine get: not called CC=1 SCAR=6.9
Pod documented
46 0 $self->{MBML_labels}[$msgnr];
47 }
48  
49 #-------------------------------------------
50  
51  
52 sub read()
53 0 ▶{ my $self = shift;
Subroutine read: not called CC=11 SCAR=48.8
Pod documented
54 0 my $seq = $self->filename;
55  
56 0 ▶ open SEQ, '<:raw', $seq
Branch: 1 branch
BranchTrueFalseTotal
open SEQ, "<:raw", $seq or return 0 0 0
57 or return;
58  
59 0 my @labels;
60  
61 0 local $_;
62 0 ▶ while(<SEQ>)
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline SEQ)) 0 0 0
63 0 { s/\s*\#.*$//;
64 0 ▶ next unless length;
Branch: 1 branch
BranchTrueFalseTotal
unless length $_ 0 0 0
65  
66 0 ▶ next unless s/^\s*(\w+)\s*\:\s*//;
Branch: 1 branch
BranchTrueFalseTotal
unless s/^\s*(\w+)\s*\:\s*// 0 0 0
67 0 my $label = $1;
68  
69 0 my $set = 1;
70 0 ▶ if($label eq 'cur' ) { $label = 'current' }
Branch: 2 branches
BranchTrueFalseTotal
if ($label eq 'cur') { } 0 0 0
elsif ($label eq 'unseen') { } 0 0 0
71 0 elsif($label eq 'unseen') { $label = 'seen'; $set = 0 }
72  
73 0 foreach (split /\s+/)
74 0 ▶ { if( /^(\d+)\-(\d+)\s*$/ )
Branch: 2 branches
BranchTrueFalseTotal
if (/^(\d+)\-(\d+)\s*$/) { } 0 0 0
elsif (/^\d+\s*$/) { } 0 0 0
75 0 { push @{$labels[$_]}, $label, $set foreach $1..$2;
76 }
77 elsif( /^\d+\s*$/ )
78 0 { push @{$labels[$_]}, $label, $set;
79 }
80 }
81 }
82  
83 0 close SEQ;
84  
85 0 $self->{MBML_labels} = \@labels;
86 0 $self;
87 }
88  
89 #-------------------------------------------
90  
91  
92 sub write(@)
93 0 ▶{ my $self = shift;
Subroutine write: not called CC=3 SCAR=24.8
Pod documented
94 0 my $filename = $self->filename;
95  
96 # Remove when no messages are left.
97 0 ▶ unless(@_)
Branch: 1 branch
BranchTrueFalseTotal
unless (@_) 0 0 0
98 0 { unlink $filename;
99 0 return $self;
100 }
101  
102 0 ▶ open my $out, '>:raw', $filename or return;
Branch: 1 branch
BranchTrueFalseTotal
open my $out, ">:raw", $filename or return 0 0 0
103 0 $self->print($out, @_);
104 0 close $out;
105  
106 0 $self;
107 }
108  
109 #-------------------------------------------
110  
111  
112 sub append(@)
113 0 ▶{ my $self = shift;
Subroutine append: not called CC=2 SCAR=17.9
Pod documented
114 0 my $filename = $self->filename;
115  
116 0 ▶ open(my $out, '>>:raw', $filename) or return;
Branch: 1 branch
BranchTrueFalseTotal
open my $out, ">>:raw", $filename or return 0 0 0
117 0 $self->print($out, @_);
118 0 close $out;
119  
120 0 $self;
121 }
122  
123 #-------------------------------------------
124  
125  
126 sub print($@)
127 0 ▶{ my ($self, $out) = (shift, shift);
Subroutine print: not called CC=11 SCAR=48.8
Pod documented
128  
129 # Collect the labels from the selected messages.
130 0 my %labeled;
131 0 foreach my $message (@_)
132 0 { my $labels = $message->labels;
133 0 (my $seq = $message->filename) =~ s!.*/!!;
134  
135 0 push @{$labeled{unseen}}, $seq
136 0 ▶ unless $labels->{seen};
Branch: 1 branch
BranchTrueFalseTotal
unless $labels->{"seen"} 0 0 0
137  
138 0 foreach (keys %$labels)
139 0 { push @{$labeled{$_}}, $seq
140 0 ▶ if $labels->{$_};
Branch: 1 branch
BranchTrueFalseTotal
if $labels->{$_} 0 0 0
141 }
142 }
143 0 delete $labeled{seen};
144  
145 # Write it out
146  
147 0 local $" = ' ';
148 0 foreach (sort keys %labeled)
149 {
150 0 my @msgs = @{$labeled{$_}}; #they are ordered already.
151 0 ▶ $_ = 'cur' if $_ eq 'current';
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "current" 0 0 0
152 0 print $out "$_:";
153  
154 0 ▶ while(@msgs)
Branch: 1 branch
BranchTrueFalseTotal
if (@msgs) 0 0 0
155 0 { my $start = shift @msgs;
156 0 my $end = $start;
157  
158 0 ▶ $end = shift @msgs
Branch: 1 branch
BranchTrueFalseTotal
@msgs and $msgs[0] == $end + 1 and do { $end = shift @msgs } 0 0 0
Condition0%0/3
@msgs and $msgs[0] == $end + 1
!ll&&!rl&&r
000
MC/DC0%0/2
@msgs and $msgs[0] == $end + 1
@msgs $msgs[0] == $end + 1
Truth table0%0/3
A and B
A= @msgsB= $msgs[0] == $end + 1
ABresult
0X0
100
111
159 while @msgs && $msgs[0]==$end+1;
160  
161 0 ▶ print $out ($start==$end ? " $start" : " $start-$end");
Branch: 1 branch
BranchTrueFalseTotal
$start == $end ? : 0 0 0
162 }
163 0 print $out "\n";
164 }
165  
166 0 $self;
167 }
168  
169 #-------------------------------------------
170  
171  
172 9 1;
« Box/Maildir.pm ↑ Summary Box.pm »