Message/Field/Address.pm

filter: Statementstmt 98.1% 53 / 54 Branchbran 81.2% 13 / 16 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 93.3% 14 / 15 Podpod 80.0% 4 / 5 totaltotal 88.4% 84 / 95 CC 10 SCAR 11.2
CC
10
Cov
90%
coerce
6.9
string
4.0
parse
2.0
CRAP 3.1
« Message/Head.pm ↑ Summary Message/Convert/MailInternet.pm »
1 # This code is part of Perl distribution Mail-Message version 4.05.
2 # The POD got stripped from this file by OODoc version 3.06.
3 # For contributors see file ChangeLog.
4  
5 # This software is copyright (c) 2001-2026 by Mark Overmeer.
6  
7 # This is free software; you can redistribute it and/or modify it under
8 # the same terms as the Perl 5 programming language system itself.
9 # SPDX-License-Identifier: Artistic-1.0-Perl OR GPL-1.0-or-later
10  
11  
12 package Mail::Message::Field::Address;{
13 28 our $VERSION = '4.05';
14 }
15  
16 28 ▶use parent 'Mail::Identity';
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 28 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 28 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 28 ▶use Log::Report 'mail-message', import => [ qw/__x error/ ];
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 28 ▶use Mail::Message::Field::Addresses ();
Subroutine BEGIN: called CC=1 SCAR=0.0
24 28 ▶use Mail::Message::Field::Full ();
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 28 ▶use Scalar::Util qw/blessed/;
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 28 my $format = 'Mail::Message::Field::Full';
29  
30 #--------------------
31  
32 use overload
33 28 ▶ '""' => 'string',
Subroutine BEGIN: called CC=1 SCAR=0.1
34 64 ▶ bool => sub {1},
Subroutine __ANON__: called CC=1 SCAR=0.0
35 0 ▶ cmp => sub { lc($_[0]->address) cmp lc($_[1]) };
Subroutine __ANON__: not called CC=1 SCAR=0.2
36  
37 #--------------------
38  
39 sub coerce($@)
40 53 ▶{ my ($class, $addr, %args) = @_;
Subroutine coerce: called CC=6 SCAR=19.3
Pod documented
41 53 ▶ defined $addr or return ();
Branch: 1 branch
BranchTrueFalseTotal
defined $addr or return () 53 0 53
42 53 ▶ blessed $addr or return $class->parse($addr);
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($addr) or return $class->parse($addr) 51 2 53
43 51 ▶ $addr->isa($class) and return $addr;
Branch: 1 branch
BranchTrueFalseTotal
$addr->isa($class) and return $addr 47 4 51
44  
45 4 ▶ my $from = $class->from($addr, %args)
Branch: 1 branch
BranchTrueFalseTotal
my $from = $class->from($addr, %args) or &error(&__x("cannot coerce a {type} into a {class}.", "type", ref $addr // $addr, "class", $class)) 4 0 4
Condition0%0/3
ref $addr // $addr
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $addr // $addr
ref $addr $addr
Truth table0%0/3
A // B
A= ref $addrB= $addr
ABresult
1X1
011
000
46 or error __x"cannot coerce a {type} into a {class}.", type => ref $addr // $addr, class => $class;
47  
48 4 bless $from, $class;
49 }
50  
51 sub init($)
52 50 ▶{ my ($self, $args) = @_;
Subroutine init: called CC=1 SCAR=0.0
Pod undocumented
53 50 $self->SUPER::init($args);
54 50 $self->{MMFA_encoding} = delete $args->{encoding};
55 50 $self;
56 }
57  
58  
59 sub parse($)
60 5 ▶{ my $self = shift;
Subroutine parse: called CC=2 SCAR=7.1
Pod documented
61 5 my $parsed = Mail::Message::Field::Addresses->new(To => shift);
62 5 ▶ defined $parsed ? ($parsed->addresses)[0] : ();
Branch: 1 branch
BranchTrueFalseTotal
defined $parsed ? : 5 0 5
63 }
64  
65 #--------------------
66  
67 62 ▶sub encoding() { $_[0]->{MMFA_encoding} }
Subroutine encoding: called CC=1 SCAR=0.0
Pod documented
68  
69 #--------------------
70  
71 sub string()
72 62 ▶{ my $self = shift;
Subroutine string: called CC=4 SCAR=13.9
Pod documented
73 62 my @opts = (charset => $self->charset, encoding => $self->encoding);
74 # language => $self->language
75  
76 62 my @parts;
77 62 my $phrase = $self->phrase;
78 62 ▶ push @parts, $format->createPhrase($phrase, @opts) if defined $phrase;
Branch: 1 branch
BranchTrueFalseTotal
if defined $phrase 36 26 62
79  
80 62 my $address = $self->address;
81 62 ▶ push @parts, @parts ? '<'.$address.'>' : $address;
Branch: 1 branch
BranchTrueFalseTotal
@parts ? : 36 26 62
82  
83 62 my $comment = $self->comment;
84 62 ▶ push @parts, $format->createComment($comment, @opts) if defined $comment;
Branch: 1 branch
BranchTrueFalseTotal
if defined $comment 9 53 62
85  
86 62 join ' ', @parts;
87 }
88  
89 28 1;
« Message/Head.pm ↑ Summary Message/Convert/MailInternet.pm »