| 1 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | package Data::Rx::Util; | ||||||||||
| 4 | # ABSTRACT: helper routines for Data::Rx | ||||||||||
| 5 | 2 | $Data::Rx::Util::VERSION = '0.200007'; | |||||||||
| 6 | 2 | ▶ | use Carp (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 2 | ▶ | use List::Util (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 2 | ▶ | use Number::Tolerant (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | sub _x_subset_keys_y { | ||||||||||
| 11 | 109 | ▶ | my ($self, $x, $y) = @_; | ||||||||
|
Subroutine
_x_subset_keys_y: called CC=4 SCAR=13.9
| |||||||||||
| 12 | |||||||||||
| 13 | 109 | ▶ | return unless keys %$x <= keys %$y; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 14 | |||||||||||
| 15 | 109 | for my $key (keys %$x) { | |||||||||
| 16 | 96 | ▶ | return unless exists $y->{$key}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 17 | } | ||||||||||
| 18 | |||||||||||
| 19 | 104 | return 1; | |||||||||
| 20 | } | ||||||||||
| 21 | |||||||||||
| 22 | sub _make_range_check { | ||||||||||
| 23 | 12 | ▶ | my ($self, $arg) = @_; | ||||||||
|
Subroutine
_make_range_check: called CC=7 SCAR=19.5
| |||||||||||
| 24 | |||||||||||
| 25 | 12 | 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 | ▶ | { map {; $_ => 1 } @keys }, | ||||||||
|
Branch: 1 branch
| |||||||||||
| 30 | ); | ||||||||||
| 31 | |||||||||||
| 32 | 12 | ▶ | return sub { 1 } unless keys %$arg; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||
| 33 | |||||||||||
| 34 | 11 | my @tolerances; | |||||||||
| 35 | push @tolerances, Number::Tolerant->new($arg->{min} => 'or_more') | ||||||||||
| 36 | 11 | ▶ | if exists $arg->{min}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | push @tolerances, Number::Tolerant->new(more_than => $arg->{'min-ex'}) | ||||||||||
| 38 | 11 | ▶ | if exists $arg->{'min-ex'}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | push @tolerances, Number::Tolerant->new($arg->{max} => 'or_less') | ||||||||||
| 40 | 11 | ▶ | if exists $arg->{max}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 41 | push @tolerances, Number::Tolerant->new(less_than => $arg->{'max-ex'}) | ||||||||||
| 42 | 11 | ▶ | if exists $arg->{'max-ex'}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 43 | |||||||||||
| 44 | 11 | my $tol = do { | |||||||||
| 45 | 2 | ▶ | no warnings 'once'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 46 | 11 | ▶ | List::Util::reduce { $a & $b } @tolerances; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 47 | }; | ||||||||||
| 48 | |||||||||||
| 49 | 11 | ▶ | return sub { $_[0] == $tol }; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 50 | } | ||||||||||
| 51 | |||||||||||
| 52 | 2 | 1; | |||||||||
| 53 | |||||||||||
| 54 | __END__ | ||||||||||