File Coverage

blib/lib/Data/Rx/Util.pm
Criterion Covered Total %
statement 39 39 100.0
branch 13 16 81.2
condition n/a
subroutine 11 11 100.0
pod n/a
total 63 66 95.4


line stmt bran cond sub pod time code
1 2     2   13079 use strict;
  2         4  
  2         50  
2 2     2   5 use warnings;
  2         2  
  2         63  
3             package Data::Rx::Util;
4             # ABSTRACT: helper routines for Data::Rx
5             $Data::Rx::Util::VERSION = '0.200007';
6 2     2   6 use Carp ();
  2         2  
  2         42  
7 2     2   6 use List::Util ();
  2         2  
  2         31  
8 2     2   824 use Number::Tolerant ();
  2         26523  
  2         364  
9              
10             sub _x_subset_keys_y {
11 109     109   131 my ($self, $x, $y) = @_;
12              
13 109 50       438 return unless keys %$x <= keys %$y;
14              
15 109         377 for my $key (keys %$x) {
16 96 100       723 return unless exists $y->{$key};
17             }
18              
19 104         547 return 1;
20             }
21              
22             sub _make_range_check {
23 12     12   208 my ($self, $arg) = @_;
24              
25 12         38 my @keys = qw(min min-ex max-ex max);
26              
27             Carp::croak "unknown arguments" unless $self->_x_subset_keys_y(
28             $arg,
29 12 50       23 { map {; $_ => 1 } @keys },
  48         118  
30             );
31              
32 12 100   13   46 return sub { 1 } unless keys %$arg;
  13         38  
33              
34 11         13 my @tolerances;
35 11 100       55 push @tolerances, Number::Tolerant->new($arg->{min} => 'or_more')
36             if exists $arg->{min};
37 11 100       57018 push @tolerances, Number::Tolerant->new(more_than => $arg->{'min-ex'})
38             if exists $arg->{'min-ex'};
39 11 50       360 push @tolerances, Number::Tolerant->new($arg->{max} => 'or_less')
40             if exists $arg->{max};
41 11 100       66135 push @tolerances, Number::Tolerant->new(less_than => $arg->{'max-ex'})
42             if exists $arg->{'max-ex'};
43            
44 11         104 my $tol = do {
45 2     2   11 no warnings 'once';
  2         3  
  2         186  
46 11     8   97 List::Util::reduce { $a & $b } @tolerances;
  8         324  
47             };
48            
49 11     77   551 return sub { $_[0] == $tol };
  77         2144  
50             }
51              
52             1;
53              
54             __END__