File Coverage

blib/lib/Email/MIME/RFC2047/AddressList.pm
Criterion Covered Total %
statement 38 39 97.4
branch 3 4 75.0
condition 5 9 55.5
subroutine 11 11 100.0
pod 5 5 100.0
total 62 68 91.1


line stmt bran cond sub pod time code
1             package Email::MIME::RFC2047::AddressList;
2             $Email::MIME::RFC2047::AddressList::VERSION = '0.96';
3 4     4   66095 use strict;
  4         12  
  4         158  
4 4     4   31 use warnings;
  4         11  
  4         165  
5              
6             # ABSTRACT: Handling of MIME encoded address lists
7              
8 4     4   30 use base qw(Email::MIME::RFC2047::Parser);
  4         17  
  4         1073  
9              
10 4     4   806 use Email::MIME::RFC2047::Decoder;
  4         16  
  4         180  
11 4     4   1118 use Email::MIME::RFC2047::Address;
  4         11  
  4         2235  
12              
13             sub new {
14 22     22 1 94 my $class = shift;
15              
16 22         61 my $self = [ @_ ];
17              
18 22         105 return bless($self, $class);
19             }
20              
21             sub parse {
22 20     20 1 13229 my ($class, $string, $decoder) = @_;
23 20 100       79 my $string_ref = ref($string) ? $string : \$string;
24 20   66     150 $decoder ||= Email::MIME::RFC2047::Decoder->new();
25              
26 20         39 my @addresses;
27              
28 20         43 do {
29 40         141 my $address = $class->_parse_item($string_ref, $decoder);
30 33         157 push(@addresses, $address);
31             } while ($$string_ref =~ /\G,/cg);
32              
33 13 50 66     75 if (!ref($string) && pos($string) < length($string)) {
34 0         0 return $class->_parse_error($string_ref);
35             }
36              
37 13         65 return $class->new(@addresses);
38             }
39              
40             sub _parse_item {
41 19     19   53 my ($class, $string_ref, $decoder) = @_;
42              
43 19         77 return Email::MIME::RFC2047::Address->parse(
44             $string_ref, $decoder
45             );
46             }
47              
48             sub items {
49 5     5 1 31 my $self = shift;
50              
51 5         49 return @$self;
52             }
53              
54             sub push {
55 13     13 1 78 my $self = shift;
56              
57 13         30 push(@$self, @_);
58              
59 13         32 return;
60             }
61              
62             sub format {
63 7     7 1 46 my ($self, $encoder) = @_;
64 7   33     49 $encoder ||= Email::MIME::RFC2047::Encoder->new();
65              
66 7         28 return join(', ', map { $_->format($encoder) } @$self);
  13         55  
67             }
68              
69             1;
70              
71             __END__