File Coverage

lib/Sisimai/Mail.pm
Criterion Covered Total %
statement 37 40 92.5
branch 8 12 66.6
condition 2 3 66.6
subroutine 5 6 83.3
pod 2 2 100.0
total 54 63 85.7


line stmt bran cond sub pod time code
1             package Sisimai::Mail;
2 78     78   209146 use feature ':5.10';
  78         143  
  78         7331  
3 78     78   447 use strict;
  78         109  
  78         1301  
4 78     78   286 use warnings;
  78         113  
  78         2891  
5             use Class::Accessor::Lite (
6 78         515 'new' => 0,
7             'ro' => [
8             'path', # [String] path to mbox or Maildir/
9             'kind', # [String] Data type: mailbox, maildir, stdin, or memory
10             ],
11             'rw' => [
12             'data', # [Sisimai::Mail::[Mbox,Maildir,Memory,STDIO] Object
13             ]
14 78     78   28245 );
  78         73421  
15              
16             sub new {
17             # Constructor of Sisimai::Mail
18             # @param [String] argv1 Path to mbox or Maildir/
19             # @return [Sisimai::Mail] Object
20             # [Undef] The argument is wrong
21 560     560 1 413245 my $class = shift;
22 560         956 my $argv1 = shift;
23 560         820 my $klass = undef;
24 560         941 my $loads = 'Sisimai/Mail/';
25 560         2006 my $param = { 'kind' => '', 'data' => undef, 'path' => $argv1 };
26              
27             # The argumenet is a mailbox or a Maildir/.
28 560 100       8334 if( -f $argv1 ) {
    100          
29             # The argument is a file, it is an mbox or email file in Maildir/
30 547         1561 $klass = __PACKAGE__.'::Mbox';
31 547         1046 $loads .= 'Mbox.pm';
32 547         1159 $param->{'kind'} = 'mailbox';
33 547         941 $param->{'path'} = $argv1;
34              
35             } elsif( -d $argv1 ) {
36             # The agument is not a file, it is a Maildir/
37 9         31 $klass = __PACKAGE__.'::Maildir';
38 9         21 $loads .= 'Maildir.pm';
39 9         22 $param->{'kind'} = 'maildir';
40              
41             } else {
42             # The argumen1 neither a mailbox nor a Maildir/.
43 4 100 66     38 if( ref($argv1) eq 'GLOB' || $argv1 eq 'STDIN' ) {
    50          
44             # Read from STDIN
45 1         2 $klass = __PACKAGE__.'::STDIN';
46 1         2 $loads .= 'STDIN.pm';
47 1         2 $param->{'kind'} = 'stdin';
48              
49             } elsif( ref($argv1) eq 'SCALAR' ) {
50             # Read from a variable as a scalar reference
51 3         7 $klass = __PACKAGE__.'::Memory';
52 3         7 $loads .= 'Memory.pm';
53 3         7 $param->{'kind'} = 'memory';
54 3         5 $param->{'path'} = 'MEMORY';
55             }
56             }
57 560 50       1345 return undef unless $klass;
58              
59 560         33545 require $loads;
60 560         2961 $param->{'data'} = $klass->new($argv1);
61              
62 560         2193 return bless($param, __PACKAGE__);
63             }
64              
65             sub read {
66             # Alias method of Sisimai::Mail::*->read()
67             # @return [String] Contents of mbox/Maildir
68 0     0 1   my $self = shift;
69 0 0         return undef unless ref $self->{'data'};
70 0           return $self->{'data'}->read;
71             }
72              
73             1;
74             __END__