examples/predicates

filter: Statementstmt 96.9% 96 / 99 Branchbran 50.0% 3 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 97.1% 34 / 35 Podpod n/a totaltotal 95.0% 133 / 140 CC 3 SCAR 1.9
CC
3
Cov
94%
BEGIN
3.2
__ANON__
2.0
__ANON__
1.1
CRAP 1.2
« .htmlgen/FunctionalPerl/Htmlgen/PXMLMapper.pm ↑ Summary website/logo.pl »
1 #!/usr/bin/env perl
2  
3 # Copyright (c) 2015-2020 Christian Jaeger, copying@christianjaeger.ch
4 # This is free software. See the file COPYING.md that came bundled
5 # with this file.
6  
7 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use warnings FATAL => 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 # find modules from functional-perl working directory (not installed)
12 1 ▶use Cwd 'abs_path';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 our ($mydir, $myname);
14  
15 1 ▶BEGIN {
Subroutine BEGIN: called CC=3 SCAR=11.7
16 1 ▶ my $location = (-l $0) ? abs_path($0) : $0;
Branch: 1 branch
BranchTrueFalseTotal
-l $0 ? : 0 1 1
17 1 ▶ $location =~ /(.*?)([^\/]+?)_?\z/s or die "?";
Branch: 1 branch
BranchTrueFalseTotal
$location =~ m[(.*?)([^/]+?)_?\z]s or die "?" 1 0 1
18 1 ($mydir, $myname) = ($1, $2);
19 }
20 1 ▶use lib "$mydir/../lib";
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 1 ▶use Chj::TEST;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 ▶use Chj::Backtrace;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 {
26  
27 package Foo;
28 1 ▶ use FP::Predicates;
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 1 ▶ BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
31 2 ▶ *is_age = both \&is_natural0, sub { $_[0] < 130 }
Subroutine __ANON__: called CC=1 SCAR=0.0
32 1 }
33  
34 1 ▶ use FP::Struct [[\&is_string, "name"], [\&is_age, "age"]];
Subroutine BEGIN: called CC=1 SCAR=0.0
35 1 _END_
36 }
37  
38 {
39  
40 1 package Bar;
41 1 ▶ use FP::Predicates;
Subroutine BEGIN: called CC=1 SCAR=0.0
42  
43 1 ▶ use FP::Struct [[\&is_string, "name"],
Subroutine BEGIN: called CC=1 SCAR=0.0
44 1 [both(\&is_natural0, less_than 130), "age"]];
45 1 _END_
46 }
47  
48 2 ▶sub test {
Subroutine test: called CC=1 SCAR=0.0
49 2 my ($class) = @_;
50  
51 2 my $f = $class->new("Heinz", 105);
52 2 ▶ TEST { $f->age }
Subroutine __ANON__: called CC=1 SCAR=0.0
53 2 105;
54 2 ▶ TEST {
Subroutine __ANON__: called CC=1 SCAR=0.0
55 # check namespace cleaning
56 2 $f->can("is_age")
57 }
58 2 undef;
59 2 ▶ TEST_EXCEPTION { $f = $class->new("Maria", 1300) }
Subroutine __ANON__: called CC=1 SCAR=0.0
60 2 'unacceptable value for field \'age\': 1300';
61 2 ▶ TEST_EXCEPTION { $f = $class->new("Maria", 104.5) }
Subroutine __ANON__: called CC=1 SCAR=0.0
62 2 'unacceptable value for field \'age\': \'104.5\'';
63 }
64  
65 1 test "Foo";
66 1 test "Bar";
67  
68 1 ▶use FP::Predicates;
Subroutine BEGIN: called CC=1 SCAR=0.0
69 1 ▶use FP::List;
Subroutine BEGIN: called CC=1 SCAR=0.0
70 1 ▶use FP::PureArray;
Subroutine BEGIN: called CC=1 SCAR=0.0
71  
72 1 ▶TEST { is_pure 11 }
Subroutine __ANON__: called CC=1 SCAR=0.0
73 1 1;
74  
75 1 ▶TEST { my $x = 11; $x++; is_pure $x }
Subroutine __ANON__: called CC=1 SCAR=0.0
76 1 1;
77  
78 1 ▶TEST { my $x = 11; $x++; is_pure_object $x }
Subroutine __ANON__: called CC=1 SCAR=0.0
79 1 undef;
80  
81 1 ▶TEST { is_pure cons 1, 2 }
Subroutine __ANON__: called CC=1 SCAR=0.0
82 1 1;
83  
84 1 ▶TEST { is_pure_object cons 1, 2 }
Subroutine __ANON__: called CC=1 SCAR=0.0
85 1 1;
86  
87 1 ▶TEST { is_pure [1, 2] }
Subroutine __ANON__: called CC=1 SCAR=0.0
88 1 '';
89  
90 1 ▶TEST { is_pure purearray 1, 2 }
Subroutine __ANON__: called CC=1 SCAR=0.0
91 1 1;
92  
93 1 ▶use FP::Lazy;
Subroutine BEGIN: called CC=1 SCAR=0.0
94  
95 1 ▶TEST {
Subroutine __ANON__: called CC=1 SCAR=1.2
96 0 ▶ is_pure lazy { cons 1, 2 }
Subroutine __ANON__: not called CC=1 SCAR=6.9
97 1 }
98 1 0; # or should it force it? XX or (wildly) assume that lazy
99 # expressions are always returning pure values?
100  
101 1 ▶use FP::OrderedCollection; # based on FP::Struct
Subroutine BEGIN: called CC=1 SCAR=0.0
102  
103 1 my $a = [1, 2];
104  
105 1 ▶TEST { is_pure(FP::OrderedCollection->unsafe_new_from_array($a)) }
Subroutine __ANON__: called CC=1 SCAR=0.0
106 1 1; # this assumes that the array passed in is not mutated by the
107 # caller!
108  
109 1 ▶TEST { is_pure(FP::OrderedCollection->new_from_array($a)) }
Subroutine __ANON__: called CC=1 SCAR=0.0
110 1 1; # this copies the array, hence is always safe
111  
112 1 ▶perhaps_run_tests "main" or do {
Branch: 1 branch
BranchTrueFalseTotal
perhaps_run_tests("main") or do { require FP::Repl; FP::Repl::repl() } 1 0 1
113 0 require FP::Repl;
114 0 FP::Repl::repl();
115 }
« .htmlgen/FunctionalPerl/Htmlgen/PXMLMapper.pm ↑ Summary website/logo.pl »