lib/FP/Cmp.pm

filter: Statementstmt 83.7% 36 / 43 Branchbran 25.0% 1 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 84.6% 11 / 13 Podpod 0.0% 0 / 2 totaltotal 77.4% 48 / 62 CC 4 SCAR 11.8
CC
4
Cov
79%
__ANON__
12.0
cmp_complement
2.0
cmp_then
2.0
CRAP 3.3
« lib/FP/Untainted.pm ↑ Summary lib/Chj/tempdir.pm »
1 #
2 # Copyright (c) 2013-2022 Christian Jaeger, copying@christianjaeger.ch
3 #
4 # This is free software, offered under either the same terms as perl 5
5 # or the terms of the Artistic License version 2 or the terms of the
6 # MIT License (Expat version). See the file COPYING.md that came
7 # bundled with this file.
8 #
9 #
10  
11 =head1 NAME
12  
13 FP::Cmp - 3-way comparison helpers
14  
15 =head1 SYNOPSIS
16  
17 =head1 DESCRIPTION
18  
19 =head1 SEE ALSO
20  
21 =head1 NOTE
22  
23 This is alpha software! Read the status section in the package README
24 or on the L<website|http://functional-perl.org/>.
25  
26 =cut
27  
28 package FP::Cmp;
29 60 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 60 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 60 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 60 ▶use warnings FATAL => 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
33  
34 #use experimental 'signatures';
35 60 ▶use Exporter "import";
Subroutine BEGIN: called CC=1 SCAR=0.0
36  
37 60 our @EXPORT = qw(cmp_complement cmp_then);
38 60 our @EXPORT_OK = qw();
39 60 our %EXPORT_TAGS = (default => \@EXPORT, all => [@EXPORT, @EXPORT_OK]);
40  
41 60 ▶use FP::Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
42 60 ▶use Chj::TEST;
Subroutine BEGIN: called CC=1 SCAR=0.0
43 60 ▶use FP::Ops qw(binary_operator);
Subroutine BEGIN: called CC=1 SCAR=0.0
44  
45 # see also `complement` from FP::Predicates
46 2 ▶sub cmp_complement {
Subroutine cmp_complement: called CC=2 SCAR=7.0
Pod undocumented
47 2 ▶ @_ == 1 or fp_croak_arity 1;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or fp_croak_arity(1) 2 0 2
48 2 my ($cmp) = @_;
49 9 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
50 9 -&$cmp(@_)
51 }
52 2 }
53  
54 1 ▶TEST {
Subroutine __ANON__: called CC=1 SCAR=0.0
55 1 my $f = cmp_complement binary_operator "cmp";
56 [
57 1 map { &$f(@$_) } (
58 [2, 4],
59 [4, 2],
60 [3, 3],
61 ["abc", "bbc"],
62 ["ab", "ab"],
63 ["bbc", "abc"]
64 )
65 ]
66 }
67 60 [1, -1, 0, 1, 0, -1];
68  
69 0 ▶sub cmp_then {
Subroutine cmp_then: not called CC=1 SCAR=6.9
Pod undocumented
70  
71 # chain of cmp until one is non-0
72 0 my @cmp = @_;
73 0 ▶ sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
74 0 my ($a, $b) = @_;
75 0 for my $cmp (@cmp) {
76 0 ▶ if (my $res = $cmp->($a, $b)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $res = &$cmp($a, $b)) 0 0 0
77 0 return $res
78 }
79 }
80 0
81 0 }
82 0 }
83  
84 60 1
« lib/FP/Untainted.pm ↑ Summary lib/Chj/tempdir.pm »