lib/FP/Div.pm

filter: Statementstmt 76.0% 38 / 50 Branchbran 35.0% 7 / 20 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 80.0% 12 / 15 Podpod 0.0% 0 / 9 totaltotal 60.6% 57 / 94 CC 14 SCAR 16.4
CC
14
Cov
64%
minmax
20.0
average
6.0
Chomp
6.0
CRAP 5.2
« .htmlgen/FunctionalPerl/Htmlgen/Mediawiki.pm ↑ Summary lib/Chj/pp.pm »
1 #
2 # Copyright (c) 2014-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::Div - various pure functions
13  
14 =head1 SYNOPSIS
15  
16 =head1 DESCRIPTION
17  
18  
19 =head1 NOTE
20  
21 This is alpha software! Read the status section in the package README
22 or on the L<website|http://functional-perl.org/>.
23  
24 =cut
25  
26 package FP::Div;
27 80 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 80 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 80 ▶use warnings FATAL => 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
30 80 ▶use Exporter "import";
Subroutine BEGIN: called CC=1 SCAR=0.0
31  
32 80 our @EXPORT = qw();
33 80 our @EXPORT_OK = qw(inc dec square average
34 identity
35 min max minmax
36 Chomp
37 );
38 80 our %EXPORT_TAGS = (all => [@EXPORT, @EXPORT_OK]);
39  
40 80 ▶use Chj::TEST;
Subroutine BEGIN: called CC=1 SCAR=0.0
41 80 ▶use FP::Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
42  
43 # XX should `indentity` pass multiple values, and this be called
44 # `identity_scalar`? :
45  
46 24 ▶sub identity {
Subroutine identity: called CC=2 SCAR=7.2
Pod undocumented
47 24 ▶ @_ == 1 or fp_croak_arity 1;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or fp_croak_arity(1) 24 0 24
48 24 $_[0]
49 }
50  
51 53 ▶sub inc {
Subroutine inc: called CC=2 SCAR=7.2
Pod undocumented
52 53 ▶ @_ == 1 or fp_croak_arity 1;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or fp_croak_arity(1) 53 0 53
53 53 $_[0] + 1
54 }
55  
56 20 ▶sub dec {
Subroutine dec: called CC=2 SCAR=7.2
Pod undocumented
57 20 ▶ @_ == 1 or fp_croak_arity 1;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or fp_croak_arity(1) 20 0 20
58 20 $_[0] - 1
59 }
60  
61 4 ▶sub square {
Subroutine square: called CC=2 SCAR=7.2
Pod undocumented
62 4 ▶ @_ == 1 or fp_croak_arity 1;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or fp_croak_arity(1) 4 0 4
63 4 $_[0] * $_[0]
64 }
65  
66 0 ▶sub average {
Subroutine average: not called CC=2 SCAR=17.9
Pod undocumented
67 0 ▶ @_ == 2 or fp_croak_arity 2;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or fp_croak_arity(2) 0 0 0
68 0 ($_[0] + $_[1]) / 2
69 }
70  
71 282 ▶sub min {
Subroutine min: called CC=3 SCAR=11.0
Pod undocumented
72 282 my $x = shift;
73 282 for (@_) {
74 19 ▶ $x = $_ if $_ < $x
Branch: 1 branch
BranchTrueFalseTotal
if $_ < $x 13 6 19
75 }
76 $x
77 282 }
78  
79 5 ▶sub max {
Subroutine max: called CC=3 SCAR=11.1
Pod undocumented
80 5 my $x = shift;
81 5 for (@_) {
82 2 ▶ $x = $_ if $_ > $x
Branch: 1 branch
BranchTrueFalseTotal
if $_ > $x 2 0 2
83 }
84 $x
85 5 }
86  
87 0 ▶sub minmax {
Subroutine minmax: not called CC=4 SCAR=30.0
Pod undocumented
88 0 my $min = shift;
89 0 my $max = $min;
90 0 for (@_) {
91 0 ▶ $min = $_ if $_ < $min;
Branch: 1 branch
BranchTrueFalseTotal
if $_ < $min 0 0 0
92 0 ▶ $max = $_ if $_ > $max;
Branch: 1 branch
BranchTrueFalseTotal
if $_ > $max 0 0 0
93 }
94 0 ($min, $max)
95 }
96  
97 # is there any better idea than ucfirst to distinguish from the
98 # builtin? `fchomp` ?
99 0 ▶sub Chomp {
Subroutine Chomp: not called CC=2 SCAR=17.9
Pod undocumented
100 0 ▶ @_ == 1 or fp_croak_arity 1;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or fp_croak_arity(1) 0 0 0
101 0 my ($str) = @_;
102 0 chomp $str;
103 0 $str
104 }
105  
106 80 1
« .htmlgen/FunctionalPerl/Htmlgen/Mediawiki.pm ↑ Summary lib/Chj/pp.pm »