Sisimai/Mail/Maildir.pm

filter: Statementstmt 100% 61 / 61 Branchbran 67.8% 19 / 28 Conditioncond 85.7% 6 / 7 MC/DCmcdc 75.0% 3 / 4 Subroutinesub 100% 9 / 9 Podpod 100% 2 / 2 totaltotal 90.0% 100 / 111 CC 18 SCAR 22.2
CC
18
Cov
90%
read
14.9
new
5.0
BEGIN
1.0
CRAP 9.2
« Sisimai/Reason/Rejected.pm ↑ Summary Sisimai/Rhost.pm »
1 package Sisimai::Mail::Maildir;
2 7 ▶use v5.26;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 7 ▶use IO::Dir;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 7 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 7 ▶use Sisimai::Eb;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 7 ▶use Class::Accessor::Lite (
Subroutine BEGIN: called CC=1 SCAR=0.0
9 7 'new' => 0,
10 'ro' => [
11 'dir', # [String] Path to Maildir/
12 ],
13 'rw' => [
14 'path', # [String] Path to each file
15 'file', # [String] Each file name of a mail in the Maildir/
16 'size', # [Integer] The number of email files in the Maildir/
17 'offset', # [Integer] The number of email files which have been read
18 'handle', # [IO::Dir] Directory handle
19 ]
20 7 );
21  
22 11 ▶sub new {
Subroutine new: called CC=5 SCAR=16.1
Pod documented
23 # Constructor of Sisimai::Mail::Maildir
24 # @param [String] argv1 Path to Maildir/
25 # @return [Sisimai::Mail::Maildir] Object
26 # [Undef] is not a directory or does not exist
27 11 my $class = shift;
28 11 ▶ my $argv1 = shift // return undef; return undef unless -d $argv1;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $argv1 0 10 10
Condition100%2/2
shift() // (return undef)
l!l
101
MC/DC100%1/1
shift() // (return undef)
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
29 10 my $files = 0;
30  
31 10 eval {
32 # Count the number of files in the Maildir/
33 10 opendir MAILDIR, $argv1;
34 10 ▶ while( my $e = readdir MAILDIR ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $e = readdir MAILDIR)) 3918 10 3928
35 3918 ▶ next unless -f sprintf("%s/%s", $argv1, $e);
Branch: 1 branch
BranchTrueFalseTotal
unless -f sprintf('%s/%s', $argv1, $e) 20 3898 3918
36 3898 $files += 1;
37 }
38 10 closedir MAILDIR;
39 };
40  
41 10 my $param = {
42 'dir' => $argv1,
43 'file' => undef,
44 'path' => undef,
45 'size' => $files,
46 'offset' => 0,
47 'handle' => IO::Dir->new($argv1),
48 };
49 10 return bless($param, __PACKAGE__);
50 }
51  
52 3275 ▶sub read {
Subroutine read: called CC=14 SCAR=27.0
Pod documented
53 # Maildir reader, works as an iterator.
54 # @return [String] Contents of file in Maildir/
55 3275 my $self = shift;
56 3275 ▶ return "" unless defined $self->{'dir'};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"dir"} 0 3275 3275
57 3275 ▶ return "" unless -d $self->{'dir'};
Branch: 1 branch
BranchTrueFalseTotal
unless -d $self->{"dir"} 0 3275 3275
58 3275 ▶ return "" unless $self->{'offset'} < $self->{'size'};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"offset"} < $self->{"size"} 9 3266 3275
59  
60 3266 my $seekhandle = $self->{'handle'};
61 3266 my $readbuffer = '';
62  
63 3266 eval {
64 3266 ▶ $seekhandle = IO::Dir->new($self->{'dir'}) unless $seekhandle;
Branch: 1 branch
BranchTrueFalseTotal
unless $seekhandle 0 3266 3266
65 3266 ▶ while( my $r = $seekhandle->read ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $r = $seekhandle->read) 3284 0 3284
66 # Read each file in the directory
67 3284 ▶ next if( $r eq '.' || $r eq '..' );
Branch: 1 branch
BranchTrueFalseTotal
if $r eq "." or $r eq ".." 18 3266 3284
Condition100%3/3
$r eq "." or $r eq ".."
l!l&&r!l&&!r
993266
MC/DC100%2/2
$r eq "." or $r eq ".."
$r eq "." $r eq ".."
Truth table100%3/3
A or B
A= $r eq "."B= $r eq ".."
ABresult
1X1
011
000
68  
69 3266 my $emailindir = $self->{'dir'}.'/'.$r; $emailindir =~ y{/}{}s;
70 3266 ▶ my $emailbytes = -s $emailindir // 0;
Condition50%1/2
-s $emailindir // 0
l!l
32660
MC/DC0%0/1
-s $emailindir // 0
-s $emailindir
Truth table50%1/2
A
A= -s $emailindir
Aresult
11
00
71 3266 $self->{'offset'} += 1;
72 3266 ▶ next unless -f $emailindir;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $emailindir 0 3266 3266
73 3266 ▶ next unless -r $emailindir;
Branch: 1 branch
BranchTrueFalseTotal
unless -r $emailindir 0 3266 3266
74 3266 ▶ next unless $emailbytes;
Branch: 1 branch
BranchTrueFalseTotal
unless $emailbytes 0 3266 3266
75 3266 ▶ next unless $emailbytes < $Sisimai::Eb::XeBYTE;
Branch: 1 branch
BranchTrueFalseTotal
unless $emailbytes < $Sisimai::Eb::XeBYTE 0 3266 3266
76  
77 3266 $self->{'path'} = $emailindir;
78 3266 $self->{'file'} = $r;
79 3266 my $filehandle = IO::File->new($emailindir, 'r');
80 3266 $readbuffer = do { local $/; <$filehandle> };
81 3266 $filehandle->close;
82 3266 last;
83 }
84 3266 ▶ $seekhandle->close unless $self->{'offset'} < $self->{'size'};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"offset"} < $self->{"size"} 9 3257 3266
85 };
86 3266 return $readbuffer;
87 }
88  
89 7 1;
90 __END__
« Sisimai/Reason/Rejected.pm ↑ Summary Sisimai/Rhost.pm »