File Coverage

blib/lib/Data/Conveyor/Value/Ticket/RC.pm
Criterion Covered Total %
statement 18 21 85.7
branch 2 2 100.0
condition 1 3 33.3
subroutine 8 9 88.8
pod 4 4 100.0
total 33 39 84.6


line stmt bran cond sub pod time code
1 1     1   885 use 5.008;
  1         4  
  1         115  
2 1     1   7 use strict;
  1         2  
  1         79  
3 1     1   8 use warnings;
  1         2  
  1         68  
4              
5             package Data::Conveyor::Value::Ticket::RC;
6             BEGIN {
7 1     1   22 $Data::Conveyor::Value::Ticket::RC::VERSION = '1.103130';
8             }
9             # ABSTRACT: Stage-based conveyor-belt-like ticket handling system
10 1     1   6 use parent 'Data::Conveyor::Value::Enum';
  1         2  
  1         8  
11 1   33 1 1 3547 sub get_valid_values_list { our $cache_values ||= $_[0]->delegate->RC }
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::NoSuchRC',
18             rc => $value,);
19             }
20              
21             # Apply a new rc to the value object's existing rc. When called by the payload
22             # methods this method makes sure that the resulting rc is the worst of all
23             # exception's associated rc's. That is, if there are only exceptions with
24             # RC_ERROR, the whole ticket will have RC_ERROR as its rc. But if one of those
25             # exceptions is associated with RC_INTERNAL_ERROR, the whole ticket will have
26             # RC_INTERNAL_ERROR.
27             #
28             # We use an op table for "$ticket_rc * $rc". Here, 'OK' stands for
29             # 'RC_OK', 'ERR' for 'RC_ERROR' and 'INT' for 'RC_INTERNAL_ERROR'.
30             #
31             # rhs |
32             # lhs | OK ERR INT
33             # -------+---------------------------
34             # OK | OK ERR INT
35             # ERR | ERR ERR INT
36             # INT | INT INT INT
37             #
38             # The following simple code relies on the fact that RC_* are encoded as
39             # numbers that increase with increasing severity. If that premise doesn't
40             # hold anymore, we'll probably have to implement a real ops table.
41             sub add {
42 21     21 1 968 my ($rc1, $rc2) = @_;
43 21 100       221 $rc1 > $rc2 ? $rc1 : $rc2;
44             }
45              
46             sub num_cmp {
47 21     21 1 28 my ($rc1, $rc2) = @_;
48 21         59 "$rc1" <=> "$rc2";
49             }
50             1;
51              
52              
53             __END__