File Coverage

blib/lib/Data/Sah/Filter/perl/Float/ceil.pm
Criterion Covered Total %
statement 8 18 44.4
branch 0 4 0.0
condition 0 4 0.0
subroutine 3 5 60.0
pod 0 2 0.0
total 11 33 33.3


line stmt bran cond sub pod time code
1             package Data::Sah::Filter::perl::Float::ceil;
2              
3 1     1   334323 use 5.010001;
  1         4  
4 1     1   6 use strict;
  1         1  
  1         23  
5 1     1   8 use warnings;
  1         1  
  1         276  
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 => 'Round number to the nearest integer (or "nearest" argument) that is greater than the number',
16             args => {
17             nearest => {
18             schema => 'ufloat*',
19             },
20             },
21             examples => [
22             {value=>1, filtered_value=>1},
23             {value=>-1.1, filtered_value=>-1},
24             {value=>1.1, filtered_value=>2},
25             {value=>1.1, filter_args=>{nearest=>0.5}, filtered_value=>1.5},
26             ],
27             };
28             }
29              
30             sub filter {
31 0     0 0   my %fargs = @_;
32              
33 0           my $dt = $fargs{data_term};
34 0   0       my $gen_args = $fargs{args} // {};
35 0           my $nearest = $gen_args->{nearest};
36 0 0         $nearest += 0 if defined $nearest;
37              
38 0           my $res = {};
39 0   0       $res->{modules}{POSIX} //= 0;
40 0 0         $res->{expr_filter} = join(
41             "",
42             defined($nearest) ? "POSIX::ceil($dt/$nearest)*$nearest" : "POSIX::ceil($dt)",
43             );
44              
45 0           $res;
46             }
47              
48             1;
49             # ABSTRACT: Round number to the nearest integer (or "nearest" argument) that is greater than the number
50              
51             __END__