lib/FP/Abstract/Compare.pm

filter: Statementstmt 95.8% 23 / 24 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 88.8% 8 / 9 Podpod 0.0% 0 / 1 totaltotal 91.1% 31 / 34 CC 1 SCAR 1.1
CC
1
Cov
96%
FP_Interface__method_names
2.0
BEGIN
1.0
FP_Compare_compare
1.0
CRAP 1.1
« lib/PXML/Preserialize/t.pm ↑ Summary functional_XML/t/div »
1 #
2 # Copyright (c) 2020 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 =head1 NAME
11  
12 FP::Abstract::Compare - comparison protocol
13  
14 =head1 SYNOPSIS
15  
16 package FPCompareExample::Foo {
17 1 ▶ use FP::Struct ["num"];
Subroutine BEGIN: called CC=1 SCAR=0.0
18 11 ▶ sub FP_Compare_compare {
Subroutine FP_Compare_compare: called CC=1 SCAR=0.0
19 11 my ($a, $b) = @_;
20 # let's make the default sort order reversed for the sake
21 # of a more interesting example:
22 11 $b->num cmp $a->num
23 }
24 _END_
25 }
26  
27 1 ▶ use FP::PureArray; use FP::Ops 'the_method'; use FP::Equal qw(is_equal);
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
28 is_equal( purearray(2,3,-7,4,2,8)
29 ->map(\&FPCompareExample::Foo::c::Foo)
30 ->sortCompare
31 ->map(the_method("num")),
32 purearray(8, 4, 3, 2, 2, -7));
33  
34 =head1 DESCRIPTION
35  
36 Objects implementing this protocol can be ordered unambiguously.
37  
38 The `$a->FP_Compare_compare($b)` returns -1 if $a is to be ordered before
39 $b (is smaller), 0 if they are to be ordered into the same position, 1
40 if $a is to be ordered after $b.
41  
42 This method is used for the default sort order by the `sort` method
43 offered on sequences.
44  
45 =head1 SEE ALSO
46  
47 L<FP::Compare>
48  
49 =head1 NOTE
50  
51 This is alpha software! Read the status section in the package README
52 or on the L<website|http://functional-perl.org/>.
53  
54 =cut
55  
56 package FP::Abstract::Compare;
57  
58 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
59 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
60 1 ▶use warnings FATAL => 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
61  
62 0 ▶sub FP_Interface__method_names { ("FP_Compare_compare") }
Subroutine FP_Interface__method_names: not called CC=1 SCAR=6.9
Pod undocumented
63  
64 1
« lib/PXML/Preserialize/t.pm ↑ Summary functional_XML/t/div »