blib/lib/OPP/State.pm

filter: Statementstmt 26.4% 14 / 53 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 20.0% 3 / 15 Podpod 0.0% 0 / 11 totaltotal 20.2% 17 / 84 CC 3 SCAR 10.2
CC
3
Cov
25%
_proc
6.0
exists
6.0
init
2.0
CRAP 2.8
« blib/lib/OPP/Proc/Exec.pm ↑ Summary blib/lib/OPP/Output.pm »
1 #
2 # $Id: State.pm,v 58d7ce835577 2023/03/25 10:34:10 gomor $
3 #
4 package OPP::State;
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 our $VERSION = '1.00';
9  
10 1 ▶use base qw(OPP);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 our @AS = qw(
13 state
14 );
15 1 __PACKAGE__->cgBuildIndices;
16 1 __PACKAGE__->cgBuildAccessorsScalar(\@AS);
17  
18 sub init {
19 0 ▶ my $self = shift;
Subroutine init: not called CC=1 SCAR=6.9
Pod undocumented
20  
21 0 $self->state({});
22  
23 0 return $self;
24 }
25  
26 sub _proc {
27 0 ▶ my $self = shift;
Subroutine _proc: not called CC=2 SCAR=17.9
28 0 my ($idx) = @_;
29  
30 # We have to have a set per each proc so we can call multiple times
31 # same procs (multiple | uniq, for instance). Otherwise, there will
32 # be a collision and only first call we have its state kept and later
33 # results will be lost:
34  
35 0 ▶ $idx ||= 0;
Condition0%0/2
$idx ||= 0
l!l
00
MC/DC0%0/1
$idx ||= 0
$idx
Truth table0%0/2
A
A= $idx
Aresult
11
00
36  
37 0 my @c = caller(1);
38  
39 0 my $module = $c[0];
40 0 $module =~ s{^.*::(\S+)$}{$1};
41  
42 0 return lc($module).':'.$idx;
43 }
44  
45 # Return proc state object:
46 sub current {
47 0 ▶ my $self = shift;
Subroutine current: not called CC=1 SCAR=6.9
Pod undocumented
48 0 my ($idx) = @_;
49  
50 0 return $self->state->{$self->_proc($idx)};
51 }
52  
53 # Update proc state object from another state object:
54 sub update {
55 0 ▶ my $self = shift;
Subroutine update: not called CC=1 SCAR=6.9
Pod undocumented
56 0 my ($state, $idx) = @_;
57  
58 0 return $self->state->{$self->_proc($idx)} = $state;
59 }
60  
61 # Reset proc state object:
62 sub reset {
63 0 ▶ my $self = shift;
Subroutine reset: not called CC=1 SCAR=6.9
Pod undocumented
64 0 my ($idx) = @_;
65  
66 0 return $self->state->{$self->_proc($idx)} = undef;
67 }
68  
69 # Reset all state objects:
70 sub reset_all {
71 0 ▶ my $self = shift;
Subroutine reset_all: not called CC=1 SCAR=6.9
Pod undocumented
72  
73 0 return $self->state = {};
74 }
75  
76 sub add {
77 0 ▶ my $self = shift;
Subroutine add: not called CC=1 SCAR=6.9
Pod undocumented
78 0 my ($k, $v, $idx) = @_;
79  
80 0 return $self->state->{$self->_proc($idx)}{$k} = $v;
81 }
82  
83 sub del {
84 0 ▶ my $self = shift;
Subroutine del: not called CC=1 SCAR=6.9
Pod undocumented
85 0 my ($k, $idx) = @_;
86  
87 0 return delete $self->state->{$self->_proc($idx)}{$k};
88 }
89  
90 sub exists {
91 0 ▶ my $self = shift;
Subroutine exists: not called CC=2 SCAR=17.9
Pod undocumented
92 0 my ($k, $idx) = @_;
93  
94 0 ▶ return defined($self->state->{$self->_proc($idx)}{$k}) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->state->{$self->_proc($idx)}{$k} ? : 0 0 0
95 }
96  
97 sub incr {
98 0 ▶ my $self = shift;
Subroutine incr: not called CC=1 SCAR=6.9
Pod undocumented
99 0 my ($k, $idx) = @_;
100  
101 0 return $self->state->{$self->_proc($idx)}{$k}++;
102 }
103  
104 sub decr {
105 0 ▶ my $self = shift;
Subroutine decr: not called CC=1 SCAR=6.9
Pod undocumented
106 0 my ($k, $idx) = @_;
107  
108 0 return $self->state->{$self->_proc($idx)}{$k}--;
109 }
110  
111 sub value {
112 0 ▶ my $self = shift;
Subroutine value: not called CC=1 SCAR=6.9
Pod undocumented
113 0 my ($k, $idx) = @_;
114  
115 0 return $self->state->{$self->_proc($idx)}{$k};
116 }
117  
118 1 1;
119  
120 __END__
« blib/lib/OPP/Proc/Exec.pm ↑ Summary blib/lib/OPP/Output.pm »