File Coverage

blib/lib/Data/Conveyor/YAML/Marshall/Payload/InstructionContainer.pm
Criterion Covered Total %
statement 19 36 52.7
branch 0 8 0.0
condition 0 6 0.0
subroutine 7 9 77.7
pod 2 2 100.0
total 28 61 45.9


line stmt bran cond sub pod time code
1 1     1   15 use 5.008;
  1         4  
  1         31  
2 1     1   6 use strict;
  1         1  
  1         39  
3 1     1   7 use warnings;
  1         2  
  1         43  
4              
5             package Data::Conveyor::YAML::Marshall::Payload::InstructionContainer;
6             BEGIN {
7 1     1   21 $Data::Conveyor::YAML::Marshall::Payload::InstructionContainer::VERSION = '1.103130';
8             }
9             # ABSTRACT: Stage-based conveyor-belt-like ticket handling system
10 1     1   5 use YAML::Marshall 'payload/instructioncontainer';
  1         2  
  1         5  
11 1     1   57 use YAML 'Dump';
  1         4  
  1         80  
12 1     1   5 use parent 'Class::Scaffold::YAML::Marshall';
  1         2  
  1         5  
13              
14             sub yaml_load {
15 0     0 1   my $self = shift;
16 0           my $node = $self->SUPER::yaml_load(@_);
17 0           my $instruction_container =
18             $self->delegate->make_obj('payload_instruction_container');
19 0   0       our $instruction_factory ||=
20             $self->delegate->make_obj('payload_instruction_factory');
21              
22             # expect an ordered list of instructions, each with name and value. The
23             # YAML::Active plugin uses the payload_instruction_factory to
24             # generate the right instruction object, then sets the value on it
25             # and inserts it into the container. The name is prepended by 'u-'
26             # for IC_UPDATE, 'a-' for IC_ADD and 'd-' for IC_DELETE to provide a
27             # concise notation.
28             #
29             # Example:
30             #
31             # - u-value_person_company_no: &COMPANYNO 1234
32             # - u-value_person_name_title: &TITLE Grunz
33             # - u-value_person_name_firstname: &FIRSTNAME Franz
34             # - u-value_person_name_lastname: &LASTNAME Testler
35             # - a-value_person_email_address: &EMAIL fh@univie.ac.at
36             # - a-value_person_fax_number: &FAX1 '+4311234566'
37             # - a-value_person_fax_number: &FAX2 '+431242342343'
38             # - clear: 1
39             # - foo: 1
40 0           for my $spec (@$node) {
41 0 0 0       unless (ref $spec eq 'HASH' && scalar(keys %$spec) == 1) {
42 0           throw Error::Hierarchy::Internal::CustomMessage(custom_message =>
43             "expected a single-item hash with the instruction, got:\n"
44             . Dump($spec));
45             }
46 0           my ($key, $value) = %$spec;
47 0 0         if ($key =~ /^([a-z])-(.*)/) {
48 0           my ($abbrev_command, $type) = ($1, $2);
49 0 0         my $command = $self->word_complete($abbrev_command, $self->delegate->IC)
50             or throw Error::Hierarchy::Internal::CustomMessage(custom_message =>
51             "can't determine instruction command from [$abbrev_command]");
52 0           $instruction_container->items_push(
53             $instruction_factory->gen_instruction(
54             $type,
55             command => $command,
56             value => $value,
57             )
58             );
59             } else {
60 0           $instruction_container->items_push(
61             $instruction_factory->gen_instruction($key, value => $value));
62             }
63             }
64 0           $instruction_container;
65             }
66              
67             sub word_complete {
68 0     0 1   my ($self, $word, @candidates) = @_;
69 0           for (@candidates) {
70 0 0         return $_ if index($_, $word) == 0;
71             }
72             }
73             1;
74              
75              
76             __END__