Mail/Identity.pm

filter: Statementstmt 30.6% 27 / 88 Branchbran 4.0% 3 / 74 Conditioncond 20.0% 1 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 41.1% 7 / 17 Podpod 81.8% 9 / 11 totaltotal 23.7% 47 / 198 CC 41 SCAR 32.7
CC
41
Cov
19%
address
56.0
from
42.0
comment
42.0
CRAP 26.4
« User/Identity/Archive/Plain.pm ↑ Summary User/Identity/Location.pm »
1 # This code is part of Perl distribution User-Identity version 4.00.
2 # The POD got stripped from this file by OODoc version 3.05.
3 # For contributors see file ChangeLog.
4  
5 # This software is copyright (c) 2003-2025 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::Identity;{
13 1 our $VERSION = '4.00';
14 }
15  
16 1 ▶use parent 'User::Identity::Item';
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 1 ▶use Log::Report 'user-identity';
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 1 ▶use User::Identity ();
Subroutine BEGIN: called CC=1 SCAR=0.0
24 1 ▶use Scalar::Util qw/weaken/;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 #--------------------
27  
28 sub type() { 'email' }
29  
30  
31 sub init($)
32 1 ▶{ my ($self, $args) = @_;
Subroutine init: called CC=6 SCAR=19.9
Pod undocumented
33 1 ▶ $args->{name} ||= '-x-';
Condition50%1/2
$args->{"name"} ||= "-x-"
l!l
10
MC/DC0%0/1
$args->{"name"} ||= "-x-"
$args->{"name"}
Truth table50%1/2
A
A= $args->{"name"}
Aresult
11
00
34  
35 1 $self->SUPER::init($args);
36  
37 exists $args->{$_} && ($self->{'MI_'.$_} = delete $args->{$_})
38 1 ▶ for qw/address charset comment domain language location organization pgp_key phrase signature username/;
Branch: 1 branch
BranchTrueFalseTotal
exists $args->{$_} and $$self{'MI_' . $_} = delete $args->{$_} 1 10 11
39  
40 $self->{UII_name} = $self->phrase || $self->address
41 1 ▶ if $self->{UII_name} eq '-x-';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"UII_name"} eq "-x-" 0 1 1
Condition0%0/3
$self->phrase || $self->address
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->phrase || $self->address
$self->phrase $self->address
Truth table0%0/3
A || B
A= $self->phraseB= $self->address
ABresult
1X1
011
000
42  
43 1 $self;
44 }
45  
46 #--------------------
47  
48 sub from($)
49 0 ▶{ my ($class, $other) = (shift, shift);
Subroutine from: not called CC=6 SCAR=37.4
Pod undocumented
50 0 ▶ return $other if $other->isa(__PACKAGE__);
Branch: 1 branch
BranchTrueFalseTotal
if $other->isa(__PACKAGE__) 0 0 0
51  
52 0 ▶ $other->isa('Mail::Address')
Branch: 1 branch
BranchTrueFalseTotal
$other->isa("Mail::Address") and return $class->parse($other->format) 0 0 0
53 and return $class->parse($other->format); # Mail::Address is far to lazy
54  
55 0 ▶ $other->isa('User::Identity')
Branch: 1 branch
BranchTrueFalseTotal
$other->isa("User::Identity") or return undef 0 0 0
56 or return undef;
57  
58 0 ▶ my $emails = $other->collection('emails') or next;
Branch: 1 branch
BranchTrueFalseTotal
my $emails = $other->collection("emails") or next 0 0 0
59 0 ▶ my @roles = $emails->roles or return ();
Branch: 1 branch
BranchTrueFalseTotal
my(@roles) = $emails->roles or return () 0 0 0
60 0 $roles[0]; # first Mail::Identity
61 }
62  
63 #--------------------
64  
65 sub comment($)
66 0 ▶{ my $self = shift;
Subroutine comment: not called CC=6 SCAR=37.4
Pod documented
67 0 ▶ return $self->{MI_comment} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
68 0 ▶ return $self->{MI_comment} if defined $self->{MI_comment};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"MI_comment"} 0 0 0
69  
70 0 ▶ my $user = $self->user or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $user = $self->user or return undef 0 0 0
71 0 ▶ my $full = $user->fullName or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $full = $user->fullName or return undef 0 0 0
72 0 ▶ $self->phrase eq $full ? undef : $full;
Branch: 1 branch
BranchTrueFalseTotal
$self->phrase eq $full ? : 0 0 0
73 }
74  
75  
76 sub charset()
77 0 ▶{ my $self = shift;
Subroutine charset: not called CC=3 SCAR=24.8
Pod documented
78 0 ▶ return $self->{MI_charset} if defined $self->{MI_charset};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"MI_charset"} 0 0 0
79  
80 0 my $user = $self->user;
81 0 ▶ defined $user ? $user->charset : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $user ? : 0 0 0
82 }
83  
84  
85 sub language()
86 0 ▶{ my $self = shift;
Subroutine language: not called CC=3 SCAR=24.8
Pod documented
87 0 ▶ return $self->{MI_language} if defined $self->{MI_language};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"MI_language"} 0 0 0
88  
89 0 my $user = $self->user;
90 0 ▶ defined $user ? $user->language : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $user ? : 0 0 0
91 }
92  
93  
94 sub domain()
95 0 ▶{ my $self = shift;
Subroutine domain: not called CC=4 SCAR=30.0
Pod documented
96 0 ▶ return $self->{MI_domain} if defined $self->{MI_domain};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"MI_domain"} 0 0 0
97  
98 0 ▶ my $address = $self->{MI_address} or return 'localhost';
Branch: 1 branch
BranchTrueFalseTotal
my $address = $self->{"MI_address"} or return "localhost" 0 0 0
99 0 ▶ $address =~ s/.*?\@// ? $address : undef;
Branch: 1 branch
BranchTrueFalseTotal
$address =~ s/.*?\@// ? : 0 0 0
100 }
101  
102  
103 sub address()
104 0 ▶{ my $self = shift;
Subroutine address: not called CC=7 SCAR=40.3
Pod documented
105 0 ▶ return $self->{MI_address} if defined $self->{MI_address};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"MI_address"} 0 0 0
106  
107 0 ▶ if(my $username = $self->username)
Branch: 1 branch
BranchTrueFalseTotal
if (my $username = $self->username) 0 0 0
108 0 ▶ { if(my $domain = $self->domain)
Branch: 1 branch
BranchTrueFalseTotal
if (my $domain = $self->domain) 0 0 0
109 0 ▶ { if($username =~ /[^a-zA-Z0-9!#\$%&'*+\-\/=?^_`{|}~.]/)
Branch: 1 branch
BranchTrueFalseTotal
if ($username =~ m[[^a-zA-Z0-9!#\$%&'*+\-/=?^_`{|}~.]]) 0 0 0
110 { # When the local part does contain a different character
111 # than an atext or dot, make it quoted-string
112 0 $username =~ s/"/\\"/g;
113 0 $username = qq{"$username"};
114 }
115 0 return "$username\@$domain";
116 }
117 }
118  
119 0 my $name = $self->name;
120 0 ▶ return $name if index($name, '@') >= 0;
Branch: 1 branch
BranchTrueFalseTotal
if index($name, "\@") != -1 0 0 0
121  
122 0 my $user = $self->user;
123 0 ▶ defined $user ? $user->nickname : $name;
Branch: 1 branch
BranchTrueFalseTotal
defined $user ? : 0 0 0
124 }
125  
126  
127 sub location()
128 0 ▶{ my $self = shift;
Subroutine location: not called CC=6 SCAR=37.4
Pod documented
129 0 my $location = $self->{MI_location};
130  
131 0 ▶ if(! defined $location)
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $location) { } 0 0 0
elsif (not ref $location) { } 0 0 0
132 0 ▶ { my $user = $self->user or return;
Branch: 1 branch
BranchTrueFalseTotal
my $user = $self->user or return 0 0 0
133 0 my @locs = $user->collection('locations');
134 0 ▶ $location = @locs ? $locs[0] : undef;
Branch: 1 branch
BranchTrueFalseTotal
@locs ? : 0 0 0
135 }
136 elsif(! ref $location)
137 0 ▶ { my $user = $self->user or return;
Branch: 1 branch
BranchTrueFalseTotal
my $user = $self->user or return 0 0 0
138 0 $location = $user->find(location => $location);
139 }
140  
141 0 $location;
142 }
143  
144  
145 sub organization()
146 0 ▶{ my $self = shift;
Subroutine organization: not called CC=3 SCAR=24.8
Pod documented
147 0 ▶ return $self->{MI_organization} if defined $self->{MI_organization};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"MI_organization"} 0 0 0
148  
149 0 ▶ my $location = $self->location or return;
Branch: 1 branch
BranchTrueFalseTotal
my $location = $self->location or return 0 0 0
150 0 $location->organization;
151 }
152  
153 #pgp_key
154  
155 sub phrase()
156 0 ▶{ my $self = shift;
Subroutine phrase: not called CC=3 SCAR=24.8
Pod documented
157 0 ▶ return $self->{MI_phrase} if defined $self->{MI_phrase};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"MI_phrase"} 0 0 0
158  
159 0 my $user = $self->user;
160 0 ▶ defined $user ? $user->fullName : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $user ? : 0 0 0
161 }
162  
163 #signature
164  
165 sub username()
166 0 ▶{ my $self = shift;
Subroutine username: not called CC=4 SCAR=30.0
Pod documented
167 0 ▶ return $self->{MI_username} if defined $self->{MI_username};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"MI_username"} 0 0 0
168  
169 0 ▶ if(my $address = $self->{MI_address})
Branch: 1 branch
BranchTrueFalseTotal
if (my $address = $self->{"MI_address"}) 0 0 0
170 0 { $address =~ s/\@.*$//; # strip domain part if present
171 0 return $address;
172 }
173  
174 0 my $user = $self->user;
175 0 ▶ defined $user ? $user->nickname : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $user ? : 0 0 0
176 }
177  
178 1 1;
« User/Identity/Archive/Plain.pm ↑ Summary User/Identity/Location.pm »