User/Identity/Location.pm

filter: Statementstmt 92.4% 61 / 66 Branchbran 76.4% 26 / 34 Conditioncond 43.7% 7 / 16 MC/DCmcdc 20.0% 2 / 10 Subroutinesub 90.0% 18 / 20 Podpod 92.8% 13 / 14 totaltotal 79.3% 127 / 160 CC 25 SCAR 19.9
CC
25
Cov
81%
fullAddress
18.4
country
4.2
init
4.0
CRAP 7.3
« Mail/Identity.pm ↑ Summary User/Identity/Collection.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 User::Identity::Location;{
13 2 our $VERSION = '4.00';
14 }
15  
16 2 ▶use parent 'User::Identity::Item';
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 2 ▶use Log::Report 'user-identity';
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 2 ▶use User::Identity ();
Subroutine BEGIN: called CC=1 SCAR=0.0
24 2 ▶use Scalar::Util qw/weaken/;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 #--------------------
27  
28 0 ▶sub type { 'location' }
Subroutine type: not called CC=1 SCAR=6.9
Pod documented
29  
30  
31 sub init($)
32 4 ▶{ my ($self, $args) = @_;
Subroutine init: called CC=4 SCAR=13.9
Pod undocumented
33  
34 4 ▶ $args->{postal_code} ||= delete $args->{pc};
Condition66%2/3
$args->{"postal_code"} ||= delete $args->{"pc"}
l!l&&r!l&&!r
202
MC/DC50%1/2
$args->{"postal_code"} ||= delete $args->{"pc"}
$args->{"postal_code"} delete $args->{"pc"}
Truth table66%2/3
A ||= B
A= $args->{"postal_code"}B= delete $args->{"pc"}
ABresult
1X1
011
000
35  
36 4 $self->SUPER::init($args);
37  
38 exists $args->{$_} && ($self->{'UIL_'.$_} = delete $args->{$_})
39 4 ▶ for qw/city country country_code fax organization pobox pobox_pc postal_code state street phone/;
Branch: 1 branch
BranchTrueFalseTotal
exists $args->{$_} and $$self{'UIL_' . $_} = delete $args->{$_} 24 20 44
40  
41 4 $self;
42 }
43  
44 #--------------------
45  
46 2 ▶sub street() { $_[0]->{UIL_street} }
Subroutine street: called CC=1 SCAR=0.0
Pod documented
47  
48  
49 2 ▶sub postalCode() { $_[0]->{UIL_postal_code} }
Subroutine postalCode: called CC=1 SCAR=0.0
Pod documented
50  
51  
52 3 ▶sub pobox() { $_[0]->{UIL_pobox} }
Subroutine pobox: called CC=1 SCAR=0.0
Pod documented
53  
54  
55 2 ▶sub poboxPostalCode() { $_[0]->{UIL_pobox_pc} }
Subroutine poboxPostalCode: called CC=1 SCAR=0.0
Pod documented
56  
57  
58 2 ▶sub city() { $_[0]->{UIL_city} }
Subroutine city: called CC=1 SCAR=0.0
Pod documented
59  
60  
61 0 ▶sub state() { $_[0]->{UIL_state} }
Subroutine state: not called CC=1 SCAR=6.9
Pod documented
62  
63  
64 sub country()
65 3 ▶{ my $self = shift;
Subroutine country: called CC=4 SCAR=14.5
Pod documented
66 3 ▶ return $self->{UIL_country} if defined $self->{UIL_country};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"UIL_country"} 2 1 3
67  
68 1 ▶ my $cc = $self->countryCode or return;
Branch: 1 branch
BranchTrueFalseTotal
my $cc = $self->countryCode or return 1 0 1
69  
70 1 eval 'require Geography::Countries';
71 1 ▶ return if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 1 0 1
72  
73 0 scalar Geography::Countries::country($cc);
74 }
75  
76  
77 5 ▶sub countryCode() { $_[0]->{UIL_country_code} }
Subroutine countryCode: called CC=1 SCAR=0.0
Pod documented
78  
79  
80 1 ▶sub organization() { $_[0]->{UIL_organization} }
Subroutine organization: called CC=1 SCAR=0.0
Pod documented
81  
82  
83 sub phone()
84 3 ▶{ my $self = shift;
Subroutine phone: called CC=4 SCAR=13.9
Pod documented
85 3 ▶ my $phone = $self->{UIL_phone} or return ();
Branch: 1 branch
BranchTrueFalseTotal
my $phone = $self->{"UIL_phone"} or return () 3 0 3
86  
87 3 ▶ my @phone = ref $phone ? @$phone : $phone;
Branch: 1 branch
BranchTrueFalseTotal
ref $phone ? : 2 1 3
88 3 ▶ wantarray ? @phone : $phone[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 2 3
89 }
90  
91  
92 sub fax()
93 3 ▶{ my $self = shift;
Subroutine fax: called CC=4 SCAR=13.9
Pod documented
94  
95 3 ▶ my $fax = $self->{UIL_fax} or return ();
Branch: 1 branch
BranchTrueFalseTotal
my $fax = $self->{"UIL_fax"} or return () 3 0 3
96 3 ▶ my @fax = ref $fax ? @$fax : $fax;
Branch: 1 branch
BranchTrueFalseTotal
ref $fax ? : 2 1 3
97 3 ▶ wantarray ? @fax : $fax[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 2 3
98 }
99  
100  
101 sub fullAddress()
102 2 ▶{ my $self = shift;
Subroutine fullAddress: called CC=13 SCAR=29.1
Pod documented
103 2 ▶ my $cc = $self->countryCode || 'en';
Condition50%1/2
$self->countryCode || 'en'
l!l
20
MC/DC0%0/1
$self->countryCode || 'en'
$self->countryCode
Truth table50%1/2
A
A= $self->countryCode
Aresult
11
00
104  
105 2 my ($address, $pc);
106 2 ▶ if($address = $self->pobox) { $pc = $self->poboxPostalCode }
Branch: 1 branch
BranchTrueFalseTotal
if ($address = $self->pobox) { } 1 1 2
107 1 else { $address = $self->street; $pc = $self->postalCode }
108  
109 2 my ($org, $city, $state) = @$self{ qw/UIL_organization UIL_city UIL_state/ };
110 2 ▶ defined $city && defined $address or return;
Branch: 1 branch
BranchTrueFalseTotal
defined $city and defined $address or return 2 0 2
Condition33%1/3
defined $city and defined $address
!ll&&!rl&&r
002
MC/DC0%0/2
defined $city and defined $address
defined $city defined $address
Truth table33%1/3
A and B
A= defined $cityB= defined $address
ABresult
0X0
100
111
111  
112 2 my $country = $self->country;
113 2 ▶ $country = defined $country ? "\n$country" : defined $cc ? "\n".uc($cc) : '';
Branch: 2 branches
BranchTrueFalseTotal
defined $country ? : 1 1 2
defined $cc ? : 1 0 1
114  
115 2 ▶ $org .= defined $org && length $org ? "\n" : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $org && length $org ? : 1 1 2
Condition66%2/3
defined $org and length $org
!ll&&!rl&&r
101
MC/DC50%1/2
defined $org and length $org
defined $org length $org
Truth table66%2/3
A and B
A= defined $orgB= length $org
ABresult
0X0
100
111
116  
117 2 ▶ if($cc eq 'nl')
Branch: 1 branch
BranchTrueFalseTotal
if ($cc eq 'nl') { } 2 0 2
118 2 ▶ { $pc = "$1 ".uc($2)." " if defined $pc && $pc =~ m/(\d{4})\s*([a-zA-Z]{2})/;
Branch: 1 branch
BranchTrueFalseTotal
if defined $pc and $pc =~ /(\d{4})\s*([a-zA-Z]{2})/ 2 0 2
Condition33%1/3
defined $pc and $pc =~ /(\d{4})\s*([a-zA-Z]{2})/
!ll&&!rl&&r
002
MC/DC0%0/2
defined $pc and $pc =~ /(\d{4})\s*([a-zA-Z]{2})/
defined $pc $pc =~ /(\d{4})\s*([a-zA-Z]{2})/
Truth table33%1/3
A and B
A= defined $pcB= $pc =~ /(\d{4})\s*([a-zA-Z]{2})/
ABresult
0X0
100
111
119 2 return "$org$address\n$pc$city$country\n";
120 }
121 else
122 0 ▶ { $state ||= '';
Condition0%0/2
$state ||= ""
l!l
00
MC/DC0%0/1
$state ||= ""
$state
Truth table0%0/2
A
A= $state
Aresult
11
00
123 0 return "$org$address\n$city$state$country\n$pc";
124 }
125 }
126  
127 2 1;
« Mail/Identity.pm ↑ Summary User/Identity/Collection.pm »