Mail/Field/AddrList.pm untested

filter: Statementstmt 0.0% 0 / 45 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 7 totaltotal 0.0% 0 / 63 CC 1 SCAR 6.9
CC
1
Cov
0%
create
2.0
parse
2.0
stringify
2.0
CRAP 2.0
1 # Copyrights 1995-2024 by [Mark Overmeer <markov@cpan.org>].
2 # For other contributors see ChangeLog.
3 # See the manual pages for details on the licensing terms.
4 # Pod stripped from pm file by OODoc 2.03.
5 # This code is part of the bundle MailTools. Meta-POD processed with
6 # OODoc into POD and HTML manual-pages. See README.md for Copyright.
7 # Licensed under the same terms as Perl itself.
8  
9 use strict;
10  
11 package Mail::Field::AddrList;{
12 our $VERSION = '2.22';
13 }
14  
15 use base 'Mail::Field';
16  
17 use Carp;
18 use Mail::Address;
19  
20  
21 my $x = bless [];
22 $x->register('To');
23 $x->register('From');
24 $x->register('Cc');
25 $x->register('Reply-To');
26 $x->register('Sender');
27  
28 sub create(@)
29 { my ($self, %arg) = @_;
30 $self->{AddrList} = {};
31  
32 while(my ($e, $n) = each %arg)
33 { $self->{AddrList}{$e} = Mail::Address->new($n, $e);
34 }
35  
36 $self;
37 }
38  
39 sub parse($)
40 { my ($self, $string) = @_;
41 foreach my $a (Mail::Address->parse($string))
42 { my $e = $a->address;
43 $self->{AddrList}{$e} = $a;
44 }
45 $self;
46 }
47  
48 sub stringify()
49 { my $self = shift;
50 join(", ", map { $_->format } values %{$self->{AddrList}});
51 }
52  
53  
54 sub addresses { keys %{shift->{AddrList}} }
55  
56  
57 # someone forgot to implement a method to return the Mail::Address
58 # objects. Added in 2.00; a pity that the name addresses() is already
59 # given :( That one should have been named emails()
60 sub addr_list { values %{shift->{AddrList}} }
61  
62  
63 sub names { map { $_->name } values %{shift->{AddrList}} }
64  
65  
66 sub set_address($$)
67 { my ($self, $email, $name) = @_;
68 $self->{AddrList}{$email} = Mail::Address->new($name, $email);
69 $self;
70 }
71  
72 1;