File Coverage

blib/lib/Email/Abstract/MailInternet.pm
Criterion Covered Total %
statement 9 35 25.7
branch 1 10 10.0
condition n/a
subroutine 4 11 36.3
pod 1 8 12.5
total 15 64 23.4


line stmt bran cond sub pod time code
1 3     3   1821 use strict;
  3         8  
  3         148  
2             package Email::Abstract::MailInternet;
3             # ABSTRACT: Email::Abstract wrapper for Mail::Internet
4             $Email::Abstract::MailInternet::VERSION = '3.010';
5 3     3   16 use Email::Abstract::Plugin;
  3         7  
  3         97  
6 3     3   1641 BEGIN { @Email::Abstract::MailInternet::ISA = 'Email::Abstract::Plugin' };
7              
8 0     0 0 0 sub target { "Mail::Internet" }
9              
10             # We need 1.77 because otherwise headers unfold badly.
11             my $is_avail;
12             sub is_available {
13 3 50   3 1 13 return $is_avail if defined $is_avail;
14 3         468 require Mail::Internet;
15 0           eval { Mail::Internet->VERSION(1.77) };
  0            
16 0 0         return $is_avail = $@ ? 0 : 1;
17             }
18              
19             sub construct {
20 0     0 0   require Mail::Internet;
21 0           my ($class, $rfc822) = @_;
22 0           Mail::Internet->new([ map { "$_\x0d\x0a" } split /\x0d\x0a/, $rfc822]);
  0            
23             }
24              
25             sub get_header {
26 0     0 0   my ($class, $obj, $header) = @_;
27 0           my @values = $obj->head->get($header);
28 0 0         return unless @values;
29              
30             # No reason to s/// lots of values if we're just going to return one.
31 0 0         $#values = 0 if not wantarray;
32              
33 0           chomp @values;
34 0           s/(?:\x0d\x0a|\x0a\x0d|\x0a|\x0d)\s+/ /g for @values;
35              
36 0 0         return wantarray ? @values : $values[0];
37             }
38              
39             sub get_body {
40 0     0 0   my ($class, $obj) = @_;
41 0           join "", @{$obj->body()};
  0            
42             }
43              
44             sub set_header {
45 0     0 0   my ($class, $obj, $header, @data) = @_;
46 0           my $count = 0;
47 0           $obj->head->replace($header, shift @data, ++$count) while @data;
48             }
49              
50             sub set_body {
51 0     0 0   my ($class, $obj, $body) = @_;
52 0           $obj->body( map { "$_\n" } split /\n/, $body );
  0            
53             }
54              
55 0     0 0   sub as_string { my ($class, $obj) = @_; $obj->as_string(); }
  0            
56              
57             1;
58              
59             #pod =head1 DESCRIPTION
60             #pod
61             #pod This module wraps the Mail::Internet mail handling library with an
62             #pod abstract interface, to be used with L
63             #pod
64             #pod =head1 SEE ALSO
65             #pod
66             #pod L, L.
67             #pod
68             #pod =cut
69              
70             __END__