Commit 54878bc3 authored by Alasdair Keyes's avatar Alasdair Keyes

Add in Country Code value objects

parent fff24a86
package ValueObject::Geography::Country::Codes::2Character;
use strict;
use warnings;
use Carp;
use ValueObject::Geography::Country::Codes::Exception::Invalid2Character;
use base qw/ ValueObject::Geography::Country::Codes::Base /;
my @codes = qw/
AF
AX
AL
DZ
AS
AD
AO
AI
AQ
AG
AR
AM
AW
AU
AT
AZ
BS
BH
BD
BB
BY
BE
BZ
BJ
BM
BT
BO
BQ
BA
BW
BV
BR
IO
BN
BG
BF
BI
CV
KH
CM
CA
KY
CF
TD
CL
CN
CX
CC
CO
KM
CG
CD
CK
CR
CI
HR
CU
CW
CY
CZ
DK
DJ
DM
DO
EC
EG
SV
GQ
ER
EE
ET
FK
FO
FJ
FI
FR
GF
PF
TF
GA
GM
GE
DE
GH
GI
GR
GL
GD
GP
GU
GT
GG
GN
GW
GY
HT
HM
VA
HN
HK
HU
IS
IN
ID
IR
IQ
IE
IM
IL
IT
JM
JP
JE
JO
KZ
KE
KI
KP
KR
KW
KG
LA
LV
LB
LS
LR
LY
LI
LT
LU
MO
MK
MG
MW
MY
MV
ML
MT
MH
MQ
MR
MU
YT
MX
FM
MD
MC
MN
ME
MS
MA
MZ
MM
NA
NR
NP
NL
NC
NZ
NI
NE
NG
NU
NF
MP
NO
OM
PK
PW
PS
PA
PG
PY
PE
PH
PN
PL
PT
PR
QA
RE
RO
RU
RW
BL
SH
KN
LC
MF
PM
VC
WS
SM
ST
SA
SN
RS
SC
SL
SG
SX
SK
SI
SB
SO
ZA
GS
SS
ES
LK
SD
SR
SJ
SZ
SE
CH
SY
TW
TJ
TZ
TH
TL
TG
TK
TO
TT
TN
TR
TM
TC
TV
UG
UA
AE
GB
US
UM
UY
UZ
VU
VE
VN
VG
VI
WF
EH
YE
ZM
ZW
/;
sub validate {
my $self = shift;
my $value = shift || '';
croak (ValueObject::Geography::Country::Codes::Exception::Invalid2Character->new($value))
unless (grep { lc($_) eq lc($value) } @codes);
return 1;
}
1;
=head1 NAME
ValueObject::Geography::Country::Codes::2Character - Value Object for ISO-3166-1 alpha-2 codes
=head1 SYNOPSIS
use ValueObject::Geography::Country::Codes::2Character;
my $vo = ValueObject::Geography::Country::Codes::2Character->new('GB');
=head1 DESCRIPTION
ValueObject::Geography::Country::Codes::2Character provides Value Object for
validation of ISO-3166-1 alpha-2 codes (Case insensitive)
=head1 METHODS
=over 4
=item new($value = '')
Creates a new object
Throws ValueObject::Geography::Country::Codes::Exception::Invalid2Character
if $value is invalid
=item validate()
Called during instantiation to validate $value
=item value()
Returns the raw value as passed in at instantiation
=back
=head1 SEE ALSO
L<ValueObject::Geography::Country::Codes::Base>
=cut
package ValueObject::Geography::Country::Codes::3Character;
use strict;
use warnings;
use Carp;
use ValueObject::Geography::Country::Codes::Exception::Invalid3Character;
use base qw/ ValueObject::Geography::Country::Codes::Base /;
my @codes = qw/
AFG
ALA
ALB
DZA
ASM
AND
AGO
AIA
ATA
ATG
ARG
ARM
ABW
AUS
AUT
AZE
BHS
BHR
BGD
BRB
BLR
BEL
BLZ
BEN
BMU
BTN
BOL
BES
BIH
BWA
BVT
BRA
IOT
BRN
BGR
BFA
BDI
CPV
KHM
CMR
CAN
CYM
CAF
TCD
CHL
CHN
CXR
CCK
COL
COM
COG
COD
COK
CRI
CIV
HRV
CUB
CUW
CYP
CZE
DNK
DJI
DMA
DOM
ECU
EGY
SLV
GNQ
ERI
EST
ETH
FLK
FRO
FJI
FIN
FRA
GUF
PYF
ATF
GAB
GMB
GEO
DEU
GHA
GIB
GRC
GRL
GRD
GLP
GUM
GTM
GGY
GIN
GNB
GUY
HTI
HMD
VAT
HND
HKG
HUN
ISL
IND
IDN
IRN
IRQ
IRL
IMN
ISR
ITA
JAM
JPN
JEY
JOR
KAZ
KEN
KIR
PRK
KOR
KWT
KGZ
LAO
LVA
LBN
LSO
LBR
LBY
LIE
LTU
LUX
MAC
MKD
MDG
MWI
MYS
MDV
MLI
MLT
MHL
MTQ
MRT
MUS
MYT
MEX
FSM
MDA
MCO
MNG
MNE
MSR
MAR
MOZ
MMR
NAM
NRU
NPL
NLD
NCL
NZL
NIC
NER
NGA
NIU
NFK
MNP
NOR
OMN
PAK
PLW
PSE
PAN
PNG
PRY
PER
PHL
PCN
POL
PRT
PRI
QAT
REU
ROU
RUS
RWA
BLM
SHN
KNA
LCA
MAF
SPM
VCT
WSM
SMR
STP
SAU
SEN
SRB
SYC
SLE
SGP
SXM
SVK
SVN
SLB
SOM
ZAF
SGS
SSD
ESP
LKA
SDN
SUR
SJM
SWZ
SWE
CHE
SYR
TWN
TJK
TZA
THA
TLS
TGO
TKL
TON
TTO
TUN
TUR
TKM
TCA
TUV
UGA
UKR
ARE
GBR
USA
UMI
URY
UZB
VUT
VEN
VNM
VGB
VIR
WLF
ESH
YEM
ZMB
ZWE
/;
sub validate {
my $self = shift;
my $value = shift || '';
croak (ValueObject::Geography::Country::Codes::Exception::Invalid3Character->new($value))
unless (grep { lc($_) eq lc($value) } @codes);
return 1;
}
1;
=head1 NAME
ValueObject::Geography::Country::Codes::3Character - Value Object for ISO-3166-1 alpha-3 codes
=head1 SYNOPSIS
use ValueObject::Geography::Country::Codes::3Character;
my $vo = ValueObject::Geography::Country::Codes::3Character->new('GB');
=head1 DESCRIPTION
ValueObject::Geography::Country::Codes::3Character provides Value Object for
validation of ISO-3166-1 alpha-3 codes (Case insensitive)
=head1 METHODS
=over 4
=item new($value = '')
Creates a new object
Throws ValueObject::Geography::Country::Codes::Invalid3Character if $value is invalid
=item validate()
Called during instantiation to validate $value
=item value()
Returns the raw value as passed in at instantiation
=back
=head1 SEE ALSO
L<ValueObject::Geography::Country::Codes::Base>
=cut
package ValueObject::Geography::Country::Codes::Base;
use strict;
use warnings;
use Carp;
use base qw/ ValueObject::Base /;
1;
=head1 NAME
ValueObject::Geography::Country::Codes::Base - Base object for all Boolean Value Objects
=head1 SYNOPSIS
use base qw/ ValueObject::Geography::Country::Codes::Base /;
sub validate {
my $self = shift;
my $value = shift || '';
# if $value validates
# return 1
# else
# Throw exception on failer
}
=head1 DESCRIPTION
ValueObject::Geography::Country::Codes::Base is a base class from which all
Country Code ValueObjects extend.
The validate() sub routine needs overriding
=head1 METHODS
=over 4
=item validate()
Called during instantiation to validate $value
=back
=head1 SEE ALSO
L<Carp>,
L<ValueObject::Base>
=cut
package ValueObject::Geography::Country::Codes::Exception::Invalid2Character;
use strict;
use warnings;
use base qw/ ValueObject::Exception::Base /;
sub new {
my $class = shift;
my $message = 'Invalid ISO-3166 alpha-2 code';
return $class->SUPER::new($message, @_);
}