| 1 | package Sisimai::Mail::STDIN; | ||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use v5.26; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use IO::Handle; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use Class::Accessor::Lite ( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 3 | 'new' => 0, | |||||||||||||||||||||||||||
| 8 | 'ro' => [ | ||||||||||||||||||||||||||||
| 9 | 'path', # [String] Fixed string "<STDIN>" | ||||||||||||||||||||||||||||
| 10 | 'size', # [Integer] Data size which has been read | ||||||||||||||||||||||||||||
| 11 | ], | ||||||||||||||||||||||||||||
| 12 | 'rw' => [ | ||||||||||||||||||||||||||||
| 13 | 'offset', # [Integer] The number of emails which have been read | ||||||||||||||||||||||||||||
| 14 | 'handle', # [IO::File] File handle | ||||||||||||||||||||||||||||
| 15 | ] | ||||||||||||||||||||||||||||
| 16 | 3 | ); | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 3 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 19 | # Constructor of Sisimai::Mail::STDIN | ||||||||||||||||||||||||||||
| 20 | # @return [Sisimai::Mail::STDIN] Object | ||||||||||||||||||||||||||||
| 21 | 3 | my $class = shift; | |||||||||||||||||||||||||||
| 22 | 3 | my $param = { | |||||||||||||||||||||||||||
| 23 | 'path' => '<STDIN>', | ||||||||||||||||||||||||||||
| 24 | 'size' => 0, | ||||||||||||||||||||||||||||
| 25 | 'offset' => 0, | ||||||||||||||||||||||||||||
| 26 | 'handle' => IO::Handle->new->fdopen(fileno(STDIN), 'r'), | ||||||||||||||||||||||||||||
| 27 | }; | ||||||||||||||||||||||||||||
| 28 | 3 | return bless($param, __PACKAGE__); | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 1 | ▶ | sub read { | ||||||||||||||||||||||||||
|
Subroutine
read: called CC=6 SCAR=21.9
Pod
documented
| |||||||||||||||||||||||||||||
| 32 | # Mbox reader, works as an iterator. | ||||||||||||||||||||||||||||
| 33 | # @return [String] Contents of mbox | ||||||||||||||||||||||||||||
| 34 | 1 | ▶ | my $self = shift; return "" unless -T $self->{'handle'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | 1 | my $readhandle = $self->{'handle'}; | |||||||||||||||||||||||||||
| 36 | 1 | my $readbuffer = ''; | |||||||||||||||||||||||||||
| 37 | 1 | eval { | |||||||||||||||||||||||||||
| 38 | 1 | ▶ | $readhandle = $self->{'handle'}->fdopen(fileno(STDIN), 'r') unless eof $readhandle; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 1 | ▶ | while( my $r = <$readhandle> ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | # Read an email from the mailbox file | ||||||||||||||||||||||||||||
| 42 | 0 | ▶ | last if( $readbuffer && substr($r, 0, 5) eq 'From ' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$readbuffer and substr($r, 0, 5) eq "From "
MC/DC0%0/2
$readbuffer and substr($r, 0, 5) eq "From "
$readbuffer
substr($r, 0, 5) eq "From "
Truth table0%0/3
A and B
A= $readbufferB= substr($r, 0, 5) eq "From "
| |||||||||||||||||||||||||||||
| 43 | 0 | $readbuffer .= $r; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | }; | ||||||||||||||||||||||||||||
| 46 | 1 | $self->{'size'} += length $readbuffer; | |||||||||||||||||||||||||||
| 47 | 1 | $self->{'offset'} += 1; | |||||||||||||||||||||||||||
| 48 | 1 | return $readbuffer; | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 3 | 1; | |||||||||||||||||||||||||||
| 52 | __END__ | ||||||||||||||||||||||||||||