| 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
| |||||||||||||||||||||||||||||
| 23 | 0 | ▶ | next if /^\s*$/o; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 39 | 0 | ▶ | (our $transition_cache)->{$state} = { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 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
Condition0%0/3
ref $Data::Conveyor::Storage::Memory::transition_cache eq "HASH" and keys %$Data::Conveyor::Storage::Memory::transition_cache
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 68 | 0 | ▶ | return unless $target->{shift}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||