RFC2047/Mailbox.pm

filter: Statementstmt 98.2% 57 / 58 Branchbran 85.0% 17 / 20 Conditioncond 53.3% 8 / 15 MC/DCmcdc 10.0% 1 / 10 Subroutinesub 100% 10 / 10 Podpod 100% 5 / 5 totaltotal 83.0% 98 / 118 SCAR 28.0
CC
16
Cov
88%
parse
7.2
format
6.6
new
3.0
CRAP 16.4
« RFC2047/Encoder.pm ↑ Summary RFC2047/Decoder.pm »
1 package Email::MIME::RFC2047::Mailbox;
2 4 $Email::MIME::RFC2047::Mailbox::VERSION = '0.96';
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 # ABSTRACT: Handling of MIME encoded mailboxes
7  
8 4 ▶use base qw(Email::MIME::RFC2047::Address);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 4 ▶use Email::MIME::RFC2047::Decoder;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use Email::MIME::RFC2047::Encoder;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 4 my $domain_part_re = qr/[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?/;
14 4 my $addr_spec_re = qr{
15 [\w&'*+.\/=?^{}~-]+
16 \@
17 $domain_part_re (?: \. $domain_part_re)+
18 }x;
19  
20 sub new {
21 65 ▶ my $class = shift;
Subroutine new: called CC=3 SCAR=11.0
Pod documented
22  
23 65 my $self;
24  
25 65 ▶ if (@_ >= 2) {
Branch: 2 branches
BranchTrueFalseTotal
if (@_ >= 2) { } 35 30 65
elsif (ref $_[0]) { } 16 14 30
26 35 $self = { @_ };
27 }
28 elsif (ref($_[0])) {
29 16 $self = $_[0];
30 }
31 else {
32 14 $self = { address => $_[0] };
33 }
34  
35 65 return bless($self, $class);
36 }
37  
38 sub parse {
39 30 ▶ my ($class, $string, $decoder) = @_;
Subroutine parse: called CC=7 SCAR=19.7
Pod documented
40 30 ▶ my $string_ref = ref($string) ? $string : \$string;
Branch: 1 branch
BranchTrueFalseTotal
ref $string ? : 21 9 30
41  
42 30 my $mailbox;
43  
44 30 ▶ if ($$string_ref =~ /\G\s*($addr_spec_re)\s*/cg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$string_ref =~ /\G\s*($addr_spec_re)\s*/cg) { } 5 25 30
45 5 $mailbox = $class->new($1);
46 }
47 else {
48 25 ▶ $decoder ||= Email::MIME::RFC2047::Decoder->new();
Condition66%2/3
$decoder ||= "Email::MIME::RFC2047::Decoder"->new
l!l&&r!l&&!r
1780
MC/DC0%0/2
$decoder ||= "Email::MIME::RFC2047::Decoder"->new
$decoder "Email::MIME::RFC2047::Decoder"->new
Truth table66%2/3
A ||= B
A= $decoderB= "Email::MIME::RFC2047::Decoder"->new
ABresult
1X1
011
000
49 25 my $name = $decoder->decode_phrase($string_ref);
50  
51 25 ▶ $$string_ref =~ /\G<\s*($addr_spec_re)\s*>\s*/cg
Branch: 1 branch
BranchTrueFalseTotal
$$string_ref =~ /\G<\s*($addr_spec_re)\s*>\s*/cg or return $class->_parse_error($string_ref, "mailbox") 7 18 25
52 or return $class->_parse_error($string_ref, 'mailbox');
53 18 my $addr_spec = $1;
54  
55 18 $mailbox = $class->new(name => $name, address => $addr_spec);
56 }
57  
58 23 ▶ if (!ref($string) && pos($string) < length($string)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $string and pos $string < length $string) 0 23 23
Condition66%2/3
not ref $string and pos $string < length $string
!ll&&!rl&&r
1670
MC/DC0%0/2
not ref $string and pos $string < length $string
not ref $string pos $string < length $string
Truth table66%2/3
not(A) and B
A= not ref $stringB= pos $string < length $string
ABresult
0X0
100
111
59 0 return $class->_parse_error($string_ref);
60 }
61  
62 23 return $mailbox;
63 }
64  
65 sub name {
66 19 ▶ my $self = shift;
Subroutine name: called CC=2 SCAR=6.9
Pod documented
67  
68 19 my $old_name = $self->{name};
69 19 ▶ $self->{name} = $_[0] if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 15 4 19
70  
71 19 return $old_name;
72 }
73  
74 sub address {
75 4 ▶ my $self = shift;
Subroutine address: called CC=2 SCAR=7.0
Pod documented
76  
77 4 my $old_address = $self->{address};
78 4 ▶ $self->{address} = $_[0] if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 4 4
79  
80 4 return $old_address;
81 }
82  
83 sub format {
84 16 ▶ my ($self, $encoder) = @_;
Subroutine format: called CC=6 SCAR=18.8
Pod documented
85  
86 16 my $name = $self->{name};
87 16 my $address = $self->{address};
88 16 ▶ defined($address) && $address =~ /^$addr_spec_re\z/
Branch: 1 branch
BranchTrueFalseTotal
defined $address and $address =~ /^$addr_spec_re\z/ or die "invalid email address" 0 16 16
Condition33%1/3
defined $address and $address =~ /^$addr_spec_re\z/
!ll&&!rl&&r
0016
MC/DC0%0/2
defined $address and $address =~ /^$addr_spec_re\z/
defined $address $address =~ /^$addr_spec_re\z/
Truth table33%1/3
A and B
A= defined $addressB= $address =~ /^$addr_spec_re\z/
ABresult
0X0
100
111
89 or die ("invalid email address");
90  
91 16 my $result;
92  
93 16 ▶ if (!defined($name) || $name eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $name or $name eq '') { } 4 12 16
Condition66%2/3
not defined $name or $name eq ""
l!l&&r!l&&!r
4012
MC/DC50%1/2
not defined $name or $name eq ""
not defined $name $name eq ""
Truth table66%2/3
not(A) or B
A= not defined $nameB= $name eq ""
ABresult
1X1
011
000
94 4 $result = $address;
95 }
96 else {
97 12 ▶ $encoder ||= Email::MIME::RFC2047::Encoder->new();
Condition33%1/3
$encoder ||= "Email::MIME::RFC2047::Encoder"->new
l!l&&r!l&&!r
1200
MC/DC0%0/2
$encoder ||= "Email::MIME::RFC2047::Encoder"->new
$encoder "Email::MIME::RFC2047::Encoder"->new
Truth table33%1/3
A ||= B
A= $encoderB= "Email::MIME::RFC2047::Encoder"->new
ABresult
1X1
011
000
98 12 my $encoded_name = $encoder->encode_phrase($name);
99  
100 12 $result = "$encoded_name <$address>";
101 }
102  
103 16 return $result;
104 }
105  
106 4 1;
107  
108 __END__
« RFC2047/Encoder.pm ↑ Summary RFC2047/Decoder.pm »