File Coverage

blib/lib/Email/MIME/RFC2047/Group.pm
Criterion Covered Total %
statement 38 38 100.0
branch 6 10 60.0
condition 2 6 33.3
subroutine 9 9 100.0
pod 4 4 100.0
total 59 67 88.0


line stmt bran cond sub pod time code
1             package Email::MIME::RFC2047::Group;
2             $Email::MIME::RFC2047::Group::VERSION = '0.97';
3 4     4   24 use strict;
  4         9  
  4         113  
4 4     4   24 use warnings;
  4         5  
  4         114  
5              
6             # ABSTRACT: MIME encoded mailbox groups
7              
8 4     4   30 use base qw(Email::MIME::RFC2047::Address);
  4         8  
  4         350  
9              
10 4     4   31 use Email::MIME::RFC2047::Decoder;
  4         7  
  4         81  
11 4     4   782 use Email::MIME::RFC2047::MailboxList;
  4         13  
  4         1124  
12              
13             sub new {
14 9     9 1 43 my $class = shift;
15              
16 9         18 my $self;
17              
18 9 100       28 if (@_ >= 2) {
19 7         23 $self = { @_ };
20             }
21             else {
22 2         6 $self = $_[0];
23             }
24              
25 9         31 return bless($self, $class);
26             }
27              
28             #sub _parse {
29             # my ($class, $string, $decoder) = @_;
30             # my $string_ref = ref($string) ? $string : \$string;
31             #
32             # $decoder ||= Email::MIME::RFC2047::Decoder->new();
33             #
34             # my $name = $decoder->decode_phrase($string_ref);
35             # return $class->_parse_error($string_ref, 'group name')
36             # if $name eq '';
37             #
38             # $$string_ref =~ /\G:/cg
39             # or return $class->_parse_error($string_ref, 'group');
40             #
41             # my $mailbox_list;
42             #
43             # if ($$string_ref =~ /\G\s*;\s*/cg) {
44             # $mailbox_list = Email::MIME::RFC2047::MailboxList->new();
45             # }
46             # else {
47             # $mailbox_list = Email::MIME::RFC2047::MailboxList->parse(
48             # $string_ref, $decoder
49             # );
50             #
51             # $$string_ref =~ /\G;\s*/cg
52             # or return $class->_parse_error($string_ref, 'group');
53             # }
54             #
55             # my $group = $class->new(
56             # name => $name,
57             # mailbox_list => $mailbox_list,
58             # );
59             #
60             # if (!ref($string) && pos($string) < length($string)) {
61             # return $class->_parse_error($string_ref);
62             # }
63             #
64             # return $group;
65             #}
66              
67             sub name {
68 2     2 1 12 my $self = shift;
69              
70 2         21 my $old_name = $self->{name};
71 2 50       10 $self->{name} = $_[0] if @_;
72              
73 2         17 return $old_name;
74             }
75              
76             sub mailbox_list {
77 2     2 1 5 my $self = shift;
78              
79 2         7 my $old_mailbox_list = $self->{mailbox_list};
80 2 50       8 $self->{mailbox_list} = $_[0] if @_;
81              
82 2         16 return $old_mailbox_list;
83             }
84              
85             sub format {
86 3     3 1 18 my ($self, $encoder) = @_;
87 3   33     14 $encoder ||= Email::MIME::RFC2047::Encoder->new();
88              
89 3         9 my $name = $self->{name};
90 3 50 33     28 die("empty group name") if !defined($name) || $name eq '';
91              
92 3         14 my $result = $encoder->encode_phrase($name) . ': ';
93              
94 3         9 my $mailbox_list = $self->{mailbox_list};
95 3 50       36 $result .= $mailbox_list->format($encoder) if $mailbox_list;
96              
97 3         11 $result .= ';';
98              
99 3         11 return $result;
100             }
101              
102             1;
103              
104             __END__