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   1177 use base qw(Number::Phone::StubCountry);
  2         9  
  2         228  
21              
22 2     2   15 use strict;
  2         8  
  2         45  
23 2     2   21 use warnings;
  2         7  
  2         50  
24 2     2   15 use utf8;
  2         6  
  2         12  
25             our $VERSION = 1.20230903131445;
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{en} = {"4143", "Zurich",
84             "4181", "Chur",
85             "4144", "Zurich",
86             "4134", "Burgdorf\/Langnau\ i\.E\.",
87             "4121", "Lausanne",
88             "4133", "Thun",
89             "4171", "St\.\ Gallen",
90             "4132", "Bienne\/Neuchâtel\/Soleure\/Jura",
91             "4126", "Fribourg",
92             "4162", "Olten",
93             "4156", "Baden",
94             "4141", "Lucerne",
95             "4155", "Rapperswil",
96             "4161", "Basel",
97             "4152", "Winterthur",
98             "4191", "Bellinzona",
99             "4122", "Geneva",
100             "4131", "Berne",
101             "4124", "Yverdon\/Aigle",
102             "4127", "Sion",};
103             $areanames{de} = {"4127", "Sitten",
104             "4131", "Bern",
105             "4122", "Genf",
106             "4141", "Luzern",
107             "4126", "Freiburg",
108             "4132", "Biel\/Neuenburg\/Solothurn\/Jura",
109             "4144", "Zürich",
110             "4143", "Zürich",};
111             $areanames{it} = {"4144", "Zurigo",
112             "4181", "Coira",
113             "4143", "Zurigo",
114             "4171", "San\ Gallo",
115             "4132", "Bienne\/Neuchâtel\/Soletta\/Giura",
116             "4126", "Friburgo",
117             "4121", "Losanna",
118             "4141", "Lucerna",
119             "4131", "Berna",
120             "4122", "Ginevra",
121             "4161", "Basilea",};
122             $areanames{fr} = {"4152", "Winterthour",
123             "4161", "Bâle",
124             "4122", "Genève",
125             "4181", "Coire",
126             "4133", "Thoune",
127             "4171", "St\.\ Gall",};
128              
129             sub new {
130 25     25 1 70 my $class = shift;
131 25         72 my $number = shift;
132 25         154 $number =~ s/(^\+41|\D)//g;
133 25         171 my $self = bless({ country_code => '41', number => $number, formatters => $formatters, validators => $validators, areanames => \%areanames}, $class);
134 25 100       120 return $self if ($self->is_valid());
135 1         9 $number =~ s/^(?:0)//;
136 1         11 $self = bless({ country_code => '41', number => $number, formatters => $formatters, validators => $validators, areanames => \%areanames}, $class);
137 1 50       8 return $self->is_valid() ? $self : undef;
138             }
139             1;