Conveyor/Storage/Memory.pm

filter: Statementstmt 46.8% 22 / 47 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 72.7% 8 / 11 Podpod 100% 3 / 3 totaltotal 40.2% 33 / 82 CC 13 SCAR 36.6
CC
13
Cov
33%
parse_table
90.0
assert_transition_cache
12.0
get_next_stage
12.0
CRAP 38.7
« Conveyor/App/Test/Stage.pm ↑ Summary Conveyor/YAML/Active/Payload/Instruction/Container.pm »
1 1 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package Data::Conveyor::Storage::Memory;
6 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 $Data::Conveyor::Storage::Memory::VERSION = '1.103130';
8 }
9 # ABSTRACT: Stage-based conveyor-belt-like ticket handling system
10  
11 1 ▶use Error::Hierarchy::Util 'assert_defined';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Class::Scaffold::Exception::Util 'assert_object_type';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use parent qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
14 Data::Storage::Memory
15 Data::Conveyor::Storage
16 1 );
17 1 ▶use constant TRANSITION_TABLE => '';
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 0 ▶sub parse_table {
Subroutine parse_table: not called CC=9 SCAR=45.0
Pod documented
20 0 my ($self, $table) = @_;
21 0 for (split /\n/ => $table) {
22 0 ▶ next if /^\s*#/o;
Branch: 1 branch
BranchTrueFalseTotal
if /^\s*#/o 0 0 0
23 0 ▶ next if /^\s*$/o;
Branch: 1 branch
BranchTrueFalseTotal
if /^\s*$/o 0 0 0
24 0 s/#.*$//o;
25 0 s/^\s+|\s+$//go;
26 0 my ($from, $rc, $to, $status, $shift) = split /\s+/;
27 assert_defined $_, 'syntax error in transition table'
28 0 for ($from, $rc, $to, $status, $shift);
29 0 for my $value ($from, $to) {
30  
31 # blow up on garbled input.
32 # note: the object knows sh** about valid stage names (?).
33 0 $self->delegate->make_obj('value_ticket_stage')->value($value);
34 }
35 0 my $state = sprintf '%s-%s' => $from, $self->delegate->$rc;
36  
37 # check supplied status value
38 0 ▶ $self->delegate->$status if $status ne '-';
Branch: 1 branch
BranchTrueFalseTotal
if $status ne "-" 0 0 0
39 0 ▶ (our $transition_cache)->{$state} = {
Branch: 2 branches
BranchTrueFalseTotal
$shift eq 'Y' ? : 0 0 0
$status eq '-' ? : 0 0 0
40 stage => $to,
41 shift => $shift eq 'Y' ? 1 : 0,
42 ($status eq '-' ? () : (status => $status)),
43 };
44 }
45 }
46  
47 # This method parses and caches the transition table. This method is called
48 # from get_next_stage(), so the transition table is built on-demand. It is not
49 # built during the storage's init() because parse_table() calls
50 # make_obj('value_ticket_stage'), and if the 'value_ticket_stage' object is
51 # also handled by the memory storage, it would cause a deep recursion.
52 0 ▶sub assert_transition_cache {
Subroutine assert_transition_cache: not called CC=3 SCAR=24.8
Pod documented
53 0 my $self = shift;
54 0 our $transition_cache;
55 0 ▶ return if (ref $transition_cache eq 'HASH') && (keys %$transition_cache);
Branch: 1 branch
BranchTrueFalseTotal
if ref $Data::Conveyor::Storage::Memory::transition_cache eq "HASH" and keys %$Data::Conveyor::Storage::Memory::transition_cache 0 0 0
Condition0%0/3
ref $Data::Conveyor::Storage::Memory::transition_cache eq "HASH" and keys %$Data::Conveyor::Storage::Memory::transition_cache
!ll&&!rl&&r
000
MC/DC0%0/2
ref $Data::Conveyor::Storage::Memory::transition_cache eq "HASH" and keys %$Data::Conveyor::Storage::Memory::transition_cache
ref $Data::Conveyor::Storage::Memory::transition_cache eq "HASH" keys %$Data::Conveyor::Storage::Memory::transition_cache
Truth table0%0/3
A and B
A= ref $Data::Conveyor::Storage::Memory::transition_cache eq "HASH"B= keys %$Data::Conveyor::Storage::Memory::transition_cache
ABresult
0X0
100
111
56 0 $self->parse_table($self->TRANSITION_TABLE);
57 }
58  
59 0 ▶sub get_next_stage {
Subroutine get_next_stage: not called CC=3 SCAR=24.8
Pod documented
60 0 my ($self, $stage, $rc) = @_;
61 0 assert_object_type $stage, 'value_ticket_stage';
62 0 assert_defined $rc, 'called without return code';
63 0 $self->assert_transition_cache;
64 0 my $state = sprintf '%s-%s' => $stage, $rc;
65  
66 # return undef if the transition is not defined.
67 0 ▶ return unless (my $target = (our $transition_cache)->{$state});
Branch: 1 branch
BranchTrueFalseTotal
unless my $target = our $transition_cache->{$state} 0 0 0
68 0 ▶ return unless $target->{shift};
Branch: 1 branch
BranchTrueFalseTotal
unless $target->{"shift"} 0 0 0
69 [ $self->delegate->make_obj('value_ticket_stage')
70 ->value($target->{stage}),
71 $target->{status}
72 0 ];
73 }
74 1 1;
75  
76  
77 __END__
« Conveyor/App/Test/Stage.pm ↑ Summary Conveyor/YAML/Active/Payload/Instruction/Container.pm »