| 1 | package Sisimai::Mail::Mbox; | ||||||||||||||||||||||||||||
| 2 | 88 | ▶ | use v5.26; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 88 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 88 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 88 | ▶ | use File::Basename qw(basename dirname); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 88 | ▶ | use IO::File; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 88 | ▶ | use Class::Accessor::Lite ( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 88 | 'new' => 0, | |||||||||||||||||||||||||||
| 9 | 'ro' => [ | ||||||||||||||||||||||||||||
| 10 | 'dir', # [String] Directory name of the mbox | ||||||||||||||||||||||||||||
| 11 | 'file', # [String] File name of the mbox | ||||||||||||||||||||||||||||
| 12 | 'path', # [String] Path to mbox | ||||||||||||||||||||||||||||
| 13 | 'size', # [Integer] File size of the mbox | ||||||||||||||||||||||||||||
| 14 | ], | ||||||||||||||||||||||||||||
| 15 | 'rw' => [ | ||||||||||||||||||||||||||||
| 16 | 'offset', # [Integer] Offset position for seeking | ||||||||||||||||||||||||||||
| 17 | 'handle', # [IO::File] File handle | ||||||||||||||||||||||||||||
| 18 | ] | ||||||||||||||||||||||||||||
| 19 | 88 | ); | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 746 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 22 | # Constructor of Sisimai::Mail::Mbox | ||||||||||||||||||||||||||||
| 23 | # @param [String] argv1 Path to mbox | ||||||||||||||||||||||||||||
| 24 | # @return [Sisimai::Mail::Mbox] Object | ||||||||||||||||||||||||||||
| 25 | # [Undef] is not a file or does not exist | ||||||||||||||||||||||||||||
| 26 | 746 | my $class = shift; | |||||||||||||||||||||||||||
| 27 | 746 | ▶ | my $argv1 = shift // return undef; return undef unless -f $argv1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
shift() // (return undef)
MC/DC100%1/1
shift() // (return undef)
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 28 | 745 | my $param = {'offset' => 0}; | |||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 745 | $param->{'dir'} = File::Basename::dirname $argv1; | |||||||||||||||||||||||||||
| 31 | 745 | $param->{'path'} = $argv1; | |||||||||||||||||||||||||||
| 32 | 745 | $param->{'size'} = -s $argv1; | |||||||||||||||||||||||||||
| 33 | 745 | $param->{'file'} = File::Basename::basename $argv1; | |||||||||||||||||||||||||||
| 34 | 745 | ▶ | $param->{'handle'} = ref $argv1 ? $argv1 : IO::File->new($argv1, 'r'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | 745 | binmode $param->{'handle'}; | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 745 | return bless($param, __PACKAGE__); | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 1747 | ▶ | sub read { | ||||||||||||||||||||||||||
|
Subroutine
read: called CC=12 SCAR=25.2
Pod
documented
| |||||||||||||||||||||||||||||
| 41 | # Mbox reader, works as an iterator. | ||||||||||||||||||||||||||||
| 42 | # @return [String] Contents of mbox | ||||||||||||||||||||||||||||
| 43 | 1747 | ▶ | my $self = shift; return "" unless defined $self->{'path'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | 1747 | ▶ | my $seekoffset = $self->{'offset'} // 0; | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->{"offset"} // 0
MC/DC0%0/1
$self->{"offset"} // 0
$self->{"offset"}
Truth table50%1/2
A
A= $self->{"offset"}
| |||||||||||||||||||||||||||||
| 45 | 1747 | my $filehandle = $self->{'handle'}; | |||||||||||||||||||||||||||
| 46 | 1747 | my $readbuffer = ''; | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 1747 | ▶ | unless( ref $self->{'path'} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | # "path" is not IO::File object | ||||||||||||||||||||||||||||
| 50 | 1747 | ▶ | return "" unless -f $self->{'path'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 1747 | ▶ | return "" unless -T $self->{'path'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | 1747 | ▶ | return "" unless $self->{'offset'} < $self->{'size'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 1004 | eval { | |||||||||||||||||||||||||||
| 56 | 1004 | ▶ | $seekoffset = 0 if $seekoffset < 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | 1004 | seek($filehandle, $seekoffset, 0); | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 1004 | ▶ | while( my $r = <$filehandle> ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | # Read the UNIX mbox file from 'From ' to the next 'From ' | ||||||||||||||||||||||||||||
| 61 | 113847 | ▶ | last if( $readbuffer && substr($r, 0, 5) eq 'From ' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$readbuffer and substr($r, 0, 5) eq "From "
MC/DC100%2/2
$readbuffer and substr($r, 0, 5) eq "From "
$readbuffer
substr($r, 0, 5) eq "From "
Truth table100%3/3
A and B
A= $readbufferB= substr($r, 0, 5) eq "From "
| |||||||||||||||||||||||||||||
| 62 | 113587 | $readbuffer .= $r; | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | 1004 | $seekoffset += length $readbuffer; | |||||||||||||||||||||||||||
| 65 | 1004 | $self->{'offset'} = $seekoffset; | |||||||||||||||||||||||||||
| 66 | 1004 | ▶ | $filehandle->close unless $seekoffset < $self->{'size'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | }; | ||||||||||||||||||||||||||||
| 68 | 1004 | return $readbuffer; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 88 | 1; | |||||||||||||||||||||||||||
| 72 | __END__ | ||||||||||||||||||||||||||||