File Coverage

blib/lib/Data/Sah/Filter/perl/Str/remove_nondigit.pm
Criterion Covered Total %
statement 8 14 57.1
branch n/a
condition n/a
subroutine 3 5 60.0
pod 0 2 0.0
total 11 21 52.3


line stmt bran cond sub pod time code
1             package Data::Sah::Filter::perl::Str::remove_nondigit;
2              
3 1     1   440360 use 5.010001;
  1         5  
4 1     1   7 use strict;
  1         3  
  1         35  
5 1     1   5 use warnings;
  1         7  
  1         1077  
6              
7             our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
8             our $DATE = '2024-07-17'; # DATE
9             our $DIST = 'Data-Sah-Filter'; # DIST
10             our $VERSION = '0.025'; # VERSION
11              
12             sub meta {
13             +{
14 0     0 0   v => 1,
15             summary => 'Remove non-digit characters',
16             examples => [
17             {value=>"5551234567"},
18             {value=>"555-123-4567", filtered_value=>"5551234567"},
19             {value=>"(555) 123-4567", filtered_value=>"5551234567"},
20             ],
21             };
22             }
23              
24             sub filter {
25 0     0 0   my %fargs = @_;
26              
27 0           my $dt = $fargs{data_term};
28              
29 0           my $res = {};
30 0           $res->{expr_filter} = join(
31             "",
32             "do { ", (
33             "my \$tmp = $dt; ",
34             "\$tmp =~ s/\\D+//g; ",
35             "\$tmp ",
36             ), "}",
37             );
38              
39 0           $res;
40             }
41              
42             1;
43             # ABSTRACT: Remove non-digit characters
44              
45             __END__