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.97';
3 4     4   66470 use strict;
  4         9  
  4         110  
4 4     4   20 use warnings;
  4         8  
  4         113  
5              
6             # ABSTRACT: MIME encoded address lists
7              
8 4     4   20 use base qw(Email::MIME::RFC2047::Parser);
  4         11  
  4         1099  
9              
10 4     4   663 use Email::MIME::RFC2047::Decoder;
  4         12  
  4         139  
11 4     4   1048 use Email::MIME::RFC2047::Address;
  4         10  
  4         1499  
12              
13             sub new {
14 22     22 1 71 my $class = shift;
15              
16 22         51 my $self = [ @_ ];
17              
18 22         92 return bless($self, $class);
19             }
20              
21             sub parse {
22 20     20 1 11005 my ($class, $string, $decoder) = @_;
23 20 100       66 my $string_ref = ref($string) ? $string : \$string;
24 20   66     138 $decoder ||= Email::MIME::RFC2047::Decoder->new();
25              
26 20         40 my @addresses;
27              
28 20         37 do {
29 40         131 my $address = $class->_parse_item($string_ref, $decoder);
30 33         501 push(@addresses, $address);
31             } while ($$string_ref =~ /\G,/cg);
32              
33 13 50 66     61 if (!ref($string) && pos($string) < length($string)) {
34 0         0 return $class->_parse_error($string_ref);
35             }
36              
37 13         60 return $class->new(@addresses);
38             }
39              
40             sub _parse_item {
41 19     19   33 my ($class, $string_ref, $decoder) = @_;
42              
43 19         50 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         44 return @$self;
52             }
53              
54             sub push {
55 13     13 1 53 my $self = shift;
56              
57 13         25 push(@$self, @_);
58              
59 13         23 return;
60             }
61              
62             sub format {
63 7     7 1 33 my ($self, $encoder) = @_;
64 7   33     27 $encoder ||= Email::MIME::RFC2047::Encoder->new();
65              
66 7         20 return join(', ', map { $_->format($encoder) } @$self);
  13         43  
67             }
68              
69             1;
70              
71             __END__