File Coverage

blib/lib/Data/Conveyor/Stage/TxSelector.pm
Criterion Covered Total %
statement 17 40 42.5
branch n/a
condition 0 3 0.0
subroutine 7 13 53.8
pod 7 7 100.0
total 31 63 49.2


line stmt bran cond sub pod time code
1 1     1   741 use 5.008;
  1         3  
  1         41  
2 1     1   7 use strict;
  1         13  
  1         47  
3 1     1   6 use warnings;
  1         2  
  1         60  
4              
5             package Data::Conveyor::Stage::TxSelector;
6             BEGIN {
7 1     1   41 $Data::Conveyor::Stage::TxSelector::VERSION = '1.103130';
8             }
9             # ABSTRACT: Stage-based conveyor-belt-like ticket handling system
10              
11             # Implements the transaction selector (txsel)
12 1     1   7 use Error::Hierarchy::Util 'assert_defined';
  1         3  
  1         69  
13 1     1   6 use parent 'Data::Conveyor::Stage::SingleTicket';
  1         2  
  1         8  
14              
15             sub DEFAULTS {
16 1     1 1 1140 (expected_stage => $_[0]->delegate->ST_TXSEL);
17             }
18              
19             # Return a list of object types that specifies in which order payload items
20             # should be traversed. Subclasses might need to override this with a specific
21             # order, for example, when new payload items are created implicitly.
22             #
23             # don't include transaction itself in calculating transactions
24             sub object_type_iteration_order {
25 0     0 1   grep { $_ ne $_[0]->delegate->OT_TRANSACTION } $_[0]->delegate->OT;
  0            
26             }
27              
28             sub main {
29 0     0 1   my ($self, %args) = @_;
30 0           $self->SUPER::main(%args);
31              
32             # Txsel handlers can create implicit payload items; to ensure idempotency,
33             # we remove them before reprocessing the ticket.
34 0           $self->ticket->payload->delete_implicit_items;
35 0           $self->ticket->payload->transactions_clear;
36 0           $self->before_object_type_iteration;
37 0           for my $object_type ($self->object_type_iteration_order) {
38 0           for my $payload_item (
39             $self->ticket->payload->get_list_for_object_type($object_type)) {
40 0           $self->calc_implicit_tx($object_type, $payload_item,
41             $self->delegate->CTX_BEFORE);
42 0           $self->calc_explicit_tx($object_type, $payload_item);
43 0           $self->calc_implicit_tx($object_type, $payload_item,
44             $self->delegate->CTX_AFTER);
45             }
46             }
47 0           $self->after_object_type_iteration;
48             }
49              
50             # Two events that subclasses might want to handle
51 0     0 1   sub before_object_type_iteration { }
52 0     0 1   sub after_object_type_iteration { }
53              
54             sub calc_explicit_tx {
55 0     0 1   my ($self, $object_type, $payload_item) = @_;
56 0           $self->ticket->payload->add_transaction(
57             object_type => $object_type,
58             command => $payload_item->command,
59             type => $self->delegate->TXT_EXPLICIT,
60             status => $self->delegate->TXS_RUNNING,
61             payload_item => $payload_item,
62             necessity => $self->delegate->TXN_MANDATORY,
63             );
64             }
65              
66             # find and set implicit transactions in the current object.
67             sub calc_implicit_tx {
68 0     0 1   my ($self, $object_type, $payload_item, $context) = @_;
69 0   0       our $factory ||= $self->delegate->make_obj('transaction_factory');
70 0           assert_defined $context, 'called without context.';
71 0           assert_defined $object_type, 'called without object_type.';
72 0           assert_defined $payload_item, 'called without payload item.';
73 0           $factory->gen_txsel_handler(
74             $object_type,
75             $payload_item->{command},
76             $context,
77             payload_item => $payload_item,
78             ticket => $self->ticket,
79             )->calc_implicit_tx;
80             }
81             1;
82              
83              
84             __END__