File Coverage

blib/lib/Number/Phone/StubCountry/SM.pm
Criterion Covered Total %
statement 27 27 100.0
branch 6 6 100.0
condition n/a
subroutine 6 6 100.0
pod 1 1 100.0
total 40 40 100.0


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::SM;
20 3     3   1700 use base qw(Number::Phone::StubCountry);
  3         9  
  3         368  
21              
22 3     3   35 use strict;
  3         7  
  3         65  
23 3     3   19 use warnings;
  3         9  
  3         72  
24 3     3   20 use utf8;
  3         6  
  3         22  
25             our $VERSION = 1.20230307181422;
26              
27             my $formatters = [
28             {
29             'format' => '$1',
30             'intl_format' => 'NA',
31             'leading_digits' => '[89]',
32             'pattern' => '(\\d{6})'
33             },
34             {
35             'format' => '$1 $2 $3 $4',
36             'leading_digits' => '[5-7]',
37             'pattern' => '(\\d{2})(\\d{2})(\\d{2})(\\d{2})'
38             },
39             {
40             'format' => '$1 $2',
41             'pattern' => '(\\d{4})(\\d{6})'
42             }
43             ];
44              
45             my $validators = {
46             'fixed_line' => '
47             0549(?:
48             8[0157-9]|
49             9\\d
50             )\\d{4}
51             ',
52             'geographic' => '
53             0549(?:
54             8[0157-9]|
55             9\\d
56             )\\d{4}
57             ',
58             'mobile' => '6[16]\\d{6}',
59             'pager' => '',
60             'personal_number' => '',
61             'specialrate' => '(7[178]\\d{6})',
62             'toll_free' => '',
63             'voip' => '5[158]\\d{6}'
64             };
65              
66             sub new {
67 18     18 1 41 my $class = shift;
68 18         34 my $number = shift;
69 18         118 $number =~ s/(^\+378|\D)//g;
70 18         94 my $self = bless({ country_code => '378', number => $number, formatters => $formatters, validators => $validators, }, $class);
71 18 100       92 return $self if ($self->is_valid());
72 4         19 my $prefix = qr/^(?:([89]\d{5})$)/;
73 4         20 my @matches = $number =~ /$prefix/;
74 4 100       15 if (defined $matches[-1]) {
75 3     3   1009 no warnings 'uninitialized';
  3         14  
  3         455  
76 1         12 $number =~ s/$prefix/0549$1/;
77             }
78             else {
79 3         12 $number =~ s/$prefix//;
80             }
81 4         39 $self = bless({ country_code => '378', number => $number, formatters => $formatters, validators => $validators, }, $class);
82 4 100       17 return $self->is_valid() ? $self : undef;
83             }
84             1;