Box/MH/Index.pm

filter: Statementstmt 25.9% 20 / 77 Branchbran 0.0% 0 / 26 Conditioncond 0.0% 0 / 16 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 50.0% 6 / 12 Podpod 83.3% 5 / 6 totaltotal 21.0% 31 / 147 CC 22 SCAR 36.8
CC
22
Cov
17%
write
72.0
read
56.0
append
42.0
CRAP 39.7
« Box/Dir.pm ↑ Summary Box/Dir/Message.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::Index;
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 9 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21  
22 #-------------------------------------------
23  
24  
25 sub init($)
26 0 ▶{ my ($self, $args) = @_;
Subroutine init: not called CC=4 SCAR=30.0
Pod undocumented
27 0 $self->SUPER::init($args);
28  
29 $self->{MBMI_filename} = $args->{filename}
30 0 ▶ or croak "No index filename specified.";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"MBMI_filename"} = $args->{"filename"} or croak("No index filename specified.") 0 0 0
31  
32 0 ▶ $self->{MBMI_head_wrap} = $args->{head_wrap} || 72;
Condition0%0/2
$args->{'head_wrap'} || 72
l!l
00
MC/DC0%0/1
$args->{'head_wrap'} || 72
$args->{'head_wrap'}
Truth table0%0/2
A
A= $args->{'head_wrap'}
Aresult
11
00
33 $self->{MBMI_head_type}
34 0 ▶ = $args->{head_type} || 'Mail::Message::Head::Subset';
Condition0%0/2
$args->{'head_type'} || 'Mail::Message::Head::Subset'
l!l
00
MC/DC0%0/1
$args->{'head_type'} || 'Mail::Message::Head::Subset'
$args->{'head_type'}
Truth table0%0/2
A
A= $args->{'head_type'}
Aresult
11
00
35  
36 0 $self;
37 }
38  
39 #-------------------------------------------
40  
41  
42 0 ▶sub filename() {shift->{MBMI_filename}}
Subroutine filename: not called CC=1 SCAR=6.9
Pod documented
43  
44 #-------------------------------------------
45  
46  
47 sub write(@)
48 0 ▶{ my $self = shift;
Subroutine write: not called CC=8 SCAR=42.8
Pod documented
49 0 ▶ my $index = $self->filename or return $self;
Branch: 1 branch
BranchTrueFalseTotal
my $index = $self->filename or return $self 0 0 0
50  
51 # Remove empty index-file.
52 0 ▶ unless(@_)
Branch: 1 branch
BranchTrueFalseTotal
unless (@_) 0 0 0
53 0 { unlink $index;
54 0 return $self;
55 }
56  
57 0 local *INDEX;
58 0 ▶ open INDEX, '>:raw', $index
Branch: 1 branch
BranchTrueFalseTotal
open INDEX, ">:raw", $index or return $self 0 0 0
59 or return $self;
60  
61 0 my $fieldtype = 'Mail::Message::Field';
62 0 my $written = 0;
63  
64 0 foreach my $msg (@_)
65 0 { my $head = $msg->head;
66 0 ▶ next if $head->isDelayed && $head->isa('Mail::Message::Head::Subset');
Branch: 1 branch
BranchTrueFalseTotal
if $head->isDelayed and $head->isa("Mail::Message::Head::Subset") 0 0 0
Condition0%0/3
$head->isDelayed and $head->isa("Mail::Message::Head::Subset")
!ll&&!rl&&r
000
MC/DC0%0/2
$head->isDelayed and $head->isa("Mail::Message::Head::Subset")
$head->isDelayed $head->isa("Mail::Message::Head::Subset")
Truth table0%0/3
A and B
A= $head->isDelayedB= $head->isa("Mail::Message::Head::Subset")
ABresult
0X0
100
111
67  
68 0 my $filename = $msg->filename;
69 0 print INDEX "X-MailBox-Filename: $filename\n"
70 , 'X-MailBox-Size: ', (-s $filename), "\n";
71  
72 0 $head->print(\*INDEX);
73 0 $written++;
74 }
75  
76 0 close INDEX;
77  
78 0 ▶ $written or unlink $index;
Branch: 1 branch
BranchTrueFalseTotal
$written or unlink $index 0 0 0
79  
80 0 $self;
81 }
82  
83 #-------------------------------------------
84  
85  
86 sub append(@)
87 0 ▶{ my $self = shift;
Subroutine append: not called CC=6 SCAR=37.4
Pod documented
88 0 ▶ my $index = $self->filename or return $self;
Branch: 1 branch
BranchTrueFalseTotal
my $index = $self->filename or return $self 0 0 0
89  
90 0 local *INDEX;
91 0 ▶ open INDEX, '>>:raw', $index
Branch: 1 branch
BranchTrueFalseTotal
open INDEX, ">>:raw", $index or return $self 0 0 0
92 or return $self;
93  
94 0 my $fieldtype = 'Mail::Message::Field';
95  
96 0 foreach my $msg (@_)
97 0 { my $head = $msg->head;
98 0 ▶ next if $head->isDelayed && $head->isa('Mail::Message::Head::Subset');
Branch: 1 branch
BranchTrueFalseTotal
if $head->isDelayed and $head->isa("Mail::Message::Head::Subset") 0 0 0
Condition0%0/3
$head->isDelayed and $head->isa("Mail::Message::Head::Subset")
!ll&&!rl&&r
000
MC/DC0%0/2
$head->isDelayed and $head->isa("Mail::Message::Head::Subset")
$head->isDelayed $head->isa("Mail::Message::Head::Subset")
Truth table0%0/3
A and B
A= $head->isDelayedB= $head->isa("Mail::Message::Head::Subset")
ABresult
0X0
100
111
99  
100 0 my $filename = $msg->filename;
101 0 print INDEX "X-MailBox-Filename: $filename\n"
102 , 'X-MailBox-Size: ', (-s $filename), "\n";
103  
104 0 $head->print(\*INDEX);
105 }
106  
107 0 close INDEX;
108 0 $self;
109 }
110  
111 #-------------------------------------------
112  
113  
114 sub read(;$)
115 0 ▶{ my $self = shift;
Subroutine read: not called CC=7 SCAR=40.3
Pod documented
116 0 my $filename = $self->{MBMI_filename};
117  
118 0 ▶ my $parser = Mail::Box::Parser->new
Branch: 1 branch
BranchTrueFalseTotal
my $parser = "Mail::Box::Parser"->new("filename", $filename, "mode", "r") or return 0 0 0
119 ( filename => $filename
120 , mode => 'r'
121 ) or return;
122  
123 0 my @options = ($self->logSettings, wrap_length => $self->{MBMI_head_wrap});
124 0 my $type = $self->{MBMI_head_type};
125 0 my $index_age= -M $filename;
126 0 my %index;
127  
128 0 ▶ while(my $head = $type->new(@options)->read($parser))
Branch: 1 branch
BranchTrueFalseTotal
if (my $head = $type->new(@options)->read($parser)) 0 0 0
129 {
130 # cleanup the index from files which were renamed
131 0 my $msgfile = $head->get('x-mailbox-filename');
132 0 my $size = int $head->get('x-mailbox-size');
133 0 ▶ next unless -f $msgfile && -s _ == $size;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $msgfile and -s _ == $size 0 0 0
Condition0%0/3
-f $msgfile and -s _ == $size
!ll&&!rl&&r
000
MC/DC0%0/2
-f $msgfile and -s _ == $size
-f $msgfile -s _ == $size
Truth table0%0/3
A and B
A= -f $msgfileB= -s _ == $size
ABresult
0X0
100
111
134 0 ▶ next if defined $index_age && -M _ < $index_age;
Branch: 1 branch
BranchTrueFalseTotal
if defined $index_age and -M _ < $index_age 0 0 0
Condition0%0/3
defined $index_age and -M _ < $index_age
!ll&&!rl&&r
000
MC/DC0%0/2
defined $index_age and -M _ < $index_age
defined $index_age -M _ < $index_age
Truth table0%0/3
A and B
A= defined $index_ageB= -M _ < $index_age
ABresult
0X0
100
111
135  
136 # keep this one
137 0 $index{$msgfile} = $head;
138 }
139  
140 0 $parser->stop;
141  
142 0 $self->{MBMI_index} = \%index;
143 0 $self;
144 }
145  
146 #-------------------------------------------
147  
148  
149 sub get($)
150 0 ▶{ my ($self, $msgfile) = @_;
Subroutine get: not called CC=1 SCAR=6.9
Pod documented
151 0 $self->{MBMI_index}{$msgfile};
152 }
153  
154 #-------------------------------------------
155  
156  
157 9 1;
« Box/Dir.pm ↑ Summary Box/Dir/Message.pm »