Country/Fast.pm

filter: Statementstmt 95.0% 38 / 40 Branchbran 90.0% 9 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 15 / 15 Podpod n/a totaltotal 95.3% 62 / 65 CC 5 SCAR 3.5
CC
5
Cov
94%
__ANON__
2.0
__ANON__
2.0
__ANON__
2.0
CRAP 1.4
« Country.pm ↑ Summary
1 package MooseX::Types::Locale::Country::Fast;
2  
3  
4 # ****************************************************************
5 # general dependency(-ies)
6 # ****************************************************************
7  
8 1 ▶use 5.008_001;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 # MooseX::Types turns strict/warnings pragmas on,
10 # however, kwalitee scorer can not detect such mechanism.
11 # (Perl::Critic can it, with equivalent_modules parameter)
12 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 ▶use Locale::Country;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use MooseX::Types::Moose qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
17 Str
18 Int
19 1 );
20 1 ▶use MooseX::Types (
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 -declare => [qw(
22 CountryCode
23 Alpha2Country
24 Alpha3Country
25 NumericCountry
26 CountryName
27 )],
28 1 );
29  
30  
31 # ****************************************************************
32 # namespace clearer
33 # ****************************************************************
34  
35 1 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
36  
37  
38 # ****************************************************************
39 # public class variable(s)
40 # ****************************************************************
41  
42 1 our $VERSION = "0.05";
43  
44  
45 # ****************************************************************
46 # subtype(s) and coercion(s)
47 # ****************************************************************
48  
49 # ----------------------------------------------------------------
50 # alpha-2 country code as defined in ISO 3166-1
51 # ----------------------------------------------------------------
52 1 foreach my $subtype (CountryCode, Alpha2Country) {
53 subtype $subtype,
54 as Str,
55 6 ▶ where {
Subroutine __ANON__: called CC=1 SCAR=0.0
56 6 code2country($_, LOCALE_CODE_ALPHA_2);
57 },
58 4 ▶ message {
Subroutine __ANON__: called CC=2 SCAR=6.9
59 4 ▶ sprintf 'Validation failed for code failed with value (%s) '
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 2 2 4
60 . 'because specified country code does not exist '
61 . 'in ISO 3166-1 alpha-2',
62 defined $_ ? $_ : q{};
63 2 };
64 }
65  
66 # ----------------------------------------------------------------
67 # alpha-3 country code as defined in ISO 3166-1
68 # ----------------------------------------------------------------
69 subtype Alpha3Country,
70 as Str,
71 3 ▶ where {
Subroutine __ANON__: called CC=1 SCAR=0.0
72 3 code2country($_, LOCALE_CODE_ALPHA_3);
73 },
74 2 ▶ message {
Subroutine __ANON__: called CC=2 SCAR=6.9
75 2 ▶ sprintf 'Validation failed for code failed with value (%s) '
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 1 1 2
76 . 'because specified country code does not exist '
77 . 'in ISO 3166-1 alpha-3',
78 defined $_ ? $_ : q{};
79 1 };
80  
81 # ----------------------------------------------------------------
82 # numeric country code as defined in ISO 3166-1
83 # ----------------------------------------------------------------
84 subtype NumericCountry,
85 as Str,
86 3 ▶ where {
Subroutine __ANON__: called CC=1 SCAR=0.0
87 3 code2country($_, LOCALE_CODE_NUMERIC);
88 },
89 2 ▶ message {
Subroutine __ANON__: called CC=2 SCAR=6.9
90 2 ▶ sprintf 'Validation failed for code failed with value (%s) '
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 1 1 2
91 . 'because specified country code does not exist '
92 . 'in ISO 3166-1 numeric',
93 defined $_ ? $_ : q{};
94 1 };
95  
96 # ----------------------------------------------------------------
97 # Country name as defined in ISO 639-1
98 # ----------------------------------------------------------------
99 subtype CountryName,
100 as Str,
101 3 ▶ where {
Subroutine __ANON__: called CC=1 SCAR=0.0
102 3 country2code($_);
103 },
104 2 ▶ message {
Subroutine __ANON__: called CC=2 SCAR=6.9
105 2 ▶ sprintf 'Validation failed for name failed with value (%s) '
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 1 1 2
106 . 'because specified country name does not exist '
107 . 'in ISO 3166-1',
108 defined $_ ? $_ : q{};
109 1 };
110  
111  
112 # ****************************************************************
113 # optionally add Getopt option type
114 # ****************************************************************
115  
116 1 eval { require MooseX::Getopt; };
117 1 ▶if (!$@) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($@) 0 1 1
118 MooseX::Getopt::OptionTypeMap->add_option_type_to_map( $_, '=s', )
119 0 for (CountryCode, Alpha2Country, Alpha3Country, CountryName);
120 MooseX::Getopt::OptionTypeMap->add_option_type_to_map( $_, '=i', )
121 0 for (NumericCountry);
122 }
123  
124  
125 # ****************************************************************
126 # return true
127 # ****************************************************************
128  
129 1 1;
130 __END__
« Country.pm ↑ Summary