blib/lib/JQ/Lite/Builtin/Math.pm

filter: Statementstmt 100% 47 / 47 Branchbran 75.0% 12 / 16 Conditioncond 100% 6 / 6 MC/DCmcdc 100% 3 / 3 Subroutinesub 100% 11 / 11 Podpod 0.0% 0 / 1 totaltotal 94.0% 79 / 84 CC 11 SCAR 13.7
CC
11
Cov
94%
__ANON__
6.2
__ANON__
6.0
register
1.0
CRAP 3.9
« blib/lib/JQ/Lite/Tokenizer.pm ↑ Summary blib/lib/JQ/Lite/Builtin/Array.pm »
1 package JQ::Lite::Builtin::Math;
2  
3 182 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 182 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 182 ▶use Scalar::Util qw(looks_like_number);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 182 ▶use JQ::Lite::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 136 ▶sub register {
Subroutine register: called CC=1 SCAR=0.0
Pod undocumented
10 136 my ($class, $register) = @_;
11  
12 2 ▶ $register->('abs', sub {
Subroutine __ANON__: called CC=6 SCAR=18.3
13 2 my ($owner, $inputs) = @_;
14 return [ map {
15 !defined($_) ? undef
16 : !ref($_) ? (looks_like_number($_) ? abs($_) : $_)
17 : ref($_) eq 'ARRAY'
18 2 ▶ ? [ map { looks_like_number($_) ? abs($_) : $_ } @{$_} ]
Branch: 5 branches
BranchTrueFalseTotal
!defined($_) ? : 0 2 2
!ref($_) ? : 1 1 2
&looks_like_number($_) ? : 1 0 1
ref $_ eq 'ARRAY' ? : 1 0 1
&looks_like_number($_) ? : 3 1 4
19 : $_
20 2 } @{$inputs} ];
21 136 });
22 136 $register->(['ceil', 'ceil()'], _numeric(\&JQ::Lite::Util::_ceil));
23 136 $register->(['floor', 'floor()'], _numeric(\&JQ::Lite::Util::_floor));
24 136 $register->(['round', 'round()'], _numeric(\&JQ::Lite::Util::_round));
25 136 $register->(['to_number', 'to_number()'], _map(\&JQ::Lite::Util::_apply_to_number));
26 136 $register->(['tonumber', 'tonumber()'], _map(\&JQ::Lite::Util::_tonumber));
27 12 ▶ $register->(qr/^clamp\((.*)\)$/, sub {
Subroutine __ANON__: called CC=6 SCAR=17.9
28 12 my ($owner, $inputs, $arguments) = @_;
29 12 my @args = JQ::Lite::Util::_parse_arguments($arguments);
30 12 ▶ my $min = @args ? JQ::Lite::Util::_normalize_numeric_bound($args[0]) : undef;
Branch: 1 branch
BranchTrueFalseTotal
@args ? : 12 0 12
31 12 ▶ my $max = @args > 1 ? JQ::Lite::Util::_normalize_numeric_bound($args[1]) : undef;
Branch: 1 branch
BranchTrueFalseTotal
@args > 1 ? : 11 1 12
32 12 ▶ ($min, $max) = ($max, $min) if defined($min) && defined($max) && $min > $max;
Branch: 1 branch
BranchTrueFalseTotal
if defined $min and defined $max and $min > $max 1 11 12
Condition100%6/6
defined $min and defined $max and $min > $max
!ll&&!rl&&r
291
defined $min and defined $max
!ll&&!rl&&r
1110
MC/DC100%3/3
defined $min and defined $max and $min > $max
defined $min defined $max $min > $max
Truth table100%4/4
A and B and C
A= defined $minB= defined $maxC= $min > $max
ABCresult
0XX0
10X0
1100
1111
33 12 return [ map { JQ::Lite::Util::_apply_clamp($_, $min, $max) } @{$inputs} ];
34 136 });
35 }
36  
37 408 ▶sub _numeric {
Subroutine _numeric: called CC=1 SCAR=0.0
38 408 my ($function) = @_;
39 16 ▶ return sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
40 16 my ($owner, $inputs) = @_;
41 16 return [ map { JQ::Lite::Util::_apply_numeric_function($_, $function) } @{$inputs} ];
42 408 };
43 }
44  
45 272 ▶sub _map {
Subroutine _map: called CC=1 SCAR=0.0
46 272 my ($function) = @_;
47 9 ▶ return sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
48 9 my ($owner, $inputs) = @_;
49 9 return [ map { $function->($_) } @{$inputs} ];
50 272 };
51 }
52  
53 182 1;
« blib/lib/JQ/Lite/Tokenizer.pm ↑ Summary blib/lib/JQ/Lite/Builtin/Array.pm »