| 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::Stage::TransactionIterator; | ||||||||||||||||||||
| 6 | 1 | ▶ | BEGIN { | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 1 | $Data::Conveyor::Stage::TransactionIterator::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 Error::Hierarchy; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | 1 | ▶ | use Error ':try'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 14 | 1 | ▶ | use parent 'Data::Conveyor::Stage::SingleTicket'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 15 | 1 | __PACKAGE__->mk_scalar_accessors(qw(factory_method)) | |||||||||||||||||||
| 16 | ->mk_boolean_accessors(qw(done)); | ||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | # Subclasses can override this if they don't want to process certain | ||||||||||||||||||||
| 19 | # transactions, e.g., a notify stage might want to process all transactions, | ||||||||||||||||||||
| 20 | # regardless of their status. | ||||||||||||||||||||
| 21 | 0 | ▶ | sub should_process_transaction { | ||||||||||||||||||
|
Subroutine
should_process_transaction: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 22 | 0 | my ($self, $transaction) = @_; | |||||||||||||||||||
| 23 | 0 | $transaction->status eq $self->delegate->TXS_RUNNING; | |||||||||||||||||||
| 24 | } | ||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | # Give subclasses a chance to do transaction-wide processing. Normally you | ||||||||||||||||||||
| 27 | # could do this by subclassing main() and doing your special stuff after | ||||||||||||||||||||
| 28 | # $self->SUPER::main(@_), but some things affect the transaction handlers | ||||||||||||||||||||
| 29 | # themselves. Still we don't want to do this before $self->SUPER::main(@_) | ||||||||||||||||||||
| 30 | # because that would preclude more basic checks (such as done by this class's | ||||||||||||||||||||
| 31 | # superclass). | ||||||||||||||||||||
| 32 | 0 | ▶ | sub before_iteration { } | ||||||||||||||||||
|
Subroutine
before_iteration: not called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | 0 | ▶ | sub main { | ||||||||||||||||||
|
Subroutine
main: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||
| 35 | 0 | my $self = shift; | |||||||||||||||||||
| 36 | 0 | $self->SUPER::main(@_); | |||||||||||||||||||
| 37 | 0 | $self->before_iteration; | |||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | # Skip the rest of the stage run if we're marked as done. this might | ||||||||||||||||||||
| 40 | # happen if very basic things didn't work out. | ||||||||||||||||||||
| 41 | 0 | ▶ | return if $self->done; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 42 | 0 | my @extra_tx; | |||||||||||||||||||
| 43 | 0 | ▶ | our $factory ||= $self->delegate->make_obj('transaction_factory'); | ||||||||||||||||||
|
Condition0%0/3
our $factory ||= $self->delegate->make_obj("transaction_factory")
MC/DC0%0/2
our $factory ||= $self->delegate->make_obj("transaction_factory")
our $factory
$self->delegate->make_obj("transaction_factory")
Truth table0%0/3
A ||= B
A= our $factoryB= $self->delegate->make_obj("transaction_factory")
| |||||||||||||||||||||
| 44 | 0 | my $factory_method = $self->factory_method; | |||||||||||||||||||
| 45 | 0 | for my $payload_tx ($self->ticket->payload->transactions) { | |||||||||||||||||||
| 46 | 0 | ▶ | next unless $self->should_process_transaction($payload_tx->transaction); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 47 | 0 | ▶ | try { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 48 | 0 | my $transaction_handler = $factory->$factory_method( | |||||||||||||||||||
| 49 | tx => $payload_tx, | ||||||||||||||||||||
| 50 | ticket => $self->ticket, | ||||||||||||||||||||
| 51 | stage => $self, | ||||||||||||||||||||
| 52 | ); | ||||||||||||||||||||
| 53 | 0 | $transaction_handler->run; | |||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | # The transaction handler will accumulate exceptions in the | ||||||||||||||||||||
| 56 | # exception container of the payload item pointed to by the | ||||||||||||||||||||
| 57 | # current transaction. | ||||||||||||||||||||
| 58 | # | ||||||||||||||||||||
| 59 | # Transaction handlers can ask for extra tx to be run by further | ||||||||||||||||||||
| 60 | # stages. For example, the policy transaction handler for | ||||||||||||||||||||
| 61 | # person.update can, when asked to modify otherwise immutable | ||||||||||||||||||||
| 62 | # owner fields, downgrade an owner to a contact when that owner | ||||||||||||||||||||
| 63 | # isn't used in a delegation. To do so, it adds a | ||||||||||||||||||||
| 64 | # person.set-contact tx so that the delegation can downgrade the | ||||||||||||||||||||
| 65 | # person. | ||||||||||||||||||||
| 66 | # | ||||||||||||||||||||
| 67 | # Transaction handlers do so via an extra_tx_list attribute, which | ||||||||||||||||||||
| 68 | # is processed here. We don't just push onto | ||||||||||||||||||||
| 69 | # $self->ticket->payload->transactions because we are iterating | ||||||||||||||||||||
| 70 | # over just that, and it's not recommended to change a list while | ||||||||||||||||||||
| 71 | # iterating over it. | ||||||||||||||||||||
| 72 | # | ||||||||||||||||||||
| 73 | # A null transaction handler - produced by a Class::Null entry in | ||||||||||||||||||||
| 74 | # the relevant hashes of the transaction factory - returns another | ||||||||||||||||||||
| 75 | # Class::Null object on each of its method calls, so here we'd be | ||||||||||||||||||||
| 76 | # pushing a Class::Null object onto @extra_tx. Avoid that. | ||||||||||||||||||||
| 77 | 0 | ▶ | if ($transaction_handler->extra_tx_list_count) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 78 | 0 | push @extra_tx => grep { !UNIVERSAL::isa($_, 'Class::Null') } | |||||||||||||||||||
| 79 | $transaction_handler->extra_tx_list; | ||||||||||||||||||||
| 80 | } | ||||||||||||||||||||
| 81 | } | ||||||||||||||||||||
| 82 | 0 | ▶ | catch Error::Hierarchy with { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | # Exception that was thrown, not recorded. | ||||||||||||||||||||
| 85 | 0 | $payload_tx->transaction->payload_item->exception_container | |||||||||||||||||||
| 86 | ->items_set_push($_[0]); | ||||||||||||||||||||
| 87 | 0 | }; | |||||||||||||||||||
| 88 | } | ||||||||||||||||||||
| 89 | 0 | $self->ticket->payload->add_transaction($_) for @extra_tx; | |||||||||||||||||||
| 90 | } | ||||||||||||||||||||
| 91 | 1 | 1; | |||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | __END__ | ||||||||||||||||||||