FIX/BaseComposite.pm

filter: Statementstmt 96.8% 61 / 63 Branchbran 81.5% 31 / 38 Conditioncond 46.6% 7 / 15 MC/DCmcdc 22.2% 2 / 9 Subroutinesub 100% 5 / 5 Podpod 100% 2 / 2 totaltotal 81.8% 108 / 132 CC 27 SCAR 26.4
CC
27
Cov
85%
new
17.6
serialize
12.3
BEGIN
1.0
CRAP 13.9
↑ Summary FIX/Parser.pm »
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
BranchTrueFalseTotal
if @$composites % 2 0 2054 2054
30 if @$composites % 2;
31  
32 2054 ▶ die "composites array must be non-empty"
Branch: 1 branch
BranchTrueFalseTotal
unless @$composites 0 2054 2054
33 unless @$composites;
34  
35 2054 ▶ die "composite name must be defined"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name and $name =~ /.+/ 0 2054 2054
Condition33%1/3
defined $name and $name =~ /.+/
!ll&&!rl&&r
002054
MC/DC0%0/2
defined $name and $name =~ /.+/
defined $name $name =~ /.+/
Truth table33%1/3
A and B
A= defined $nameB= $name =~ /.+/
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if ($idx < @$composites) 39737 2053 41790
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
BranchTrueFalseTotal
unless Protocol::FIX::is_composite($c) 0 39737 39737
47 unless Protocol::FIX::is_composite($c);
48  
49 39737 my $prerequisite_composite;
50 39737 ▶ if ($c->{type} eq 'DATA') {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->{"type"} eq "DATA") 2586 37151 39737
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'
!ll&&!rl&&r
102585
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'
ABresult
0X0
100
111
53 die "The field type 'LENGTH' must appear before field " . $c->{name}
54 2586 ▶ unless $valid_definition;
Branch: 1 branch
BranchTrueFalseTotal
unless $valid_definition 1 2585 2586
55 2585 $prerequisite_composite = $composites->[$idx - 2];
56 }
57  
58 39736 ▶ push @composites, $c, ($required ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
$required ? : 5621 34115 39736
59 39736 ▶ push @mandatory_composites, $c->{name} if $required;
Branch: 1 branch
BranchTrueFalseTotal
if $required 5621 34115 39736
60 39736 $composite_by_name{$c->{name}} = [$c, $prerequisite_composite];
61  
62 39736 ▶ if (UNIVERSAL::isa($c, 'Protocol::FIX::Component')) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($c, "Protocol::FIX::Component")) 4371 35365 39736
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
BranchTrueFalseTotal
if (exists $component_for{$k}) 0 33862 33862
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
BranchTrueFalseTotal
if (exists $component_for{$c->{"name"}}) 0 39736 39736
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
BranchTrueFalseTotal
if ref $values ne "ARRAY" or not @$values or @$values % 2 0 54 54
Condition33%2/6
ref $values ne "ARRAY" or not @$values or @$values % 2
l!l&&r!l&&!r
0054
ref $values ne "ARRAY" or not @$values
l!l&&r!l&&!r
0054
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
ABCresult
1XX1
01X1
0011
0000
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
BranchTrueFalseTotal
if ($idx < @$values) 165 47 212
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
BranchTrueFalseTotal
unless ($c_info) 1 164 165
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
BranchTrueFalseTotal
if ($c->{"type"} eq "DATA") 5 159 164
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
!ll&&!rl&&r
104
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
ABresult
0X0
100
111
131  
132 5 ▶ die "The field '" . $c_length->{name} . "' must precede '" . $c->{name} . "'"
Branch: 1 branch
BranchTrueFalseTotal
unless $valid_sequence 1 4 5
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
BranchTrueFalseTotal
unless $$values[$idx - 1] == $actual_length 1 3 4
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
BranchTrueFalseTotal
unless exists $used_composites{$mandatory_name} 4 87 91
146 }
147 43 return join $Protocol::FIX::SEPARATOR, @strings;
148 }
149  
150 18 1;
↑ Summary FIX/Parser.pm »