| 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::Test::Stage; | ||||||||||
| 6 | 1 | ▶ | BEGIN { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | $Data::Conveyor::Test::Stage::VERSION = '1.103130'; | |||||||||
| 8 | } | ||||||||||
| 9 | # ABSTRACT: Stage-based conveyor-belt-like ticket handling system | ||||||||||
| 10 | 1 | ▶ | use Test::More; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 1 | ▶ | use Error::Hierarchy::Util 'assert_defined'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 1 | ▶ | use Class::Scaffold::ConstantImporter qw(RC_OK TS_RUNNING); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 1 | ▶ | use parent qw( | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | Test::Class | ||||||||||
| 15 | Class::Scaffold::Delegate::Mixin | ||||||||||
| 16 | Class::Accessor::Complex | ||||||||||
| 17 | 1 | ); | |||||||||
| 18 | 1 | __PACKAGE__->mk_scalar_accessors(qw(test_name stage ticket ticket_no run)); | |||||||||
| 19 | |||||||||||
| 20 | 0 | ▶ | sub opt { | ||||||||
|
Subroutine
opt: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 21 | 0 | my $self = shift; | |||||||||
| 22 | 0 | $::app->opt(@_); | |||||||||
| 23 | } | ||||||||||
| 24 | |||||||||||
| 25 | 0 | ▶ | sub run_stage_test { | ||||||||
|
Subroutine
run_stage_test: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 26 | 0 | my ($self, %args) = @_; | |||||||||
| 27 | 0 | assert_defined $args{$_}, "called without '$_' argument" for qw(name code); | |||||||||
| 28 | 0 | my $runs = $self->opt('runs'); | |||||||||
| 29 | 0 | for my $run (1 .. $runs) { | |||||||||
| 30 | 0 | $self->run($run); | |||||||||
| 31 | 0 | my $subtest_name = sprintf '%s run %s of %s', $args{name}, $run, $runs; | |||||||||
| 32 | 0 | ▶ | subtest $subtest_name, sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 33 | 0 | note ref $self; | |||||||||
| 34 | 0 | $self->run_subtest_code($args{code}); | |||||||||
| 35 | 0 | done_testing; | |||||||||
| 36 | 0 | }; | |||||||||
| 37 | } | ||||||||||
| 38 | } | ||||||||||
| 39 | |||||||||||
| 40 | 0 | ▶ | sub run_subtest_code { | ||||||||
|
Subroutine
run_subtest_code: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 41 | 0 | my ($self, $code) = @_; | |||||||||
| 42 | 0 | $code->($self); | |||||||||
| 43 | |||||||||||
| 44 | # To prepare for the next run, reset the ticket to the stage start and an | ||||||||||
| 45 | # ok status and rc, just as you'd do manually when rerunning the ticket in | ||||||||||
| 46 | # the regsh. Note that this is the same as would happen in the regsh when | ||||||||||
| 47 | # given the command 'set_stage -g starten_<stagename>' | ||||||||||
| 48 | 0 | for ($self->ticket) { | |||||||||
| 49 | 0 | $_->stage->new_start($self->stage); | |||||||||
| 50 | 0 | $_->status(TS_RUNNING); | |||||||||
| 51 | 0 | $_->rc(RC_OK); | |||||||||
| 52 | 0 | $_->close_basic; | |||||||||
| 53 | } | ||||||||||
| 54 | } | ||||||||||
| 55 | |||||||||||
| 56 | 0 | ▶ | sub run_ticket_in_stage { | ||||||||
|
Subroutine
run_ticket_in_stage: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 57 | 0 | my $self = shift; | |||||||||
| 58 | 0 | my $ticket = | |||||||||
| 59 | $self->delegate->make_obj('ticket', ticket_no => $self->ticket_no); | ||||||||||
| 60 | 0 | $ticket->open($self->stage); | |||||||||
| 61 | 0 | $self->delegate->make_stage_object($self->stage, ticket => $ticket)->run; | |||||||||
| 62 | 0 | ▶ | $ticket->store if $ticket->rc eq $self->delegate->RC_INTERNAL_ERROR; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 63 | 0 | $ticket->close; | |||||||||
| 64 | |||||||||||
| 65 | # The ticket that we test our expectations against is a fresh ticket | ||||||||||
| 66 | # object where we read the ticket we just wrote. Note that we read(), not | ||||||||||
| 67 | # open() the ticket, because after the stage run, it will still be in | ||||||||||
| 68 | # an 'active_*' stage, and open() wouldn't find it. | ||||||||||
| 69 | 0 | $self->ticket( | |||||||||
| 70 | $self->delegate->make_obj('ticket', ticket_no => $self->ticket_no)); | ||||||||||
| 71 | 0 | $self->ticket->read; | |||||||||
| 72 | } | ||||||||||
| 73 | |||||||||||
| 74 | 0 | ▶ | sub object_with { | ||||||||
|
Subroutine
object_with: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||
| 75 | 0 | my ($self, $object_type, @args) = @_; | |||||||||
| 76 | 0 | my $object = $self->delegate->make_obj($object_type); | |||||||||
| 77 | 0 | ▶ | while (my ($key, $value) = splice @args, 0, 2) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 78 | 0 | ▶ | if ($key =~ /^\+(.*)$/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 79 | 0 | my $composition = $1; | |||||||||
| 80 | 0 | ▶ | while (my ($comp_key, $comp_value) = splice @$value, 0, 2) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 81 | 0 | $object->$composition->$comp_key($comp_value); | |||||||||
| 82 | } | ||||||||||
| 83 | } else { | ||||||||||
| 84 | 0 | $object->$key($value); | |||||||||
| 85 | } | ||||||||||
| 86 | } | ||||||||||
| 87 | 0 | $object; | |||||||||
| 88 | } | ||||||||||
| 89 | |||||||||||
| 90 | 0 | ▶ | sub make_payload { | ||||||||
|
Subroutine
make_payload: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 91 | 0 | my ($self, @items) = @_; | |||||||||
| 92 | 0 | my $payload = | |||||||||
| 93 | $self->object_with('ticket_payload', add_items_from_list => \@items); | ||||||||||
| 94 | 0 | $self->gen_tx_item_ref($payload); | |||||||||
| 95 | 0 | $payload; | |||||||||
| 96 | } | ||||||||||
| 97 | |||||||||||
| 98 | 0 | ▶ | sub make_test_ticket { | ||||||||
|
Subroutine
make_test_ticket: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 99 | 0 | my ($self, %args) = @_; | |||||||||
| 100 | 0 | my $ticket = | |||||||||
| 101 | $self->delegate->make_obj('test_ticket')->make_whole_ticket(%args); | ||||||||||
| 102 | 0 | $ticket->store_full; | |||||||||
| 103 | |||||||||||
| 104 | # Set up some accessors so other methods can refer to them. | ||||||||||
| 105 | 0 | $self->ticket_no($ticket->ticket_no); | |||||||||
| 106 | } | ||||||||||
| 107 | |||||||||||
| 108 | 0 | ▶ | sub gen_tx_item_ref { | ||||||||
|
Subroutine
gen_tx_item_ref: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||
| 109 | 0 | my ($self, $payload) = @_; | |||||||||
| 110 | 0 | for my $payload_tx ($payload->transactions) { | |||||||||
| 111 | 0 | my $item_spec = $payload_tx->transaction->payload_item; | |||||||||
| 112 | 0 | ▶ | next if ref $item_spec; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 113 | 0 | ▶ | if ($item_spec =~ /^(\w+)\.(\d+)$/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 114 | 0 | my ($accessor, $index) = ($1, $2 - 1); | |||||||||
| 115 | 0 | $payload_tx->transaction->payload_item( | |||||||||
| 116 | eval "\$payload->$accessor\->[$index]"); | ||||||||||
| 117 | 0 | ▶ | die $@ if $@; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 118 | } | ||||||||||
| 119 | 0 | ▶ | unless (ref $payload_tx->transaction->payload_item) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 120 | 0 | throw Error::Hierarchy::Internal::CustomMessage( | |||||||||
| 121 | custom_message => sprintf 'No such payload item [%s]', | ||||||||||
| 122 | $item_spec, | ||||||||||
| 123 | ); | ||||||||||
| 124 | } | ||||||||||
| 125 | } | ||||||||||
| 126 | } | ||||||||||
| 127 | |||||||||||
| 128 | 0 | ▶ | sub make_exception_container { | ||||||||
|
Subroutine
make_exception_container: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 129 | 0 | my ($self, @def) = @_; | |||||||||
| 130 | 0 | my $container = $self->delegate->make_obj('exception_container'); | |||||||||
| 131 | 0 | for my $def (@def) { | |||||||||
| 132 | 0 | my %args = %$def; | |||||||||
| 133 | 0 | my $class = delete $args{ref}; | |||||||||
| 134 | 0 | $container->record($class, %args); | |||||||||
| 135 | } | ||||||||||
| 136 | 0 | $container; | |||||||||
| 137 | } | ||||||||||
| 138 | |||||||||||
| 139 | 0 | ▶ | sub rc_is { | ||||||||
|
Subroutine
rc_is: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 140 | 0 | my ($self, $rc) = @_; | |||||||||
| 141 | 0 | is $self->ticket->rc, $rc, 'rc'; | |||||||||
| 142 | } | ||||||||||
| 143 | |||||||||||
| 144 | 0 | ▶ | sub status_is { | ||||||||
|
Subroutine
status_is: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 145 | 0 | my ($self, $status) = @_; | |||||||||
| 146 | 0 | is $self->ticket->status, $status, 'status'; | |||||||||
| 147 | } | ||||||||||
| 148 | 1 | 1; | |||||||||
| 149 | |||||||||||
| 150 | |||||||||||
| 151 | __END__ | ||||||||||