| 1 | 3 | ▶ | use 5.008; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | 3 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 3 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | package Data::Conveyor::Stage::SingleTicket; | ||||||||||
| 6 | 3 | ▶ | BEGIN { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 3 | $Data::Conveyor::Stage::SingleTicket::VERSION = '1.103130'; | |||||||||
| 8 | } | ||||||||||
| 9 | # ABSTRACT: Stage-based conveyor-belt-like ticket handling system | ||||||||||
| 10 | |||||||||||
| 11 | # Base class for stages handling a single ticket (i.e., policy or delegation, | ||||||||||
| 12 | # but not queue). | ||||||||||
| 13 | # | ||||||||||
| 14 | # To use it, create an object of this class, set the ticket and | ||||||||||
| 15 | # call run(). You can then read the status the stage's ticket and act on it. | ||||||||||
| 16 | 3 | ▶ | use Error::Hierarchy::Util 'assert_defined'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | 3 | ▶ | use parent 'Data::Conveyor::Stage'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 18 | 3 | __PACKAGE__->mk_framework_object_accessors( | |||||||||
| 19 | ticket => 'ticket', | ||||||||||
| 20 | stage_delegate => 'stage_delegate', | ||||||||||
| 21 | )->mk_scalar_accessors(qw(expected_stage log_max_level_previous)); | ||||||||||
| 22 | |||||||||||
| 23 | 0 | ▶ | sub MUNGE_CONSTRUCTOR_ARGS { | ||||||||
|
Subroutine
MUNGE_CONSTRUCTOR_ARGS: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 24 | 0 | my ($self, @args) = @_; | |||||||||
| 25 | 0 | @args = $self->SUPER::MUNGE_CONSTRUCTOR_ARGS(@args); | |||||||||
| 26 | 0 | push @args => | |||||||||
| 27 | (stage_delegate => $self->delegate->make_delegate('stage_delegate')); | ||||||||||
| 28 | 0 | @args; | |||||||||
| 29 | } | ||||||||||
| 30 | |||||||||||
| 31 | 0 | ▶ | sub main { | ||||||||
|
Subroutine
main: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 32 | 0 | my ($self, %args) = @_; | |||||||||
| 33 | 0 | $self->SUPER::main(%args); | |||||||||
| 34 | 0 | assert_defined $self->expected_stage, 'called without set expected_stage.'; | |||||||||
| 35 | 0 | assert_defined $self->ticket, 'called without set ticket.'; | |||||||||
| 36 | |||||||||||
| 37 | # Remember the log's previous max_level settings and temporarily (until | ||||||||||
| 38 | # the end of the ticket stage) set the log's max_level to the one | ||||||||||
| 39 | # indicated by the ticket. This mechanism can be used to increase a faulty | ||||||||||
| 40 | # ticket's log level from the regsh so that verbose information can be | ||||||||||
| 41 | # seen in the log. But only override with the ticket's log level if it is | ||||||||||
| 42 | # higher than the current log level; we don't want a ticket to actually | ||||||||||
| 43 | # reduce the current log level. | ||||||||||
| 44 | 0 | $self->log_max_level_previous($self->log->max_level); | |||||||||
| 45 | 0 | ▶ | if ($self->ticket->get_log_level > $self->log->max_level) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 46 | 0 | $self->log->max_level($self->ticket->get_log_level); | |||||||||
| 47 | } | ||||||||||
| 48 | 0 | ▶ | unless ($self->ticket->stage->name eq $self->expected_stage) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 49 | 0 | throw Data::Conveyor::Exception::Ticket::InvalidStage( | |||||||||
| 50 | stage => $self->ticket->stage,); | ||||||||||
| 51 | } | ||||||||||
| 52 | } | ||||||||||
| 53 | |||||||||||
| 54 | 0 | ▶ | sub end { | ||||||||
|
Subroutine
end: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 55 | 0 | my $self = shift; | |||||||||
| 56 | |||||||||||
| 57 | # After handling all exceptions, if the ticket status is anything else | ||||||||||
| 58 | # than TS_RUNNING, but the rc is RC_ERROR, set the status to TS_RUNNING so | ||||||||||
| 59 | # that the ticket gets passed on to the notify stage. | ||||||||||
| 60 | # | ||||||||||
| 61 | # The reason is that we don't want erroneous tickets to be left on hold. | ||||||||||
| 62 | # If there's a reason it would normally go on hold and another reason it's | ||||||||||
| 63 | # erroneous, the error takes precedence. | ||||||||||
| 64 | 0 | ▶ | $self->ticket->status($self->delegate->TS_RUNNING) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 65 | if $self->ticket->rc eq $self->delegate->RC_ERROR; | ||||||||||
| 66 | 0 | $self->stage_delegate->handle_stage_end($self); | |||||||||
| 67 | |||||||||||
| 68 | # restore the log's previous max_level setting. | ||||||||||
| 69 | 0 | $self->log->max_level($self->log_max_level_previous); | |||||||||
| 70 | 0 | $self->ticket->store; | |||||||||
| 71 | } | ||||||||||
| 72 | 3 | 1; | |||||||||
| 73 | |||||||||||
| 74 | |||||||||||
| 75 | __END__ | ||||||||||