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   1174 use base qw(Number::Phone::StubCountry);
  2         8  
  2         212  
21              
22 2     2   33 use strict;
  2         11  
  2         57  
23 2     2   10 use warnings;
  2         7  
  2         65  
24 2     2   22 use utf8;
  2         13  
  2         13  
25             our $VERSION = 1.20230903131448;
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} = {"2612069", "Maintirano",
70             "2612047", "Ambositra",
71             "2612044", "Antsirabe",
72             "2612056", "Moramanga",
73             "2612022", "Antananarivo",
74             "2612057", "Maroantsetra\/Sainte\ Marie",
75             "2612073", "Farafangana",
76             "2612054", "Ambatondrazaka",
77             "26120722", "Manakara",
78             "2612095", "Morondava",
79             "2612086", "Nosy\ Be",
80             "2612067", "Antsohihy",
81             "2612053", "Toamasina",
82             "26120729", "Mananjary",
83             "2612088", "Sambava",
84             "2612062", "Mahajanga",
85             "2612082", "Antsiranana",
86             "2612075", "Fianarantsoa",
87             "2612094", "Toliary",
88             "2612092", "TaolaƱaro",};
89              
90             sub new {
91 10     10 1 23 my $class = shift;
92 10         17 my $number = shift;
93 10         65 $number =~ s/(^\+261|\D)//g;
94 10         61 my $self = bless({ country_code => '261', number => $number, formatters => $formatters, validators => $validators, areanames => \%areanames}, $class);
95 10 100       50 return $self if ($self->is_valid());
96 1         15 my $prefix = qr/^(?:([24-9]\d{6})$|0)/;
97 1         3 my @matches = $number =~ /$prefix/;
98 1 50       4 if (defined $matches[-1]) {
99 2     2   744 no warnings 'uninitialized';
  2         5  
  2         368  
100 0         0 $number =~ s/$prefix/20$1/;
101             }
102             else {
103 1         3 $number =~ s/$prefix//;
104             }
105 1         10 $self = bless({ country_code => '261', number => $number, formatters => $formatters, validators => $validators, areanames => \%areanames}, $class);
106 1 50       5 return $self->is_valid() ? $self : undef;
107             }
108             1;