lib/Flux/Storage/Memory.pm

filter: Statementstmt 96.9% 64 / 66 Branchbran 50.0% 2 / 4 Conditioncond 100% 4 / 4 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 18 / 18 Podpod 0.0% 0 / 5 totaltotal 90.9% 90 / 99 CC 5 SCAR 3.2
CC
5
Cov
95%
in
2.1
_lock_client
2.0
_lag
2.0
CRAP 1.4
« lib/Flux/Mapper/MappedMapper.pm ↑ Summary lib/Flux/Simple/ArrayIn.pm »
1 package Flux::Storage::Memory;
2 {
3 2 $Flux::Storage::Memory::VERSION = '1.03';
4 }
5  
6 # ABSTRACT: in-memory storage with support for named clients
7  
8 2 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 with
10 'Flux::Out::Role::Easy',
11 'Flux::Storage',
12 'Flux::Storage::Role::ClientList';
13  
14 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶use Flux::Storage::Memory::In;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 2 ▶use List::Util qw(sum);
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 has 'data' => (
19 is => 'ro',
20 12 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
21 2 );
22  
23 has 'client_pos' => (
24 is => 'ro',
25 12 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
26 2 );
27  
28 has 'client_lock' => (
29 is => 'ro',
30 12 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
31 2 );
32  
33 27 ▶sub write {
Subroutine write: called CC=1 SCAR=0.0
Pod undocumented
34 27 my $self = shift;
35 27 my ($item) = @_;
36  
37 27 push @{ $self->data }, $item;
38 }
39  
40 16 ▶sub _read {
Subroutine _read: called CC=1 SCAR=0.0
41 16 my $self = shift;
42 16 my ($pos) = @_;
43  
44 16 return $self->data->[$pos];
45 }
46  
47 3 ▶sub _lag {
Subroutine _lag: called CC=2 SCAR=6.9
48 3 my $self = shift;
49 3 my ($pos) = @_;
50  
51 3 ▶ return sum(map { length } @{$self->data}[ $pos .. @{$self->data} - 1 ]) || 0;
Condition100%2/2
&sum(map({length $_;} @{$self->data;}[$pos .. @{$self->data;} - 1])) || 0
l!l
21
MC/DC100%1/1
&sum(map({length $_;} @{$self->data;}[$pos .. @{$self->data;} - 1])) || 0
&sum(map({length $_;} @{$self->data;}[$pos .. @{$self->data;} - 1]))
Truth table100%2/2
A
A= &sum(map({length $_;} @{$self->data;}[$pos .. @{$self->data;} - 1]))
Aresult
11
00
52 }
53  
54 8 ▶sub _lock_client {
Subroutine _lock_client: called CC=2 SCAR=7.1
55 8 my $self = shift;
56 8 my ($client) = @_;
57  
58 8 my $lock = $self->client_lock->{$client};
59 8 ▶ if ($lock) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lock) 0 8 8
60 # already locked
61 0 return 0;
62 }
63 8 $self->client_lock->{$client} = 1;
64 8 return 1;
65 }
66  
67 8 ▶sub _unlock_client {
Subroutine _unlock_client: called CC=1 SCAR=0.0
68 8 my $self = shift;
69 8 my ($client) = @_;
70  
71 8 $self->client_lock->{$client} = 0;
72 }
73  
74 7 ▶sub _get_client_pos {
Subroutine _get_client_pos: called CC=2 SCAR=6.9
75 7 my $self = shift;
76 7 my ($client) = @_;
77  
78 7 ▶ return $self->client_pos->{$client} || 0;
Condition100%2/2
$self->client_pos->{$client} || 0
l!l
16
MC/DC100%1/1
$self->client_pos->{$client} || 0
$self->client_pos->{$client}
Truth table100%2/2
A
A= $self->client_pos->{$client}
Aresult
11
00
79 }
80  
81 2 ▶sub _set_client_pos {
Subroutine _set_client_pos: called CC=1 SCAR=0.0
82 2 my $self = shift;
83 2 my ($client, $pos) = @_;
84  
85 2 $self->client_pos->{$client} = $pos;
86 }
87  
88 2 ▶sub client_names {
Subroutine client_names: called CC=1 SCAR=0.0
Pod undocumented
89 2 my $self = shift;
90 2 return keys %{ $self->client_pos };
91 }
92  
93 9 ▶sub register_client {
Subroutine register_client: called CC=1 SCAR=0.0
Pod undocumented
94 9 my $self = shift;
95 9 my ($name) = @_;
96  
97 9 $self->client_pos->{$name} = 0;
98 }
99  
100 2 ▶sub unregister_client {
Subroutine unregister_client: called CC=1 SCAR=0.0
Pod undocumented
101 2 my $self = shift;
102 2 my ($name) = @_;
103  
104 2 delete $self->client_pos->{$name};
105 2 delete $self->client_lock->{$name};
106 }
107  
108 8 ▶sub in {
Subroutine in: called CC=2 SCAR=7.4
Pod undocumented
109 8 my $self = shift;
110 8 my ($client) = @_;
111  
112 8 ▶ unless ($self->_lock_client($client)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_lock_client($client)) 0 8 8
113 0 croak "Constructing two clients with same name '$client' for one MemoryStorage - not implemented yet";
114 }
115 8 return Flux::Storage::Memory::In->new({
116 storage => $self,
117 client => $client,
118 });
119 }
120  
121 2 1;
122  
123 __END__
« lib/Flux/Mapper/MappedMapper.pm ↑ Summary lib/Flux/Simple/ArrayIn.pm »