Contact/Address/Country.pm

filter: Statementstmt 100% 14 / 14 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod n/a totaltotal 100% 19 / 19 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Contact/Address/City.pm ↑ Summary Contact/Address/State.pm »
1 1 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package Class::Value::Contact::Address::Country;
6 our $VERSION = '1.100840';
7 # ABSTRACT: Contact-related value objects
8 1 ▶use Error::Hierarchy::Util 'assert_defined';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use parent 'Class::Value::Contact::Address';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 # Class method:
12 #
13 # Takes a potential country name which could be an alias and returns the
14 # normal country name for that country (e.g., 'Oesterreich' and 'Austria'
15 # both map to 'Austria') If the name is already the normal name, it isn't
16 # changed and returned. If the name given isn't a country name (or an
17 # alias), a false value is returned.
18 sub normalize_value {
19 my ($self, $value) = @_;
20 return unless $value;
21 $self->get_short_country_name($value);
22 }
23  
24 # get_normal_country_name() can be called as a class method with an argument,
25 # or as an object method without an argument (in which case it will act on the
26 # object's value).
27 sub get_normal_country_name {
28 my ($self, $country) = @_;
29 our %cache;
30 $country = $self->value unless defined $country;
31 $cache{normal_country_name}{$country} =
32 $self->_get_normal_country_name($country)
33 unless defined $cache{normal_country_name}{$country};
34 $cache{normal_country_name}{$country};
35 }
36  
37 sub _get_normal_country_name {
38 my ($self, $country) = @_;
39 $country; # no normalizations defined
40 }
41  
42 # get_short_country_name() can be called as a class method with an argument,
43 # or as an object method without an argument (in which case it will act on the
44 # object's value).
45 sub get_short_country_name {
46 my ($self, $country) = @_;
47 our %cache;
48 $country = $self->value unless defined $country;
49 $cache{short_country_name}{$country} =
50 $self->_get_short_country_name($country)
51 unless defined $cache{short_country_name}{$country};
52 $cache{short_country_name}{$country};
53 }
54  
55 sub _get_short_country_name {
56 my ($self, $country) = @_;
57 undef; # no short country names defined
58 }
59  
60 sub send_notify_value_normalized {
61 my ($self, $value, $normalized) = @_;
62 my $class = 'Class::Value::Contact::Exception::ReplaceAliasCountry';
63 $self->exception_container->record(
64 $class,
65 original => $value,
66 replacement => $normalized,
67 );
68 }
69  
70 sub send_notify_value_invalid {
71 my ($self, $value) = @_;
72 local $Error::Depth = $Error::Depth + 2;
73 $self->exception_container->record(
74 'Class::Value::Contact::Exception::InvalidCountry',
75 country => $value,);
76 }
77 1;
78  
79  
80 __END__
« Contact/Address/City.pm ↑ Summary Contact/Address/State.pm »