File Coverage

blib/lib/Quantum/Superpositions/Lazy.pm
Criterion Covered Total %
statement 44 45 97.7
branch 2 4 50.0
condition 9 12 75.0
subroutine 15 15 100.0
pod 7 8 87.5
total 77 84 91.6


line stmt bran cond sub pod time code
1             package Quantum::Superpositions::Lazy;
2             $Quantum::Superpositions::Lazy::VERSION = '1.12';
3 15     15   585599 use v5.24;
  15         128  
4 15     15   99 use warnings;
  15         52  
  15         525  
5 15     15   108 use Carp qw(croak);
  15         26  
  15         653  
6 15     15   6178 use Quantum::Superpositions::Lazy::Superposition;
  15         50  
  15         480  
7 15     15   105 use Quantum::Superpositions::Lazy::Operation::Logical;
  15         27  
  15         419  
8 15     15   74 use Quantum::Superpositions::Lazy::Util qw(is_collapsible);
  15         29  
  15         678  
9 15     15   78 use Exporter qw(import);
  15         28  
  15         7792  
10              
11             our @EXPORT = qw(
12             superpos
13             );
14              
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             our %EXPORT_TAGS = (
25             all => [@EXPORT, @EXPORT_OK],
26             );
27              
28             our $global_reducer_type = "any";
29             our $global_compare_bool = 1;
30             our $global_sourced_calculations = 0;
31              
32             sub run_sub_as
33             {
34 46     46 0 131 my ($sub, %env) = @_;
35              
36 46   66     184 local $global_reducer_type = $env{reducer_type} // $global_reducer_type;
37 46   100     220 local $global_compare_bool = $env{compare_bool} // $global_compare_bool;
38 46   66     161 local $global_sourced_calculations = $env{sourced_calculations} // $global_sourced_calculations;
39 46         116 return $sub->();
40             }
41              
42             sub superpos
43             {
44 71     71 1 27417 my (@positions) = @_;
45 71         128 my $positions_ref;
46              
47 71 50 66     317 if (@positions == 1 && ref $positions[0] eq ref []) {
48 0         0 $positions_ref = $positions[0];
49             }
50             else {
51 71         965 $positions_ref = [@positions];
52             }
53              
54 71         1298 return Quantum::Superpositions::Lazy::Superposition->new(
55             states => $positions_ref
56             );
57             }
58              
59             sub collapse
60             {
61 1     1 1 74 my (@superpositions) = @_;
62              
63             return map {
64 1 50       2 croak "Element not collapsible"
  3         48  
65             unless is_collapsible($_);
66 3         58 $_->collapse;
67             } @superpositions;
68             }
69              
70             sub any_state(&)
71             {
72 4     4 1 9 my ($sub) = @_;
73              
74 4         8 return run_sub_as $sub, reducer_type => "any";
75             }
76              
77             sub every_state(&)
78             {
79 14     14 1 252 my ($sub) = @_;
80              
81 14         39 return run_sub_as $sub, reducer_type => "all";
82             }
83              
84             sub one_state(&)
85             {
86 9     9 1 105 my ($sub) = @_;
87              
88 9         20 return run_sub_as $sub, reducer_type => "one";
89             }
90              
91             sub fetch_matches(&)
92             {
93 13     13 1 25557 my ($sub) = @_;
94              
95 13         41 return run_sub_as $sub, compare_bool => 0;
96             }
97              
98             sub with_sources(&)
99             {
100 6     6 1 8220 my ($sub) = @_;
101              
102 6         23 return run_sub_as $sub, sourced_calculations => 1;
103             }
104              
105             1;
106             __END__