Rx/Util.pm

filter: Statementstmt 100% 41 / 41 Branchbran 81.2% 13 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 11 / 11 Podpod n/a totaltotal 95.5% 65 / 68 CC 10 SCAR 13.1
CC
10
Cov
95%
_make_range_check
7.0
_x_subset_keys_y
4.0
BEGIN
1.0
CRAP 3.7
« Rx/CoreType/one.pm ↑ Summary Rx/CoreType/all.pm »
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
BranchTrueFalseTotal
unless keys %$x <= keys %$y 0 109 109
14  
15 109 for my $key (keys %$x) {
16 96 ▶ return unless exists $y->{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $y->{$key} 5 91 96
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
BranchTrueFalseTotal
unless $self->_x_subset_keys_y($arg, {map({$_, 1;} @keys)}) 0 12 12
30 );
31  
32 12 ▶ return sub { 1 } unless keys %$arg;
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
unless keys %$arg 1 11 12
33  
34 11 my @tolerances;
35 push @tolerances, Number::Tolerant->new($arg->{min} => 'or_more')
36 11 ▶ if exists $arg->{min};
Branch: 1 branch
BranchTrueFalseTotal
if exists $arg->{"min"} 5 6 11
37 push @tolerances, Number::Tolerant->new(more_than => $arg->{'min-ex'})
38 11 ▶ if exists $arg->{'min-ex'};
Branch: 1 branch
BranchTrueFalseTotal
if exists $arg->{"min-ex"} 2 9 11
39 push @tolerances, Number::Tolerant->new($arg->{max} => 'or_less')
40 11 ▶ if exists $arg->{max};
Branch: 1 branch
BranchTrueFalseTotal
if exists $arg->{"max"} 11 0 11
41 push @tolerances, Number::Tolerant->new(less_than => $arg->{'max-ex'})
42 11 ▶ if exists $arg->{'max-ex'};
Branch: 1 branch
BranchTrueFalseTotal
if exists $arg->{"max-ex"} 1 10 11
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__
« Rx/CoreType/one.pm ↑ Summary Rx/CoreType/all.pm »