File Coverage

blib/lib/User/Identity/Location.pm
Criterion Covered Total %
statement 60 65 92.3
branch 24 32 75.0
condition 7 15 46.6
subroutine 18 20 90.0
pod 13 14 92.8
total 122 146 83.5


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