File Coverage

blib/lib/User/Identity/Location.pm
Criterion Covered Total %
statement 58 63 92.0
branch 24 32 75.0
condition 9 18 50.0
subroutine 18 20 90.0
pod 13 14 92.8
total 122 147 82.9


line stmt bran cond sub pod time code
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             our $VERSION = '4.00';
14             }
15              
16 2     2   101609 use parent 'User::Identity::Item';
  2         293  
  2         10  
17              
18 2     2   141 use strict;
  2         4  
  2         43  
19 2     2   9 use warnings;
  2         3  
  2         92  
20              
21 2     2   9 use Log::Report 'user-identity';
  2         2  
  2         11  
22              
23 2     2   1191 use User::Identity ();
  2         4  
  2         84  
24 2     2   10 use Scalar::Util qw/weaken/;
  2         4  
  2         1440  
25              
26             #--------------------
27              
28 0     0 1 0 sub type { 'location' }
29              
30              
31             sub init($)
32 4     4 0 14 { my ($self, $args) = @_;
33              
34 4   66     26 $args->{postal_code} ||= delete $args->{pc};
35              
36 4         25 $self->SUPER::init($args);
37              
38             exists $args->{$_} && ($self->{'UIL_'.$_} = delete $args->{$_})
39 4   100     97 for qw/city country country_code fax organization pobox pobox_pc postal_code state street phone/;
40              
41 4         12 $self;
42             }
43              
44             #--------------------
45              
46 2     2 1 909 sub street() { $_[0]->{UIL_street} }
47              
48              
49 2     2 1 8 sub postalCode() { $_[0]->{UIL_postal_code} }
50              
51              
52 3     3 1 17 sub pobox() { $_[0]->{UIL_pobox} }
53              
54              
55 2     2 1 9 sub poboxPostalCode() { $_[0]->{UIL_pobox_pc} }
56              
57              
58 2     2 1 14 sub city() { $_[0]->{UIL_city} }
59              
60              
61 0     0 1 0 sub state() { $_[0]->{UIL_state} }
62              
63              
64             sub country()
65 3     3 1 20 { my $self = shift;
66 3 100       20 return $self->{UIL_country} if defined $self->{UIL_country};
67              
68 1 50       4 my $cc = $self->countryCode or return;
69              
70 1         74 eval 'require Geography::Countries';
71 1 50       10 return if $@;
72              
73 0         0 scalar Geography::Countries::country($cc);
74             }
75              
76              
77 5     5 1 423 sub countryCode() { $_[0]->{UIL_country_code} }
78              
79              
80 1     1 1 8 sub organization() { $_[0]->{UIL_organization} }
81              
82              
83             sub phone()
84 3     3 1 11 { my $self = shift;
85 3 50       12 my $phone = $self->{UIL_phone} or return ();
86              
87 3 100       15 my @phone = ref $phone ? @$phone : $phone;
88 3 100       17 wantarray ? @phone : $phone[0];
89             }
90              
91              
92             sub fax()
93 3     3 1 2649 { my $self = shift;
94              
95 3 50       32 my $fax = $self->{UIL_fax} or return ();
96 3 100       16 my @fax = ref $fax ? @$fax : $fax;
97 3 100       20 wantarray ? @fax : $fax[0];
98             }
99              
100              
101             sub fullAddress()
102 2     2 1 3290 { my $self = shift;
103 2   50     8 my $cc = $self->countryCode || 'en';
104              
105 2         6 my ($address, $pc);
106 2 100       8 if($address = $self->pobox) { $pc = $self->poboxPostalCode }
  1         5  
107 1         5 else { $address = $self->street; $pc = $self->postalCode }
  1         4  
108              
109 2         9 my ($org, $city, $state) = @$self{ qw/UIL_organization UIL_city UIL_state/ };
110 2 50 33     16 defined $city && defined $address or return;
111              
112 2         8 my $country = $self->country;
113 2 50       13 $country = defined $country ? "\n$country" : defined $cc ? "\n".uc($cc) : '';
    100          
114              
115 2 100 66     15 $org .= defined $org && length $org ? "\n" : '';
116              
117 2 50       7 if($cc eq 'nl')
118 2 50 33     31 { $pc = "$1 ".uc($2)." " if defined $pc && $pc =~ m/(\d{4})\s*([a-zA-Z]{2})/;
119 2         19 return "$org$address\n$pc$city$country\n";
120             }
121             else
122 0   0       { $state ||= '';
123 0           return "$org$address\n$city$state$country\n$pc";
124             }
125             }
126              
127             1;