File Coverage

blib/lib/Data/Conveyor/Value/Ticket/Status.pm
Criterion Covered Total %
statement 25 28 89.2
branch 10 10 100.0
condition 1 3 33.3
subroutine 9 10 90.0
pod 4 4 100.0
total 49 55 89.0


line stmt bran cond sub pod time code
1 1     1   2407 use 5.008;
  1         5  
  1         181  
2 1     1   108 use strict;
  1         4  
  1         87  
3 1     1   7 use warnings;
  1         3  
  1         180  
4              
5             package Data::Conveyor::Value::Ticket::Status;
6             BEGIN {
7 1     1   23 $Data::Conveyor::Value::Ticket::Status::VERSION = '1.103130';
8             }
9             # ABSTRACT: Stage-based conveyor-belt-like ticket handling system
10 1     1   8 use parent 'Data::Conveyor::Value::Enum';
  1         2  
  1         9  
11 1   33 1 1 3672 sub get_valid_values_list { our $cache_values ||= $_[0]->delegate->TS }
12              
13             sub send_notify_value_invalid {
14 0     0 1 0 my ($self, $value) = @_;
15 0         0 local $Error::Depth = $Error::Depth + 2;
16 0         0 $self->exception_container->record(
17             'Data::Conveyor::Exception::Ticket::NoSuchStatus',
18             status => $value,);
19             }
20              
21             # Apply a new status to the value object's existing status. When called by the
22             # payload methods this method makes sure that the resulting status is the
23             # worst of all exception's associated status's. That is, if there are only
24             # exceptions with
25             #
26             # The status is encoded as a character, but we can map each status to a
27             # numeric value and perform the same operation as in apply_rc(). The following
28             # op table holds:
29             #
30             # Again we use an op table. Here, 'RUN' stands for 'TS_RUNNING', 'HOLD' for
31             # 'TS_HOLD', and 'ERR' for 'TS_ERROR'. TS_PENDING is like TS_HOLD. We haven't
32             # decided yet what to do if a ticket has both a TS_HOLD and a TS_PENDING
33             # exception because we don't really use TS_HOLD anymore.
34             #
35             # rhs |
36             # lhs | RUN HOLD ERR
37             # -------+----------------------------
38             # RUN | RUN HOLD ERR
39             # HOLD | HOLD HOLD ERR
40             # ERR | ERR ERR ERR
41             sub add {
42 20     20 1 815 my ($status1, $status2) = @_;
43 20 100       44 $status1 > $status2 ? $status1 : $status2;
44             }
45              
46             sub num_cmp {
47 20     20 1 28 my ($status1, $status2) = @_;
48 20         67 my $delegate = Data::Conveyor::Environment->getenv;
49             my $get_status_number = sub {
50 40 100   40   458 return 0 if $_[0] eq $delegate->TS_RUNNING;
51 24 100       492 return 1 if $_[0] eq $delegate->TS_HOLD;
52 17 100       271 return 1 if $_[0] eq $delegate->TS_PENDING;
53 10 100       157 return 2 if $_[0] eq $delegate->TS_ERROR;
54 1         26 return 0;
55 20         181 };
56 20         40 $get_status_number->($status1) <=> $get_status_number->($status2);
57             }
58             1;
59              
60              
61             __END__