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