| 1 | package Protocol::FIX::BaseComposite; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 18 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 18 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 18 | ▶ | use Protocol::FIX; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 18 | our $VERSION = '0.08'; ## VERSION | |||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | Protocol::FIX::BaseComposite - base class for Component, Group and Message | ||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | =head1 METHODS (for protocol developers) | ||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | =head3 new | ||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | new($class, $name, $type, $composites) | ||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | Creates new BaseComposite (performed by Protocol, when it parses XML definition) | ||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 2054 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=16 SCAR=28.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 2054 | my ($class, $name, $type, $composites) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 2054 | ▶ | die "composites array must be even" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | if @$composites % 2; | ||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | 2054 | ▶ | die "composites array must be non-empty" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | unless @$composites; | ||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 2054 | ▶ | die "composite name must be defined" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $name and $name =~ /.+/
MC/DC0%0/2
defined $name and $name =~ /.+/
defined $name
$name =~ /.+/
Truth table33%1/3
A and B
A= defined $nameB= $name =~ /.+/
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | if (!defined($name) || $name !~ /.+/); | ||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | 2054 | my @composites; | |||||||||||||||||||||||||||||||||||||||||
| 39 | my @mandatory_composites; | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 2054 | my %composite_by_name; | |||||||||||||||||||||||||||||||||||||||||
| 41 | 2054 | my %component_for; | |||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 2054 | ▶ | for (my $idx = 0; $idx < @$composites; $idx += 2) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 39737 | my $c = $composites->[$idx]; | |||||||||||||||||||||||||||||||||||||||||
| 45 | 39737 | my $required = $composites->[$idx + 1]; | |||||||||||||||||||||||||||||||||||||||||
| 46 | 39737 | ▶ | die "The object $idx must be a composite" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | unless Protocol::FIX::is_composite($c); | ||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | 39737 | my $prerequisite_composite; | |||||||||||||||||||||||||||||||||||||||||
| 50 | 39737 | ▶ | if ($c->{type} eq 'DATA') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | my $valid_definition = ($idx > 0) | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 2586 | ▶ | && $composites->[$idx - 2]->{type} eq 'LENGTH'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$idx > 0 && $$composites[$idx - 2]{'type'} eq 'LENGTH'
MC/DC50%1/2
$idx > 0 && $$composites[$idx - 2]{'type'} eq 'LENGTH'
$idx > 0
$$composites[$idx - 2]{'type'} eq 'LENGTH'
Truth table66%2/3
A && B
A= $idx > 0B= $$composites[$idx - 2]{'type'} eq 'LENGTH'
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | die "The field type 'LENGTH' must appear before field " . $c->{name} | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 2586 | ▶ | unless $valid_definition; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | 2585 | $prerequisite_composite = $composites->[$idx - 2]; | |||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | 39736 | ▶ | push @composites, $c, ($required ? 1 : 0); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 39736 | ▶ | push @mandatory_composites, $c->{name} if $required; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | 39736 | $composite_by_name{$c->{name}} = [$c, $prerequisite_composite]; | |||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | 39736 | ▶ | if (UNIVERSAL::isa($c, 'Protocol::FIX::Component')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 4371 | my $sub_dependency = $c->{field_to_component}; | |||||||||||||||||||||||||||||||||||||||||
| 64 | 4371 | for my $k (keys %$sub_dependency) { | |||||||||||||||||||||||||||||||||||||||||
| 65 | 33862 | ▶ | if (exists $component_for{$k}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | die( "Ambiguity when constructing component '$name': '$k' already points to '" | ||||||||||||||||||||||||||||||||||||||||||
| 67 | . $component_for{$k} | ||||||||||||||||||||||||||||||||||||||||||
| 68 | . "', trying to add another pointer to '" | ||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | . $sub_dependency->{$k} | |||||||||||||||||||||||||||||||||||||||||
| 70 | . "'"); | ||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||
| 72 | 33862 | $component_for{$k} = $sub_dependency->{$k}; | |||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||
| 75 | 39736 | ▶ | if (exists $component_for{$c->{name}}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | die( "Ambiguity when constructing component '$name': '" | ||||||||||||||||||||||||||||||||||||||||||
| 77 | . $c->{name} | ||||||||||||||||||||||||||||||||||||||||||
| 78 | . "' already points to '" | ||||||||||||||||||||||||||||||||||||||||||
| 79 | . $component_for{$c->{name}} | ||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | . "', trying to add another pointer to '" | |||||||||||||||||||||||||||||||||||||||||
| 81 | . $name | ||||||||||||||||||||||||||||||||||||||||||
| 82 | . "'"); | ||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||
| 84 | 39736 | $component_for{$c->{name}} = $name; | |||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | 2053 | my $obj = { | |||||||||||||||||||||||||||||||||||||||||
| 89 | name => $name, | ||||||||||||||||||||||||||||||||||||||||||
| 90 | type => $type, | ||||||||||||||||||||||||||||||||||||||||||
| 91 | composites => \@composites, | ||||||||||||||||||||||||||||||||||||||||||
| 92 | composite_by_name => \%composite_by_name, | ||||||||||||||||||||||||||||||||||||||||||
| 93 | mandatory_composites => \@mandatory_composites, | ||||||||||||||||||||||||||||||||||||||||||
| 94 | field_to_component => \%component_for, | ||||||||||||||||||||||||||||||||||||||||||
| 95 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | 2053 | return bless $obj, $class; | |||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | =head3 serialize | ||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | serialize($self, $values) | ||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | Serializes array of C<$values>. Not for end-user usage. Please, refer | ||||||||||||||||||||||||||||||||||||||||||
| 105 | L<Message/"serialize"> | ||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | 54 | ▶ | sub serialize { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
serialize: called CC=12 SCAR=25.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | 54 | my ($self, $values) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | 54 | ▶ | die "values must be non-empty even array" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
ref $values ne "ARRAY" or not @$values or @$values % 2
ref $values ne "ARRAY" or not @$values
MC/DC0%0/3
ref $values ne "ARRAY" or not @$values or @$values % 2
ref $values ne "ARRAY"
not @$values
@$values % 2
Truth table25%1/4
A or not(B) or C
A= ref $values ne "ARRAY"B= not @$valuesC= @$values % 2
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | if (ref($values) ne 'ARRAY') || !@$values || (@$values % 2); | ||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | 54 | my @strings; | |||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | my %used_composites; | ||||||||||||||||||||||||||||||||||||||||||
| 118 | 54 | ▶ | for (my $idx = 0; $idx < @$values; $idx += 2) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | 165 | my $name = $values->[$idx]; | |||||||||||||||||||||||||||||||||||||||||
| 120 | 165 | my $value = $values->[$idx + 1]; | |||||||||||||||||||||||||||||||||||||||||
| 121 | 165 | my $c_info = $self->{composite_by_name}->{$name}; | |||||||||||||||||||||||||||||||||||||||||
| 122 | 165 | ▶ | if (!$c_info) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | 1 | die "Composite '$name' is not available for " . $self->{type} . " '" . $self->{name} . "'"; | |||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | 164 | my $c = $c_info->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 127 | 164 | ▶ | if ($c->{type} eq 'DATA') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | 5 | my $c_length = $c_info->[1]; | |||||||||||||||||||||||||||||||||||||||||
| 129 | my $valid_sequence = ($idx > 0) | ||||||||||||||||||||||||||||||||||||||||||
| 130 | 5 | ▶ | && $self->{composite_by_name}->{$values->[$idx - 2]}->[0] == $c_length; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$idx > 0 && $self->{'composite_by_name'}{$$values[$idx - 2]}[0] == $c_length
MC/DC50%1/2
$idx > 0 && $self->{'composite_by_name'}{$$values[$idx - 2]}[0] == $c_length
$idx > 0
$self->{'composite_by_name'}{$$values[$idx - 2]}[0] == $c_length
Truth table66%2/3
A && B
A= $idx > 0B= $self->{'composite_by_name'}{$$values[$idx - 2]}[0] == $c_length
| |||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | 5 | ▶ | die "The field '" . $c_length->{name} . "' must precede '" . $c->{name} . "'" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | unless $valid_sequence; | ||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||
| 135 | 4 | my $actual_length = length($value); | |||||||||||||||||||||||||||||||||||||||||
| 136 | 4 | ▶ | die "The length field '" . $c_length->{name} . "' ($actual_length) isn't equal previously declared (" . $values->[$idx - 1] . ")" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | unless $values->[$idx - 1] == $actual_length; | ||||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | 162 | push @strings, $c->serialize($value); | |||||||||||||||||||||||||||||||||||||||||
| 141 | 158 | $used_composites{$name} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||
| 143 | 47 | for my $mandatory_name (@{$self->{mandatory_composites}}) { | |||||||||||||||||||||||||||||||||||||||||
| 144 | die "'$mandatory_name' is mandatory for " . $self->{type} . " '" . $self->{name} . "'" | ||||||||||||||||||||||||||||||||||||||||||
| 145 | 91 | ▶ | unless exists $used_composites{$mandatory_name}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||
| 147 | 43 | return join $Protocol::FIX::SEPARATOR, @strings; | |||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||
| 150 | 18 | 1; | |||||||||||||||||||||||||||||||||||||||||