File Coverage

lib/Sisimai/Mail/Memory.pm
Criterion Covered Total %
statement 25 25 100.0
branch 6 6 100.0
condition 5 6 83.3
subroutine 6 6 100.0
pod 2 2 100.0
total 44 45 97.7


line stmt bran cond sub pod time code
1             package Sisimai::Mail::Memory;
2 4     4   151291 use v5.26;
  4         19  
3 4     4   45 use strict;
  4         8  
  4         156  
4 4     4   41 use warnings;
  4         11  
  4         424  
5             use Class::Accessor::Lite (
6 4         44 'new' => 0,
7             'ro' => [
8             'path', # [String] Fixed string ""
9             'size', # [Integer] data size
10             ],
11             'rw' => [
12             'payload', # [Array] entire bounce mail message
13             'offset', # [Integer] Index of "data"
14             ]
15 4     4   643 );
  4         1738  
16              
17             sub new {
18             # Constructor of Sisimai::Mail::Memory
19             # @param [String] argv1 Entire email string
20             # @return [Sisimai::Mail::Memory] Object
21             # [Undef] is not a valid email text
22 7     7 1 420459 my $class = shift;
23 7   100     33 my $argv1 = shift // return undef;
24 6   100     50 my $param = {
25             'payload' => [],
26             'path' => '',
27             'size' => length $$argv1 || 0,
28             'offset' => 0,
29             };
30 6 100       32 return undef unless $param->{'size'};
31              
32 5 100 50     37 if( (substr($$argv1, 0, 5) || '') eq 'From ') {
33             # UNIX mbox
34 3         606 $param->{'payload'} = [split(/^From /m, $$argv1)];
35 3         19 shift $param->{'payload'}->@*;
36 3         1464 $_ = 'From '.$_ for $param->{'payload'}->@*;
37             } else {
38 2         10 $param->{'payload'} = [$$argv1];
39             }
40 5         55 return bless($param, __PACKAGE__);
41             }
42              
43             sub read {
44             # Memory reader, works as an iterator.
45             # @return [String] Contents of a bounce mail
46 42 100   42 1 94411 my $self = shift; return "" unless scalar $self->{'payload'}->@*;
  42         166  
47              
48 39         77 $self->{'offset'} += 1;
49 39         167 return shift $self->{'payload'}->@*;
50             }
51              
52             1;
53             __END__