blib/lib/Quantum/Superpositions/Lazy.pm

filter: Statementstmt 98.1% 52 / 53 Branchbran 50.0% 2 / 4 Conditioncond 66.6% 8 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 100% 15 / 15 Podpod 87.5% 7 / 8 totaltotal 84.0% 84 / 100 CC 7 SCAR 7.0
CC
7
Cov
90%
run_sub_as
4.2
superpos
3.2
collapse
2.0
CRAP 2.0
« blib/lib/Quantum/Superpositions/Lazy/Util.pm ↑ Summary blib/lib/Quantum/Superpositions/Lazy/State.pm »
1 package Quantum::Superpositions::Lazy;
2 15 $Quantum::Superpositions::Lazy::VERSION = '1.12';
3 15 ▶use v5.24;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 15 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 15 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 15 ▶use Quantum::Superpositions::Lazy::Superposition;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 15 ▶use Quantum::Superpositions::Lazy::Operation::Logical;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 15 ▶use Quantum::Superpositions::Lazy::Util qw(is_collapsible);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 15 ▶use Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 15 our @EXPORT = qw(
12 superpos
13 );
14  
15 15 our @EXPORT_OK = qw(
16 collapse
17 any_state
18 every_state
19 one_state
20 fetch_matches
21 with_sources
22 );
23  
24 15 our %EXPORT_TAGS = (
25 all => [@EXPORT, @EXPORT_OK],
26 );
27  
28 15 our $global_reducer_type = "any";
29 15 our $global_compare_bool = 1;
30 15 our $global_sourced_calculations = 0;
31  
32 sub run_sub_as
33 46 ▶{
Subroutine run_sub_as: called CC=4 SCAR=14.2
Pod undocumented
34 46 my ($sub, %env) = @_;
35  
36 46 ▶ local $global_reducer_type = $env{reducer_type} // $global_reducer_type;
Condition66%2/3
$env{"reducer_type"} // $Quantum::Superpositions::Lazy::global_reducer_type
l!l&&r!l&&!r
27190
MC/DC0%0/2
$env{"reducer_type"} // $Quantum::Superpositions::Lazy::global_reducer_type
$env{"reducer_type"} $Quantum::Superpositions::Lazy::global_reducer_type
Truth table66%2/3
A // B
A= $env{"reducer_type"}B= $Quantum::Superpositions::Lazy::global_reducer_type
ABresult
1X1
011
000
37 46 ▶ local $global_compare_bool = $env{compare_bool} // $global_compare_bool;
Condition66%2/3
$env{"compare_bool"} // $Quantum::Superpositions::Lazy::global_compare_bool
l!l&&r!l&&!r
13330
MC/DC0%0/2
$env{"compare_bool"} // $Quantum::Superpositions::Lazy::global_compare_bool
$env{"compare_bool"} $Quantum::Superpositions::Lazy::global_compare_bool
Truth table66%2/3
A // B
A= $env{"compare_bool"}B= $Quantum::Superpositions::Lazy::global_compare_bool
ABresult
1X1
011
000
38 46 ▶ local $global_sourced_calculations = $env{sourced_calculations} // $global_sourced_calculations;
Condition66%2/3
$env{"sourced_calculations"} // $Quantum::Superpositions::Lazy::global_sourced_calculations
l!l&&r!l&&!r
6400
MC/DC0%0/2
$env{"sourced_calculations"} // $Quantum::Superpositions::Lazy::global_sourced_calculations
$env{"sourced_calculations"} $Quantum::Superpositions::Lazy::global_sourced_calculations
Truth table66%2/3
A // B
A= $env{"sourced_calculations"}B= $Quantum::Superpositions::Lazy::global_sourced_calculations
ABresult
1X1
011
000
39 46 return $sub->();
40 }
41  
42 sub superpos
43 71 ▶{
Subroutine superpos: called CC=3 SCAR=11.6
Pod documented
44 71 my (@positions) = @_;
45 71 my $positions_ref;
46  
47 71 ▶ if (@positions == 1 && ref $positions[0] eq ref []) {
Branch: 1 branch
BranchTrueFalseTotal
if (@positions == 1 and ref $positions[0] eq ref []) { } 0 71 71
Condition66%2/3
@positions == 1 and ref $positions[0] eq ref []
!ll&&!rl&&r
60110
MC/DC0%0/2
@positions == 1 and ref $positions[0] eq ref []
@positions == 1 ref $positions[0] eq ref []
Truth table66%2/3
A and B
A= @positions == 1B= ref $positions[0] eq ref []
ABresult
0X0
100
111
48 0 $positions_ref = $positions[0];
49 }
50 else {
51 71 $positions_ref = [@positions];
52 }
53  
54 71 return Quantum::Superpositions::Lazy::Superposition->new(
55 states => $positions_ref
56 );
57 }
58  
59 sub collapse
60 1 ▶{
Subroutine collapse: called CC=2 SCAR=7.0
Pod documented
61 1 my (@superpositions) = @_;
62  
63 return map {
64 1 ▶ croak "Element not collapsible"
Branch: 1 branch
BranchTrueFalseTotal
unless is_collapsible($_) 0 3 3
65 unless is_collapsible($_);
66 3 $_->collapse;
67 } @superpositions;
68 }
69  
70 sub any_state(&)
71 4 ▶{
Subroutine any_state: called CC=1 SCAR=0.0
Pod documented
72 4 my ($sub) = @_;
73  
74 4 return run_sub_as $sub, reducer_type => "any";
75 }
76  
77 sub every_state(&)
78 14 ▶{
Subroutine every_state: called CC=1 SCAR=0.0
Pod documented
79 14 my ($sub) = @_;
80  
81 14 return run_sub_as $sub, reducer_type => "all";
82 }
83  
84 sub one_state(&)
85 9 ▶{
Subroutine one_state: called CC=1 SCAR=0.0
Pod documented
86 9 my ($sub) = @_;
87  
88 9 return run_sub_as $sub, reducer_type => "one";
89 }
90  
91 sub fetch_matches(&)
92 13 ▶{
Subroutine fetch_matches: called CC=1 SCAR=0.0
Pod documented
93 13 my ($sub) = @_;
94  
95 13 return run_sub_as $sub, compare_bool => 0;
96 }
97  
98 sub with_sources(&)
99 6 ▶{
Subroutine with_sources: called CC=1 SCAR=0.0
Pod documented
100 6 my ($sub) = @_;
101  
102 6 return run_sub_as $sub, sourced_calculations => 1;
103 }
104  
105 15 1;
106 __END__
« blib/lib/Quantum/Superpositions/Lazy/Util.pm ↑ Summary blib/lib/Quantum/Superpositions/Lazy/State.pm »