1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
# This code is part of Perl distribution User-Identity version 1.03.
# The POD got stripped from this file by OODoc version 3.05.
# For contributors see file ChangeLog.
# This software is copyright (c) 2003-2025 by Mark Overmeer.
# This is free software; you can redistribute it and/or modify it under
# the same terms as the Perl 5 programming language system itself.
# SPDX-License-Identifier: Artistic-1.0-Perl OR GPL-1.0-or-later
#oodist: *** DO NOT USE THIS VERSION FOR PRODUCTION ***
#oodist: This file contains OODoc-style documentation which will get stripped
#oodist: during its release in the distribution. You can use this file for
#oodist: testing, however the code of this development version may be broken!
package User::Identity::Location;{
our $VERSION = '1.03';
}
use base 'User::Identity::Item';
use strict;
use warnings;
use User::Identity;
use Scalar::Util 'weaken';
#--------------------
sub type { "location" }
sub init($)
{ my ($self, $args) = @_;
$args->{postal_code} ||= delete $args->{pc};
$self->SUPER::init($args);
exists $args->{$_} && ($self->{'UIL_'.$_} = delete $args->{$_})
for qw/city country country_code fax organization pobox pobox_pc postal_code state street phone/;
$self;
}
#--------------------
sub street() { $_[0]->{UIL_street} }
sub postalCode() { $_[0]->{UIL_postal_code} }
sub pobox() { $_[0]->{UIL_pobox} }
sub poboxPostalCode() { $_[0]->{UIL_pobox_pc} }
sub city() { $_[0]->{UIL_city} }
sub state() { $_[0]->{UIL_state} }
sub country()
{ my $self = shift;
return $self->{UIL_country} if defined $self->{UIL_country};
my $cc = $self->countryCode or return;
eval 'require Geography::Countries';
return if $@;
scalar Geography::Countries::country($cc);
}
sub countryCode() { $_[0]->{UIL_country_code} }
sub organization() { $_[0]->{UIL_organization} }
sub phone()
{ my $self = shift;
my $phone = $self->{UIL_phone} or return ();
my @phone = ref $phone ? @$phone : $phone;
wantarray ? @phone : $phone[0];
}
sub fax()
{ my $self = shift;
my $fax = $self->{UIL_fax} or return ();
my @fax = ref $fax ? @$fax : $fax;
wantarray ? @fax : $fax[0];
}
sub fullAddress()
{ my $self = shift;
my $cc = $self->countryCode || 'en';
my ($address, $pc);
if($address = $self->pobox) { $pc = $self->poboxPostalCode }
else { $address = $self->street; $pc = $self->postalCode }
my ($org, $city, $state) = @$self{ qw/UIL_organization UIL_city UIL_state/ };
defined $city && defined $address or return;
my $country = $self->country;
$country
= defined $country ? "\n$country"
: defined $cc ? "\n".uc($cc)
: '';
if(defined $org) {$org .= "\n"} else {$org = ''};
if($cc eq 'nl')
{ $pc = "$1 ".uc($2)." " if defined $pc && $pc =~ m/(\d{4})\s*([a-zA-Z]{2})/;
return "$org$address\n$pc$city$country\n";
}
else
{ $state ||= '';
return "$org$address\n$city$state$country\n$pc";
}
}
1;
|