Lite.pm

filter: Statementstmt 11.7% 31 / 263 Branchbran 0.0% 0 / 120 Conditioncond 0.0% 0 / 45 MC/DCmcdc 0.0% 0 / 26 Subroutinesub 22.2% 8 / 36 Podpod 35.7% 10 / 28 totaltotal 9.4% 49 / 518 SCAR 86.7
CC
85
Cov
7%
constructMessage
506.0
listen
182.0
request
90.0
CRAP 5851.0
↑ Summary Lite/Dictionary.pm »
1 package FIX::Lite;
2  
3 1 ▶use vars qw($VERSION @ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use IO::Socket;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use POSIX qw(strftime);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 #use Net::Cmd;
10 1 ▶use FIX::Lite::Dictionary;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use IO::Select;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Time::HiRes qw(gettimeofday);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 #@ISA = qw(Net::Cmd IO::Socket::INET);
15 1 @ISA = qw(IO::Socket::INET);
16 1 $VERSION = "0.03";
17  
18 1 my $fixDict;
19 1 my $MsgSeqNum = 0;
20 1 my %fieldDefaults = (
21 EncryptMethod => 0,
22 HeartBtInt => 30,
23 );
24 1 my $sel;
25  
26 sub new {
27 0 ▶ my $self = shift;
Subroutine new: not called CC=7 SCAR=40.3
Pod documented
28 0 ▶ my $type = ref($self) || $self;
Condition0%0/3
ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table0%0/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
29 0 my %arg = @_;
30 0 my $obj;
31 $obj = $type->SUPER::new(
32 PeerHost => defined $arg{Host} ? $arg{Host} : '127.0.0.1',
33 PeerPort => defined $arg{Port} ? $arg{Port} : '5201',
34 0 ▶ Timeout => defined $arg{Timeout} ? $arg{Timeout} : 60,
Branch: 3 branches
BranchTrueFalseTotal
defined $arg{'Host'} ? : 0 0 0
defined $arg{'Port'} ? : 0 0 0
defined $arg{'Timeout'} ? : 0 0 0
35 Proto => 'tcp',
36 );
37 0 $sel = IO::Select->new( $obj );
38  
39 return undef
40 0 ▶ unless defined $obj;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $obj 0 0 0
41  
42 0 $obj->autoflush(1);
43  
44 #$obj->debug(exists $arg{Debug} ? $arg{Debug} : undef);
45  
46 # Initialize $fixDict
47  
48 0 ▶ if ( defined $arg{version} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $arg{'version'}) { } 0 0 0
49 0 FIX::Lite::Dictionary::load( $arg{version} );
50 }
51 else {
52 0 FIX::Lite::Dictionary::load('FIX44');
53 }
54 0 $fixDict = FIX::Lite::Dictionary->new();
55  
56 0 $obj;
57 }
58  
59 sub logon {
60 0 ▶ my $self = shift;
Subroutine logon: not called CC=5 SCAR=34.0
Pod documented
61 0 my %arg = @_;
62  
63 0 $arg{ResetSeqNumFlag} = 'Y';
64 0 $MsgSeqNum=0;
65  
66 0 my $msgBody = constructMessage('Logon',\%arg);
67 0 ▶ print "----\nPrepared Logon FIX Message:\n".readableFix($msgBody)."\n" if ($arg{Debug});
Branch: 1 branch
BranchTrueFalseTotal
if $arg{"Debug"} 0 0 0
68  
69 0 my $size = $self->send($msgBody);
70 0 ▶ print " Sent data of length $size\n" if ($arg{Debug});
Branch: 1 branch
BranchTrueFalseTotal
if $arg{"Debug"} 0 0 0
71  
72 # receive a response of up to 1024 characters from server
73 0 my $response = "";
74 0 $self->recv($response, 1024);
75 0 ▶ print "----\nReceived Logon response:\n".readableFix($response)."\n" if ($arg{Debug});
Branch: 1 branch
BranchTrueFalseTotal
if $arg{"Debug"} 0 0 0
76 0 my $parsedResp;
77 0 ▶ $parsedResp = parseFixMessage($response) if ($response);
Branch: 1 branch
BranchTrueFalseTotal
if $response 0 0 0
78 0 ${*$self}->{logon}=$parsedResp;
79 0 ${*$self}->{args}=\%arg;
80 0 return $parsedResp;
81 }
82  
83 sub request {
84 0 ▶ my $self = shift;
Subroutine request: not called CC=9 SCAR=45.0
Pod documented
85 0 my %arg = @_;
86  
87 0 ▶ $arg{SenderCompID} ||= ${*$self}->{args}->{SenderCompID};
Condition0%0/3
$arg{"SenderCompID"} ||= ${*$self;}->{"args"}{"SenderCompID"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$arg{"SenderCompID"} ||= ${*$self;}->{"args"}{"SenderCompID"}
$arg{"SenderCompID"} ${*$self;}->{"args"}{"SenderCompID"}
Truth table0%0/3
A ||= B
A= $arg{"SenderCompID"}B= ${*$self;}->{"args"}{"SenderCompID"}
ABresult
1X1
011
000
88 0 ▶ $arg{TargetCompID} ||= ${*$self}->{args}->{TargetCompID};
Condition0%0/3
$arg{"TargetCompID"} ||= ${*$self;}->{"args"}{"TargetCompID"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$arg{"TargetCompID"} ||= ${*$self;}->{"args"}{"TargetCompID"}
$arg{"TargetCompID"} ${*$self;}->{"args"}{"TargetCompID"}
Truth table0%0/3
A ||= B
A= $arg{"TargetCompID"}B= ${*$self;}->{"args"}{"TargetCompID"}
ABresult
1X1
011
000
89 0 ▶ $arg{TargetSubID} ||= (${*$self}->{args}->{TargetSubID}) ? ${*$self}->{args}->{TargetSubID} : undef;
Branch: 1 branch
BranchTrueFalseTotal
${*$self;}->{'args'}{'TargetSubID'} ? : 0 0 0
Condition0%0/3
$arg{"TargetSubID"} ||= ${*$self;}->{"args"}{"TargetSubID"} ? ${*$self;}->{"args"}{"TargetSubID"} : undef
l!l&&r!l&&!r
000
MC/DC0%0/2
$arg{"TargetSubID"} ||= ${*$self;}->{"args"}{"TargetSubID"} ? ${*$self;}->{"args"}{"TargetSubID"} : undef
$arg{"TargetSubID"} ${*$self;}->{"args"}{"TargetSubID"} ? ${*$self;}->{"args"}{"TargetSubID"} : undef
Truth table0%0/3
A ||= B
A= $arg{"TargetSubID"}B= ${*$self;}->{"args"}{"TargetSubID"} ? ${*$self;}->{"args"}{"TargetSubID"} : undef
ABresult
1X1
011
000
90  
91 0 my $msgBody = constructMessage($arg{MsgType},\%arg);
92 0 ▶ print "----\nPrepared FIX Message:\n".readableFix($msgBody)."\n" if ($arg{Debug});
Branch: 1 branch
BranchTrueFalseTotal
if $arg{"Debug"} 0 0 0
93  
94 0 my $size = $self->send($msgBody);
95 0 ▶ print " Sent data of length $size\n" if ($arg{Debug});
Branch: 1 branch
BranchTrueFalseTotal
if $arg{"Debug"} 0 0 0
96  
97 0 my $response = "";
98  
99 0 $self->recv($response, 4096);
100  
101 0 ▶ print "----\nReceived response:\n".readableFix($response)."\n" if ($arg{Debug});
Branch: 1 branch
BranchTrueFalseTotal
if $arg{"Debug"} 0 0 0
102 0 my $parsedResp;
103 0 ▶ $parsedResp = parseFixMessage($response) if ($response);
Branch: 1 branch
BranchTrueFalseTotal
if $response 0 0 0
104 0 ${*$self}->{request}=$parsedResp;
105  
106 0 return $parsedResp;
107 }
108  
109 sub heartbeat {
110 0 ▶ my $self = shift;
Subroutine heartbeat: not called CC=7 SCAR=40.3
Pod documented
111 0 my %arg = @_;
112  
113 0 ▶ $arg{SenderCompID} ||= ${*$self}->{args}->{SenderCompID};
Condition0%0/3
$arg{"SenderCompID"} ||= ${*$self;}->{"args"}{"SenderCompID"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$arg{"SenderCompID"} ||= ${*$self;}->{"args"}{"SenderCompID"}
$arg{"SenderCompID"} ${*$self;}->{"args"}{"SenderCompID"}
Truth table0%0/3
A ||= B
A= $arg{"SenderCompID"}B= ${*$self;}->{"args"}{"SenderCompID"}
ABresult
1X1
011
000
114 0 ▶ $arg{TargetCompID} ||= ${*$self}->{args}->{TargetCompID};
Condition0%0/3
$arg{"TargetCompID"} ||= ${*$self;}->{"args"}{"TargetCompID"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$arg{"TargetCompID"} ||= ${*$self;}->{"args"}{"TargetCompID"}
$arg{"TargetCompID"} ${*$self;}->{"args"}{"TargetCompID"}
Truth table0%0/3
A ||= B
A= $arg{"TargetCompID"}B= ${*$self;}->{"args"}{"TargetCompID"}
ABresult
1X1
011
000
115 0 ▶ $arg{TargetSubID} ||= (${*$self}->{args}->{TargetSubID}) ? ${*$self}->{args}->{TargetSubID} : undef;
Branch: 1 branch
BranchTrueFalseTotal
${*$self;}->{'args'}{'TargetSubID'} ? : 0 0 0
Condition0%0/3
$arg{"TargetSubID"} ||= ${*$self;}->{"args"}{"TargetSubID"} ? ${*$self;}->{"args"}{"TargetSubID"} : undef
l!l&&r!l&&!r
000
MC/DC0%0/2
$arg{"TargetSubID"} ||= ${*$self;}->{"args"}{"TargetSubID"} ? ${*$self;}->{"args"}{"TargetSubID"} : undef
$arg{"TargetSubID"} ${*$self;}->{"args"}{"TargetSubID"} ? ${*$self;}->{"args"}{"TargetSubID"} : undef
Truth table0%0/3
A ||= B
A= $arg{"TargetSubID"}B= ${*$self;}->{"args"}{"TargetSubID"} ? ${*$self;}->{"args"}{"TargetSubID"} : undef
ABresult
1X1
011
000
116  
117 0 my $msgBody = constructMessage('Heartbeat',\%arg);
118 0 ▶ print "----\nPrepared FIX Heartbeat:\n".readableFix($msgBody)."\n" if ($arg{Debug});
Branch: 1 branch
BranchTrueFalseTotal
if $arg{"Debug"} 0 0 0
119 0 my $size = $self->send($msgBody);
120 0 ▶ print " Sent data of length $size\n" if ($arg{Debug});
Branch: 1 branch
BranchTrueFalseTotal
if $arg{"Debug"} 0 0 0
121 }
122  
123 sub listen {
124 0 ▶ my $self = shift;
Subroutine listen: not called CC=13 SCAR=52.0
Pod documented
125 0 my $handler = shift;
126 0 my %arg = @_;
127  
128 0 ▶ my $HeartBtInt = $arg{HeartBtInt} || $fieldDefaults{HeartBtInt};
Condition0%0/3
$arg{'HeartBtInt'} || $fieldDefaults{'HeartBtInt'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$arg{'HeartBtInt'} || $fieldDefaults{'HeartBtInt'}
$arg{'HeartBtInt'} $fieldDefaults{'HeartBtInt'}
Truth table0%0/3
A || B
A= $arg{'HeartBtInt'}B= $fieldDefaults{'HeartBtInt'}
ABresult
1X1
011
000
129 0 my $response;
130 0 my $lastHbTime = time;
131 0 while (1) {
132 0 my @ready = $sel->can_read(0);
133 0 ▶ if (scalar(@ready)) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @ready) 0 0 0
134 0 my $sock = $ready[0];
135 0 ▶ if (! sysread($ready[0], $response, 4096)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not sysread($ready[0], $response, 4096)) { } 0 0 0
136 0 print "recv failed :$!\n";
137 0 return 1;
138 } else {
139 0 ▶ print "----\nReceived FIX message:\n".readableFix($response)."\n" if ($arg{Debug});
Branch: 1 branch
BranchTrueFalseTotal
if $arg{"Debug"} 0 0 0
140 0 my $parsedResp = parseFixMessage($response);
141 0 ▶ if ( ! defined $parsedResp->{MsgType} ) {
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $parsedResp->{'MsgType'}) { } 0 0 0
elsif ($parsedResp->{'MsgType'} eq '0') { } 0 0 0
elsif ($parsedResp->{'MsgType'} eq '1') { } 0 0 0
142 0 ▶ print " Cannot parse message\n" if ($arg{Debug});
Branch: 1 branch
BranchTrueFalseTotal
if $arg{"Debug"} 0 0 0
143 }
144 elsif ( $parsedResp->{MsgType} eq '0' ) {
145 0 ▶ print " This is heartbeat. Will not pass it to handler\n" if ($arg{Debug});
Branch: 1 branch
BranchTrueFalseTotal
if $arg{"Debug"} 0 0 0
146 }
147 elsif ( $parsedResp->{MsgType} eq '1' ) {
148 0 ▶ my $TestReqID = (defined $parsedResp->{TestReqID})?$parsedResp->{TestReqID}:'TEST';
Branch: 1 branch
BranchTrueFalseTotal
defined $parsedResp->{'TestReqID'} ? : 0 0 0
149 0 ▶ print " This is TestRequest. Will send heartbeat with TestReqID $TestReqID\n" if ($arg{Debug});
Branch: 1 branch
BranchTrueFalseTotal
if $arg{"Debug"} 0 0 0
150 $self->heartbeat(
151 TestReqID => $TestReqID,
152 Debug => $arg{Debug}
153 0 );
154 }
155 else {
156 0 $handler->($parsedResp);
157 }
158 }
159 }
160  
161 0 ▶ if ( time - $lastHbTime > $HeartBtInt ) {
Branch: 1 branch
BranchTrueFalseTotal
if (time - $lastHbTime > $HeartBtInt) 0 0 0
162 0 $lastHbTime = time;
163 0 $self->heartbeat( Debug => $arg{Debug} );
164 }
165 0 select(undef, undef, undef, 0.002);
166  
167 }
168 }
169  
170 sub loggedIn {
171 0 ▶ my $self = shift;
Subroutine loggedIn: not called CC=3 SCAR=24.8
Pod documented
172 0 ▶ return 1 if (defined ${*$self}->{logon}->{'MsgType'} && ${*$self}->{logon}->{'MsgType'} eq getMessageType('Logon'));
Branch: 1 branch
BranchTrueFalseTotal
if defined ${*$self;}->{"logon"}{"MsgType"} and ${*$self;}->{"logon"}{"MsgType"} eq &getMessageType("Logon") 0 0 0
Condition0%0/3
defined ${*$self;}->{"logon"}{"MsgType"} and ${*$self;}->{"logon"}{"MsgType"} eq &getMessageType("Logon")
!ll&&!rl&&r
000
MC/DC0%0/2
defined ${*$self;}->{"logon"}{"MsgType"} and ${*$self;}->{"logon"}{"MsgType"} eq &getMessageType("Logon")
defined ${*$self;}->{"logon"}{"MsgType"} ${*$self;}->{"logon"}{"MsgType"} eq &getMessageType("Logon")
Truth table0%0/3
A and B
A= defined ${*$self;}->{"logon"}{"MsgType"}B= ${*$self;}->{"logon"}{"MsgType"} eq &getMessageType("Logon")
ABresult
0X0
100
111
173 0 return 0;
174 }
175  
176 sub lastRequest {
177 0 ▶ my $self = shift;
Subroutine lastRequest: not called CC=1 SCAR=6.9
Pod documented
178 0 my $field = shift;
179 0 return getFieldDescription($field, ${*$self}->{request}->{$field});
180 }
181  
182 sub constructMessage($$) {
183  
184 0 ▶ my $msgtype = shift;
Subroutine constructMessage: not called CC=22 SCAR=62.3
Pod undocumented
185 0 my $arg = shift;
186 0 my @fields;
187 0 undef $arg->{MsgType};
188 0 $MsgSeqNum++;
189  
190 0 my $time = strftime "%Y%m%d-%H:%M:%S.".getMilliseconds(), gmtime;
191 0 push @fields, getFieldNumber('MsgType')."=".getMessageType($msgtype);
192 0 push @fields, getFieldNumber('SendingTime')."=".$time;
193 0 push @fields, getFieldNumber('MsgSeqNum')."=".$MsgSeqNum;
194  
195 0 my @allFields = ( @{getMessageHeader()}, @{getMessageFields($msgtype)} );
196  
197 0 foreach my $field ( @allFields ) {
198 0 ▶ if ( defined $arg->{$field->{name}} ) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined $$arg{$field->{'name'}}) { } 0 0 0
elsif ($field->{'required'} eq 'Y' and defined $fieldDefaults{$field->{'name'}}) { } 0 0 0
elsif ($field->{'required'} eq 'Y' and $field->{'name'} ne 'BeginString' and $field->{'name'} ne 'BodyLength' and $field->{'name'} ne 'MsgType' and $field->{'name'} ne 'MsgSeqNum' and $field->{'name'} ne 'SendingTime') { } 0 0 0
199 0 ▶ if (ref($arg->{$field->{name}}) eq "HASH") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $$arg{$field->{"name"}} eq "HASH") 0 0 0
200 0 my @tmpFields;
201 0 my $count=0;
202 0 foreach my $component ( keys %{$arg->{$field->{name}}} ) {
203 0 ▶ if (isComponent($component)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&isComponent($component)) { } 0 0 0
204 0 my @componentFields = @{getComponentFields($component)};
205 0 foreach ( @componentFields ) {
206 0 ▶ if ( defined $arg->{$field->{name}}->{$component}->{$_->{name}} ){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$arg{$field->{"name"}}{$component}{$_->{"name"}}) 0 0 0
207 0 my $componentField = $arg->{$field->{name}}->{$component}->{$_->{name}};
208 0 ▶ if ( ref($componentField) eq "ARRAY" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $componentField eq 'ARRAY') { } 0 0 0
209 0 foreach my $entry ( @{$componentField} ) {
210 0 push @tmpFields, getFieldNumber($_->{name})."=".getFieldValue($_->{name},$entry);
211 0 $count++
212 }
213 } else {
214 0 push @tmpFields, getFieldNumber($_->{name})."=".getFieldValue($_->{name},$componentField);
215 0 $count++;
216 }
217 }
218 }
219 } else {
220 0 my $componentField = $arg->{$field->{name}}->{$component};
221 0 ▶ if ( ref($componentField) eq "ARRAY" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $componentField eq 'ARRAY') { } 0 0 0
222 0 foreach my $entry ( @{$componentField} ) {
223 0 push @tmpFields, getFieldNumber($component)."=".getFieldValue($component,$entry);
224 0 $count++
225 }
226 } else {
227 0 push @tmpFields, getFieldNumber($component)."=".getFieldValue($component,$componentField);
228 }
229 }
230
231 }
232 0 push @fields, getFieldNumber($field->{name})."=".$count;
233 0 @fields = ( @fields, @tmpFields );
234 }
235  
236 0 ▶ next if (ref($arg->{$field->{name}}) eq "HASH");
Branch: 1 branch
BranchTrueFalseTotal
if ref $$arg{$field->{"name"}} eq "HASH" 0 0 0
237 0 push @fields, getFieldNumber($field->{name})."=".getFieldValue($field->{name},$arg->{$field->{name}});
238 }
239 ▶ elsif ( $field->{required} eq 'Y' && defined $fieldDefaults{$field->{name}} ) {
Condition0%0/3
$field->{"required"} eq "Y" and defined $fieldDefaults{$field->{"name"}}
!ll&&!rl&&r
000
MC/DC0%0/2
$field->{"required"} eq "Y" and defined $fieldDefaults{$field->{"name"}}
$field->{"required"} eq "Y" defined $fieldDefaults{$field->{"name"}}
Truth table0%0/3
A and B
A= $field->{"required"} eq "Y"B= defined $fieldDefaults{$field->{"name"}}
ABresult
0X0
100
111
240 push @fields, getFieldNumber($field->{name})."=".$fieldDefaults{$field->{name}}
241 0 }
242 ▶ elsif ( $field->{required} eq 'Y' && $field->{name} ne 'BeginString' and $field->{name} ne 'BodyLength'
Condition0%0/15
$field->{"required"} eq "Y" and $field->{"name"} ne "BeginString" and $field->{"name"} ne "BodyLength" and $field->{"name"} ne "MsgType" and $field->{"name"} ne "MsgSeqNum" and $field->{"name"} ne "SendingTime"
!ll&&!rl&&r
000
$field->{"required"} eq "Y" and $field->{"name"} ne "BeginString" and $field->{"name"} ne "BodyLength" and $field->{"name"} ne "MsgType" and $field->{"name"} ne "MsgSeqNum"
!ll&&!rl&&r
000
$field->{"required"} eq "Y" and $field->{"name"} ne "BeginString" and $field->{"name"} ne "BodyLength" and $field->{"name"} ne "MsgType"
!ll&&!rl&&r
000
$field->{"required"} eq "Y" and $field->{"name"} ne "BeginString" and $field->{"name"} ne "BodyLength"
!ll&&!rl&&r
000
$field->{"required"} eq "Y" and $field->{"name"} ne "BeginString"
!ll&&!rl&&r
000
MC/DC0%0/6
$field->{"required"} eq "Y" and $field->{"name"} ne "BeginString" and $field->{"name"} ne "BodyLength" and $field->{"name"} ne "MsgType" and $field->{"name"} ne "MsgSeqNum" and $field->{"name"} ne "SendingTime"
$field->{"required"} eq "Y" $field->{"name"} ne "BeginString" $field->{"name"} ne "BodyLength" $field->{"name"} ne "MsgType" $field->{"name"} ne "MsgSeqNum" $field->{"name"} ne "SendingTime"
Truth table0%0/7
A and B and C and D and E and F
A= $field->{"required"} eq "Y"B= $field->{"name"} ne "BeginString"C= $field->{"name"} ne "BodyLength"D= $field->{"name"} ne "MsgType"E= $field->{"name"} ne "MsgSeqNum"F= $field->{"name"} ne "SendingTime"
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
1110XX0
11110X0
1111100
1111111
243 and $field->{name} ne 'MsgType' and $field->{name} ne 'MsgSeqNum' and $field->{name} ne 'SendingTime') {
244 0 ▶ if ($field->{name} eq "MDReqID") {
Branch: 1 branch
BranchTrueFalseTotal
if ($field->{'name'} eq 'MDReqID') { } 0 0 0
245 0 push @fields, getFieldNumber($field->{name})."=".randomString();
246 } else {
247 0 print "ERROR: $field->{name}\n";
248 }
249 }
250 }
251  
252 0 my $req = join "\x01",@fields;
253 0 $req .= "\x01";
254 0 $req = getFieldNumber('BeginString')."=FIX.4.4\x01".getFieldNumber('BodyLength')."=".length($req)."\x01".$req;
255 0 my $checksum = unpack("%8C*", $req) % 256;
256 0 $checksum = sprintf( "%03d", $checksum );
257 0 $req .= getFieldNumber('CheckSum')."=$checksum\x01";
258 0 return $req."\n";
259 }
260  
261 sub getField($) {
262 0 ▶ my $f = shift;
Subroutine getField: not called CC=1 SCAR=6.9
Pod undocumented
263 0 return $fixDict->{hFields}->{$f};
264 }
265  
266 sub getFieldName($) {
267 0 ▶ my $f = shift;
Subroutine getFieldName: not called CC=2 SCAR=17.9
Pod undocumented
268 0 my $fh = getField($f);
269 0 ▶ return defined $fh ? $fh->{name} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $fh ? : 0 0 0
270 }
271  
272 sub getTagById {
273 0 ▶ my ($self, $f) = @_;
Subroutine getTagById: not called CC=1 SCAR=6.9
Pod documented
274 0 return getFieldName($f);
275 }
276  
277 sub getFieldNumber($) {
278 0 ▶ my $f = shift;
Subroutine getFieldNumber: not called CC=4 SCAR=30.0
Pod undocumented
279 0 ▶ return $f if ( $f =~ /^[0-9]+$/ );
Branch: 1 branch
BranchTrueFalseTotal
if $f =~ /^[0-9]+$/ 0 0 0
280 0 my $fh = getField($f);
281 0 ▶ warn("getFieldNumber($f) returning undef") if !defined $fh;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fh 0 0 0
282 0 ▶ return defined $fh ? $fh->{number} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $fh ? : 0 0 0
283 }
284  
285 sub getFieldValue($$) {
286 0 ▶ my $f = shift;
Subroutine getFieldValue: not called CC=6 SCAR=37.4
Pod undocumented
287 0 my $v = shift;
288 0 ▶ return $v if ( $v =~ /^[0-9]+$/ );
Branch: 1 branch
BranchTrueFalseTotal
if $v =~ /^[0-9]+$/ 0 0 0
289 0 my $fh = getField($f);
290 0 ▶ warn("getField($f) returning undef") if !defined $fh;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fh 0 0 0
291 0 ▶ if ($fh->{enum}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fh->{"enum"}) 0 0 0
292 0 foreach ( @{$fh->{enum}} ) {
293 0 ▶ if ($_->{description} eq $v) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->{"description"} eq $v) 0 0 0
294 0 return $_->{name};
295 }
296 }
297 }
298 0 return $v;
299 }
300  
301 sub getFieldDescription($$) {
302 0 ▶ my $f = shift;
Subroutine getFieldDescription: not called CC=5 SCAR=34.0
Pod undocumented
303 0 my $v = shift;
304 0 my $fh = getField($f);
305 0 ▶ warn("getField($f) returning undef") if !defined $fh;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fh 0 0 0
306 0 ▶ if ($fh->{enum}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fh->{"enum"}) 0 0 0
307 0 foreach ( @{$fh->{enum}} ) {
308 0 ▶ if ($_->{name} eq $v) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->{"name"} eq $v) 0 0 0
309 0 return $_->{description};
310 }
311 }
312 }
313 0 return $v;
314 }
315  
316 sub getMessage($) {
317 0 ▶ my $f = shift;
Subroutine getMessage: not called CC=1 SCAR=6.9
Pod undocumented
318 0 return $fixDict->{hMessages}->{$f};
319 }
320  
321 sub getMessageType($) {
322 0 ▶ my $f = shift;
Subroutine getMessageType: not called CC=4 SCAR=30.0
Pod undocumented
323 0 ▶ return $f if ( $f =~ /^[0-9]+$/ );
Branch: 1 branch
BranchTrueFalseTotal
if $f =~ /^[0-9]+$/ 0 0 0
324 0 my $fh = getMessage($f);
325 0 ▶ warn("getMessage($f) returning undef") if !defined $fh;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fh 0 0 0
326 0 ▶ return defined $fh ? $fh->{msgtype} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $fh ? : 0 0 0
327 }
328  
329 sub getMessageName($) {
330 0 ▶ my $f = shift;
Subroutine getMessageName: not called CC=3 SCAR=24.8
Pod undocumented
331 0 my $fh = getMessage($f);
332 0 ▶ warn("getMessage($f) returning undef") if !defined $fh;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fh 0 0 0
333 0 ▶ return defined $fh ? $fh->{name} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $fh ? : 0 0 0
334 }
335  
336 sub getMsgByType {
337 0 ▶ my ($self, $f) = @_;
Subroutine getMsgByType: not called CC=1 SCAR=6.9
Pod documented
338 0 return getMessageName($f);
339 }
340  
341 sub getMessageFields($) {
342 0 ▶ my $f = shift;
Subroutine getMessageFields: not called CC=3 SCAR=24.8
Pod undocumented
343 0 my $fh = getMessage($f);
344 0 ▶ warn("getMessage($f) returning undef") if !defined $fh;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fh 0 0 0
345 0 ▶ return defined $fh ? $fh->{fields} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $fh ? : 0 0 0
346 }
347  
348 sub getMessageHeader {
349 0 ▶ return $fixDict->{header};
Subroutine getMessageHeader: not called CC=1 SCAR=6.9
Pod undocumented
350 }
351  
352 sub getComponent($) {
353 0 ▶ my $f = shift;
Subroutine getComponent: not called CC=1 SCAR=6.9
Pod undocumented
354 0 return $fixDict->{hComponents}->{$f};
355 }
356  
357 sub isComponent($) {
358 0 ▶ my $f = shift;
Subroutine isComponent: not called CC=1 SCAR=6.9
Pod undocumented
359 0 return defined $fixDict->{hComponents}->{$f};
360 }
361  
362 sub getComponentFields($) {
363 0 ▶ my $f = shift;
Subroutine getComponentFields: not called CC=3 SCAR=24.8
Pod undocumented
364 0 my $fh = getComponent($f);
365 0 ▶ warn("getComponent($f) returning undef") if !defined $fh;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fh 0 0 0
366 0 ▶ return defined $fh ? $fh->{fields} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $fh ? : 0 0 0
367 }
368  
369 sub parseFixMessage {
370 0 ▶ my $message = shift;
Subroutine parseFixMessage: not called CC=3 SCAR=24.8
Pod undocumented
371 0 my $nodes;
372 0 for my $node ( split /\x01/, $message ) { # Split on "SOH"
373 0 my @kvp = split /=/, $node;
374 0 ▶ if (scalar @kvp == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @kvp == 2) 0 0 0
375 0 $nodes->{$kvp[0]}=$kvp[1];
376 0 $nodes->{getFieldName($kvp[0])}=$kvp[1];
377 }
378 }
379 0 return $nodes;
380 }
381  
382 sub randomString {
383 0 ▶ my @chars = ("A".."Z", "a".."z");
Subroutine randomString: not called CC=2 SCAR=17.9
Pod undocumented
384 0 my $string;
385 0 $string .= $chars[rand @chars] for 1..6;
386 0 return $string;
387 }
388  
389 sub readableFix {
390 0 ▶ my $fixMsg = shift;
Subroutine readableFix: not called CC=1 SCAR=6.9
Pod undocumented
391 0 $fixMsg =~ s/\x01/\|/g;
392 0 return $fixMsg;
393 }
394  
395 sub quit {
396 0 ▶ my $self = shift;
Subroutine quit: not called CC=1 SCAR=6.9
Pod documented
397  
398 0 $self->close;
399 }
400  
401 sub getMilliseconds {
402 0 ▶ my $time = gettimeofday;
Subroutine getMilliseconds: not called CC=1 SCAR=6.9
Pod undocumented
403 0 return sprintf("%03d",int(($time-int($time))*1000));
404 }
405 1 1; # End of FIX::Lite
406 __END__
↑ Summary Lite/Dictionary.pm »