File Coverage

blib/lib/Number/Phone/StubCountry/CH.pm
Criterion Covered Total %
statement 20 20 100.0
branch 3 4 75.0
condition n/a
subroutine 5 5 100.0
pod 1 1 100.0
total 29 30 96.6


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::CH;
20 2     2   1161 use base qw(Number::Phone::StubCountry);
  2         7  
  2         244  
21              
22 2     2   25 use strict;
  2         4  
  2         51  
23 2     2   13 use warnings;
  2         6  
  2         59  
24 2     2   11 use utf8;
  2         6  
  2         12  
25             our $VERSION = 1.20230614174401;
26              
27             my $formatters = [
28             {
29             'format' => '$1 $2 $3',
30             'leading_digits' => '
31             8[047]|
32             90
33             ',
34             'national_rule' => '0$1',
35             'pattern' => '(\\d{3})(\\d{3})(\\d{3})'
36             },
37             {
38             'format' => '$1 $2 $3 $4',
39             'leading_digits' => '
40             [2-79]|
41             81
42             ',
43             'national_rule' => '0$1',
44             'pattern' => '(\\d{2})(\\d{3})(\\d{2})(\\d{2})'
45             },
46             {
47             'format' => '$1 $2 $3 $4 $5',
48             'leading_digits' => '8',
49             'national_rule' => '0$1',
50             'pattern' => '(\\d{3})(\\d{2})(\\d{3})(\\d{2})(\\d{2})'
51             }
52             ];
53              
54             my $validators = {
55             'fixed_line' => '
56             (?:
57             2[12467]|
58             3[1-4]|
59             4[134]|
60             5[256]|
61             6[12]|
62             [7-9]1
63             )\\d{7}
64             ',
65             'geographic' => '
66             (?:
67             2[12467]|
68             3[1-4]|
69             4[134]|
70             5[256]|
71             6[12]|
72             [7-9]1
73             )\\d{7}
74             ',
75             'mobile' => '7[35-9]\\d{7}',
76             'pager' => '74[0248]\\d{6}',
77             'personal_number' => '878\\d{6}',
78             'specialrate' => '(84[0248]\\d{6})|(90[016]\\d{6})|(5[18]\\d{7})',
79             'toll_free' => '800\\d{6}',
80             'voip' => ''
81             };
82             my %areanames = ();
83             $areanames{de} = {"4131", "Bern",
84             "4143", "Zürich",
85             "4132", "Biel\/Neuenburg\/Solothurn\/Jura",
86             "4127", "Sitten",
87             "4122", "Genf",
88             "4141", "Luzern",
89             "4126", "Freiburg",
90             "4144", "Zürich",};
91             $areanames{fr} = {"4171", "St\.\ Gall",
92             "4133", "Thoune",
93             "4161", "Bâle",
94             "4152", "Winterthour",
95             "4122", "Genève",
96             "4181", "Coire",};
97             $areanames{en} = {"4134", "Burgdorf\/Langnau\ i\.E\.",
98             "4122", "Geneva",
99             "4191", "Bellinzona",
100             "4181", "Chur",
101             "4121", "Lausanne",
102             "4143", "Zurich",
103             "4131", "Berne",
104             "4127", "Sion",
105             "4124", "Yverdon\/Aigle",
106             "4155", "Rapperswil",
107             "4132", "Bienne\/Neuchâtel\/Soleure\/Jura",
108             "4156", "Baden",
109             "4152", "Winterthur",
110             "4144", "Zurich",
111             "4171", "St\.\ Gallen",
112             "4133", "Thun",
113             "4162", "Olten",
114             "4141", "Lucerne",
115             "4126", "Fribourg",
116             "4161", "Basel",};
117             $areanames{it} = {"4122", "Ginevra",
118             "4121", "Losanna",
119             "4181", "Coira",
120             "4143", "Zurigo",
121             "4131", "Berna",
122             "4132", "Bienne\/Neuchâtel\/Soletta\/Giura",
123             "4144", "Zurigo",
124             "4171", "San\ Gallo",
125             "4141", "Lucerna",
126             "4126", "Friburgo",
127             "4161", "Basilea",};
128              
129             sub new {
130 25     25 1 57 my $class = shift;
131 25         39 my $number = shift;
132 25         159 $number =~ s/(^\+41|\D)//g;
133 25         152 my $self = bless({ country_code => '41', number => $number, formatters => $formatters, validators => $validators, areanames => \%areanames}, $class);
134 25 100       119 return $self if ($self->is_valid());
135 1         11 $number =~ s/^(?:0)//;
136 1         22 $self = bless({ country_code => '41', number => $number, formatters => $formatters, validators => $validators, areanames => \%areanames}, $class);
137 1 50       9 return $self->is_valid() ? $self : undef;
138             }
139             1;