Mail/Identity.pm

filter: Statementstmt 28.8% 26 / 90 Branchbran 3.9% 3 / 76 Conditioncond 20.0% 1 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 41.1% 7 / 17 Podpod 81.8% 9 / 11 totaltotal 22.7% 46 / 202 SCAR 69.4
CC
42
Cov
18%
address
56.0
from
42.0
comment
42.0
CRAP 1030.9
« User/Identity/Archive/Plain.pm ↑ Summary User/Identity.pm »
1 # Copyrights 2003-2022 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 distribution User-Identity. Meta-POD processed with
6 # OODoc into POD and HTML manual-pages. See README.md
7 # Copyright Mark Overmeer. Licensed under the same terms as Perl itself.
8  
9 package Mail::Identity;
10 1 ▶use vars '$VERSION';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 $VERSION = '1.01';
12  
13 1 ▶use base 'User::Identity::Item';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 1 ▶use User::Identity;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use Scalar::Util 'weaken';
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21  
22 sub type() { "email" }
23  
24  
25 sub init($)
26 1 ▶{ my ($self, $args) = @_;
Subroutine init: called CC=6 SCAR=19.9
Pod undocumented
27  
28 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
29  
30 1 $self->SUPER::init($args);
31  
32 exists $args->{$_} && ($self->{'MI_'.$_} = delete $args->{$_})
33 1 ▶ foreach qw/address charset comment domain language
Branch: 1 branch
BranchTrueFalseTotal
exists $args->{$_} and $$self{'MI_' . $_} = delete $args->{$_} 1 10 11
34 location organization pgp_key phrase signature
35 username/;
36  
37 $self->{UII_name} = $self->phrase || $self->address
38 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
39  
40 1 $self;
41 }
42  
43  
44 sub from($)
45 0 ▶{ my ($class, $other) = (shift, shift);
Subroutine from: not called CC=6 SCAR=37.4
Pod undocumented
46 0 ▶ return $other if $other->isa(__PACKAGE__);
Branch: 1 branch
BranchTrueFalseTotal
if $other->isa(__PACKAGE__) 0 0 0
47  
48 0 ▶ if($other->isa('Mail::Address'))
Branch: 1 branch
BranchTrueFalseTotal
if ($other->isa("Mail::Address")) 0 0 0
49 { # Mail::Address is far to lazy
50 0 return $class->parse($other->format);
51 }
52  
53 0 ▶ if($other->isa('User::Identity'))
Branch: 1 branch
BranchTrueFalseTotal
if ($other->isa("User::Identity")) 0 0 0
54 0 ▶ { my $emails = $other->collection('emails') or next;
Branch: 1 branch
BranchTrueFalseTotal
my $emails = $other->collection("emails") or next 0 0 0
55 0 ▶ my @roles = $emails->roles or return ();
Branch: 1 branch
BranchTrueFalseTotal
my(@roles) = $emails->roles or return () 0 0 0
56 0 return $roles[0]; # first Mail::Identity
57 }
58  
59 0 undef;
60 }
61  
62  
63 sub comment($)
64 0 ▶{ my $self = shift;
Subroutine comment: not called CC=6 SCAR=37.4
Pod documented
65 0 ▶ return $self->{MI_comment} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
66 0 ▶ return $self->{MI_comment} if defined $self->{MI_comment};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"MI_comment"} 0 0 0
67  
68 0 ▶ my $user = $self->user or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $user = $self->user or return undef 0 0 0
69 0 ▶ my $full = $user->fullName or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $full = $user->fullName or return undef 0 0 0
70 0 ▶ $self->phrase eq $full ? undef : $full;
Branch: 1 branch
BranchTrueFalseTotal
$self->phrase eq $full ? : 0 0 0
71 }
72  
73  
74 sub charset()
75 0 ▶{ my $self = shift;
Subroutine charset: not called CC=3 SCAR=24.8
Pod documented
76 0 ▶ return $self->{MI_charset} if defined $self->{MI_charset};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"MI_charset"} 0 0 0
77  
78 0 ▶ my $user = $self->user or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $user = $self->user or return undef 0 0 0
79 0 $user->charset;
80 }
81  
82  
83 sub language()
84 0 ▶{ my $self = shift;
Subroutine language: not called CC=3 SCAR=24.8
Pod documented
85
86 0 ▶ return $self->{MI_language} if defined $self->{MI_language};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"MI_language"} 0 0 0
87  
88 0 ▶ my $user = $self->user or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $user = $self->user or return undef 0 0 0
89 0 $user->language;
90 }
91  
92  
93 sub domain()
94 0 ▶{ my $self = shift;
Subroutine domain: not called CC=4 SCAR=30.0
Pod documented
95 return $self->{MI_domain}
96 0 ▶ 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  
148 0 ▶ return $self->{MI_organization} if defined $self->{MI_organization};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"MI_organization"} 0 0 0
149  
150 0 ▶ my $location = $self->location or return;
Branch: 1 branch
BranchTrueFalseTotal
my $location = $self->location or return 0 0 0
151 0 $location->organization;
152 }
153  
154 #pgp_key
155  
156 sub phrase()
157 0 ▶{ my $self = shift;
Subroutine phrase: not called CC=4 SCAR=30.0
Pod documented
158 0 ▶ return $self->{MI_phrase} if defined $self->{MI_phrase};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"MI_phrase"} 0 0 0
159 0 ▶ my $user = $self->user or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $user = $self->user or return undef 0 0 0
160 0 ▶ my $full = $user->fullName or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $full = $user->fullName or return undef 0 0 0
161 0 $full;
162 }
163  
164 #signature
165  
166  
167 sub username()
168 0 ▶{ my $self = shift;
Subroutine username: not called CC=4 SCAR=30.0
Pod documented
169 0 ▶ return $self->{MI_username} if defined $self->{MI_username};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"MI_username"} 0 0 0
170
171 0 ▶ if(my $address = $self->{MI_address})
Branch: 1 branch
BranchTrueFalseTotal
if (my $address = $self->{"MI_address"}) 0 0 0
172 0 { $address =~ s/\@.*$//; # strip domain part if present
173 0 return $address;
174 }
175  
176 0 ▶ my $user = $self->user or return;
Branch: 1 branch
BranchTrueFalseTotal
my $user = $self->user or return 0 0 0
177 0 $user->nickname;
178 }
179  
180 1 1;
181  
« User/Identity/Archive/Plain.pm ↑ Summary User/Identity.pm »