Cascade/Value.pm

filter: Statementstmt 79.6% 47 / 59 Branchbran 50.0% 6 / 12 Conditioncond 60.0% 3 / 5 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 76.9% 10 / 13 Podpod 66.6% 4 / 6 totaltotal 72.4% 71 / 98 SCAR 23.5
CC
9
Cov
74%
state_as_str
20.0
thrown_from_code
6.0
new
3.1
CRAP 10.5
« Cascade/Target.pm ↑ Summary
1 package CHI::Cascade::Value;
2  
3 15 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 15 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 15 my %states = (
7 # value = undef -> no in cache
8 CASCADE_NO_CACHE => 1 << 0,
9  
10 # value = undef | old_value -> other process is computing this target or its any dependencies
11 CASCADE_COMPUTING => 1 << 1,
12  
13 # value = undef | old_value -> recomputing is deferred
14 CASCADE_DEFERRED => 1 << 2,
15  
16 # value = old_value | actual_value -> the value from cache (not computed now)
17 CASCADE_FROM_CACHE => 1 << 3,
18  
19 # value = actual_value -> this value is actual
20 CASCADE_ACTUAL_VALUE => 1 << 4,
21  
22 # value = actual_value & recomuted now -> this value is recomputed right now
23 CASCADE_RECOMPUTED => 1 << 5,
24  
25 # value = undef | old_value | value passed by exception -> code of target or code of any dependencies has raised an exception
26 CASCADE_CODE_EXCEPTION => 1 << 6,
27  
28 # value = old_value | actual_value - value may be actual or not but actual term isn valid (only if 'run' is run with 'actual_term' option)
29 CASCADE_ACTUAL_TERM => 1 << 7,
30  
31 # Some dependencies are affected for recomputing, but no recomputing now - only TTL period and value from cache
32 CASCADE_TTL_INVOLVED => 1 << 8
33 );
34  
35 15 for ( keys %states ) {
36 15 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
37 15 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
38  
39 135 my $bit = $states{$_};
40  
41 0 ▶ *{ $_ } = sub () { $bit }
Subroutine __ANON__: not called CC=1 SCAR=1.2
42 135 }
43  
44  
45 15 ▶use parent 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
46  
47 {
48 15 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
49  
50 our %EXPORT_TAGS = (
51 15 ▶ state => [ map { "$_" } grep { /^CASCADE_/ && *{$_}{CODE} } keys %{ __PACKAGE__ . "::" } ]
Branch: 1 branch
BranchTrueFalseTotal
/^CASCADE_/ and *{$_;}{"CODE"} 135 150 285
52 );
53 15 Exporter::export_ok_tags( keys %EXPORT_TAGS );
54 }
55  
56 sub new {
57 20 ▶ my ($class, %opts) = @_;
Subroutine new: called CC=3 SCAR=11.3
Pod undocumented
58  
59 20 ▶ my $self = bless { %opts }, ref($class) || $class;
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
0200
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
60  
61 20 ▶ $self->{state} ||= 0;
Condition100%2/2
$self->{"state"} ||= 0
l!l
128
MC/DC100%1/1
$self->{"state"} ||= 0
$self->{"state"}
Truth table100%2/2
A
A= $self->{"state"}
Aresult
11
00
62  
63 20 $self;
64 }
65  
66 sub is_value {
67 36 ▶ shift->{is_value};
Subroutine is_value: called CC=1 SCAR=0.0
Pod documented
68 }
69  
70 sub state {
71 51 ▶ my $self = shift;
Subroutine state: called CC=2 SCAR=6.9
Pod documented
72  
73 51 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 24 27 51
74 24 $self->{state} |= $_[0];
75 24 return $self;
76 }
77 27 $self->{state};
78 }
79  
80 sub state_as_str {
81 0 ▶ my $state = $_[1];
Subroutine state_as_str: not called CC=4 SCAR=30.0
Pod documented
82  
83 0 ▶ return '' if ! $state;
Branch: 1 branch
BranchTrueFalseTotal
unless $state 0 0 0
84  
85 0 my @names;
86  
87 0 for ( keys %states ) {
88 push @names, $_
89 0 ▶ if ( $state & $states{$_} );
Branch: 1 branch
BranchTrueFalseTotal
if $state & $states{$_} 0 0 0
90 }
91  
92 0 join( " | ", sort @names );
93 }
94  
95 sub value {
96 27 ▶ my $self = shift;
Subroutine value: called CC=2 SCAR=6.9
Pod documented
97  
98 27 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 8 19 27
99 8 $self->{is_value} = 1;
100 8 $self->{value} = $_[0];
101 8 return $self;
102 }
103 19 $self->{value};
104 }
105  
106 sub thrown_from_code {
107 0 ▶ my $self = shift;
Subroutine thrown_from_code: not called CC=2 SCAR=17.9
Pod undocumented
108  
109 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
110 0 $self->{thrown_from_code} = $_[0];
111 0 return $self;
112 }
113 0 $self->{thrown_from_code};
114 }
115  
116 15 1;
117  
118 __END__
« Cascade/Target.pm ↑ Summary