File Coverage

blib/lib/Number/Phone/StubCountry/MG.pm
Criterion Covered Total %
statement 26 27 96.3
branch 4 6 66.6
condition n/a
subroutine 6 6 100.0
pod 1 1 100.0
total 37 40 92.5


line stmt bran cond sub pod time code
1             # automatically generated file, don't edit
2              
3              
4              
5             # Copyright 2023 David Cantrell, derived from data from libphonenumber
6             # http://code.google.com/p/libphonenumber/
7             #
8             # Licensed under the Apache License, Version 2.0 (the "License");
9             # you may not use this file except in compliance with the License.
10             # You may obtain a copy of the License at
11             #
12             # http://www.apache.org/licenses/LICENSE-2.0
13             #
14             # Unless required by applicable law or agreed to in writing, software
15             # distributed under the License is distributed on an "AS IS" BASIS,
16             # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17             # See the License for the specific language governing permissions and
18             # limitations under the License.
19             package Number::Phone::StubCountry::MG;
20 2     2   1233 use base qw(Number::Phone::StubCountry);
  2         7  
  2         252  
21              
22 2     2   19 use strict;
  2         7  
  2         54  
23 2     2   11 use warnings;
  2         6  
  2         75  
24 2     2   13 use utf8;
  2         8  
  2         15  
25             our $VERSION = 1.20230614174404;
26              
27             my $formatters = [
28             {
29             'format' => '$1 $2 $3 $4',
30             'leading_digits' => '[23]',
31             'national_rule' => '0$1',
32             'pattern' => '(\\d{2})(\\d{2})(\\d{3})(\\d{2})'
33             }
34             ];
35              
36             my $validators = {
37             'fixed_line' => '
38             2072[29]\\d{4}|
39             20(?:
40             2\\d|
41             4[47]|
42             5[3467]|
43             6[279]|
44             7[35]|
45             8[268]|
46             9[245]
47             )\\d{5}
48             ',
49             'geographic' => '
50             2072[29]\\d{4}|
51             20(?:
52             2\\d|
53             4[47]|
54             5[3467]|
55             6[279]|
56             7[35]|
57             8[268]|
58             9[245]
59             )\\d{5}
60             ',
61             'mobile' => '3[2-47-9]\\d{7}',
62             'pager' => '',
63             'personal_number' => '',
64             'specialrate' => '',
65             'toll_free' => '',
66             'voip' => '22\\d{7}'
67             };
68             my %areanames = ();
69             $areanames{en} = {"2612047", "Ambositra",
70             "2612057", "Maroantsetra\/Sainte\ Marie",
71             "26120722", "Manakara",
72             "2612044", "Antsirabe",
73             "26120729", "Mananjary",
74             "2612094", "Toliary",
75             "2612054", "Ambatondrazaka",
76             "2612056", "Moramanga",
77             "2612082", "Antsiranana",
78             "2612062", "Mahajanga",
79             "2612075", "Fianarantsoa",
80             "2612073", "Farafangana",
81             "2612092", "TaolaƱaro",
82             "2612086", "Nosy\ Be",
83             "2612088", "Sambava",
84             "2612067", "Antsohihy",
85             "2612053", "Toamasina",
86             "2612095", "Morondava",
87             "2612069", "Maintirano",
88             "2612022", "Antananarivo",};
89              
90             sub new {
91 10     10 1 26 my $class = shift;
92 10         19 my $number = shift;
93 10         62 $number =~ s/(^\+261|\D)//g;
94 10         60 my $self = bless({ country_code => '261', number => $number, formatters => $formatters, validators => $validators, areanames => \%areanames}, $class);
95 10 100       56 return $self if ($self->is_valid());
96 1         6 my $prefix = qr/^(?:([24-9]\d{6})$|0)/;
97 1         3 my @matches = $number =~ /$prefix/;
98 1 50       8 if (defined $matches[-1]) {
99 2     2   757 no warnings 'uninitialized';
  2         5  
  2         335  
100 0         0 $number =~ s/$prefix/20$1/;
101             }
102             else {
103 1         7 $number =~ s/$prefix//;
104             }
105 1         13 $self = bless({ country_code => '261', number => $number, formatters => $formatters, validators => $validators, areanames => \%areanames}, $class);
106 1 50       12 return $self->is_valid() ? $self : undef;
107             }
108             1;