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   1826 use base qw(Number::Phone::StubCountry);
  3         9  
  3         331  
21              
22 3     3   22 use strict;
  3         11  
  3         68  
23 3     3   17 use warnings;
  3         10  
  3         78  
24 3     3   19 use utf8;
  3         13  
  3         19  
25             our $VERSION = 1.20230903131448;
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 45 my $class = shift;
68 18         37 my $number = shift;
69 18         124 $number =~ s/(^\+378|\D)//g;
70 18         99 my $self = bless({ country_code => '378', number => $number, formatters => $formatters, validators => $validators, }, $class);
71 18 100       110 return $self if ($self->is_valid());
72 4         22 my $prefix = qr/^(?:([89]\d{5})$)/;
73 4         19 my @matches = $number =~ /$prefix/;
74 4 100       20 if (defined $matches[-1]) {
75 3     3   909 no warnings 'uninitialized';
  3         11  
  3         499  
76 1         8 $number =~ s/$prefix/0549$1/;
77             }
78             else {
79 3         12 $number =~ s/$prefix//;
80             }
81 4         41 $self = bless({ country_code => '378', number => $number, formatters => $formatters, validators => $validators, }, $class);
82 4 100       21 return $self->is_valid() ? $self : undef;
83             }
84             1;