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   41798 use strict;
  2         6  
  2         72  
2 2     2   10 use warnings;
  2         4  
  2         99  
3             package Data::Rx::Util;
4             # ABSTRACT: helper routines for Data::Rx
5             $Data::Rx::Util::VERSION = '0.200006';
6 2     2   12 use Carp ();
  2         3  
  2         29  
7 2     2   19 use List::Util ();
  2         2  
  2         44  
8 2     2   6182 use Number::Tolerant ();
  2         53092  
  2         682  
9              
10             sub _x_subset_keys_y {
11 109     109   208 my ($self, $x, $y) = @_;
12              
13 109 50       376 return unless keys %$x <= keys %$y;
14              
15 109         480 for my $key (keys %$x) {
16 97 100       1295 return unless exists $y->{$key};
17             }
18              
19 104         420 return 1;
20             }
21              
22             sub _make_range_check {
23 12     12   389 my ($self, $arg) = @_;
24              
25 12         53 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       29 { map {; $_ => 1 } @keys },
  48         166  
30             );
31              
32 12 100   13   60 return sub { 1 } unless keys %$arg;
  13         74  
33              
34 11         19 my @tolerances;
35 11 100       72 push @tolerances, Number::Tolerant->new($arg->{min} => 'or_more')
36             if exists $arg->{min};
37 11 100       126144 push @tolerances, Number::Tolerant->new(more_than => $arg->{'min-ex'})
38             if exists $arg->{'min-ex'};
39 11 50       741 push @tolerances, Number::Tolerant->new($arg->{max} => 'or_less')
40             if exists $arg->{max};
41 11 100       150799 push @tolerances, Number::Tolerant->new(less_than => $arg->{'max-ex'})
42             if exists $arg->{'max-ex'};
43            
44 11         134 my $tol = do {
45 2     2   22 no warnings 'once';
  2         4  
  2         287  
46 11     8   149 List::Util::reduce { $a & $b } @tolerances;
  8         479  
47             };
48            
49 11     77   716 return sub { $_[0] == $tol };
  77         5321  
50             }
51              
52             1;
53              
54             __END__