FIX.pm

filter: Statementstmt 96.5% 225 / 233 Branchbran 75.0% 33 / 44 Conditioncond 37.5% 6 / 16 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 100% 33 / 33 Podpod 100% 14 / 14 totaltotal 89.3% 311 / 348 CC 31 SCAR 12.3
CC
31
Cov
90%
_construct_components
7.0
is_composite
6.6
_construct_messages
6.0
CRAP 3.4
« FIX/Message.pm ↑ Summary FIX/Group.pm »
1 package Protocol::FIX;
2 # ABSTRACT: Financial Information eXchange (FIX) messages parser/serializer
3  
4 18 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 18 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 18 ▶use XML::Fast;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 18 ▶use File::ShareDir qw/dist_dir/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 18 ▶use Path::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 18 ▶use Protocol::FIX::Component;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 18 ▶use Protocol::FIX::Field;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 18 ▶use Protocol::FIX::Group;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 18 ▶use Protocol::FIX::BaseComposite;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 18 ▶use Protocol::FIX::Message;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 18 ▶use Protocol::FIX::Parser;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 18 ▶use Exporter qw/import/;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 18 our @EXPORT_OK = qw/humanize/;
20 18 our $VERSION = '0.08';
21  
22 =head1 NAME
23  
24 Protocol::FIX - Financial Information eXchange (FIX) messages parser/serializer
25  
26 =head1 SYNOPSIS
27  
28 use Protocol::FIX;
29  
30 my $proto = Protocol::FIX->new('FIX44')->extension('t/data/extension-sample.xml');
31  
32 my $serialized = $proto->serialize_message('IOI', [
33 SenderCompID => 'me',
34 TargetCompID => 'you',
35 MsgSeqNum => 1,
36 SendingTime => '20090107-18:15:16',
37 IOIID => 'abc',
38 IOITransType => 'CANCEL',
39 IOIQty => 'LARGE',
40 Side => 'BORROW',
41 Instrument => [
42 Symbol => 'EURUSD',
43 EvntGrp => [ NoEvents => [ [EventType => 'PUT'], [EventType => 'CALL'], [EventType => 'OTHER'] ] ],
44 ],
45 OrderQtyData => [
46 OrderQty => '499',
47 ],
48 ]);
49 # managed fields (BeginString, MsgType, and CheckSum) are handled automatically,
50 # no need to provide them
51  
52 my ($message_instance, $error) = $proto->parse_message(\$serialized);
53 print("No error on parsing message");
54 print "Message, ", $message_instance->name, " / ", $message_instance->category, "\n";
55  
56 print "Field 'SenderCompID' value: ", $message_instance->value('SenderCompID'), "\n";
57  
58 print "Component 'OrderQtyData' access: ",
59 $message_instance->value('OrderQtyData')->value('OrderQty'), "\n";
60  
61 my $group = $message_instance->value('Instrument')->value('EvntGrp')->value('NoEvents');
62 print "0th group 'NoEvents' of component 'Instrument/EvntGrp' access: ",
63 $group->[0]->value('EventType'), "\n";
64  
65 my $buff = '';
66 ($message_instance, $error) = $proto->parse_message(\$buff);
67 # no error nor message_instance, as there is no enough data.
68  
69 See also the "eg" folder for sample of FIX-server.
70  
71 =head1 DESCRIPTION
72  
73 With this module you can easily create new FIX messages in human-readable way, i.e. use
74 names like OrderQty => '499', instead of directly wring string like '39=499'; and vise
75 versa, you can parse the gibberish FIX messages to access fields in human-readable way
76 too.
77  
78 The module checks that mandatory fields are present, and that field values bypass
79 the validation.
80  
81 =cut
82  
83 18 my $distribution = 'Protocol-FIX';
84  
85 18 my %MANAGED_COMPOSITES = map { $_ => 1 } qw/BeginString BodyLength MsgType CheckSum/;
86  
87 18 my %specification_for = (fix44 => 'FIX44.xml');
88  
89 18 our $SEPARATOR = "\x{01}";
90 18 our $TAG_SEPARATOR = "=";
91  
92 =head1 METHODS
93  
94 =head3 new
95  
96 new($class, $version)
97  
98 Creates new protocol instance for the specified FIX protocol version. Currently
99 shipped version is 'FIX44'.
100  
101 The xml with protocol definition was taken at L<http://quickfixengine.org/>.
102  
103 =cut
104  
105 7 ▶sub new {
Subroutine new: called CC=4 SCAR=14.6
Pod documented
106 7 my ($class, $version) = @_;
107 7 ▶ die("FIX protocol version should be specified")
Branch: 1 branch
BranchTrueFalseTotal
unless $version 0 7 7
108 unless $version;
109  
110 7 my $file = $specification_for{lc $version};
111 0 ▶ die("Unsupported FIX protocol version: $version. Supported versions are: " . join(", ", sort { $a cmp $b } keys %specification_for))
Branch: 1 branch
BranchTrueFalseTotal
unless $file 0 7 7
112 unless $file;
113  
114 7 ▶ my $dir = $ENV{PROTOCOL_FIX_SHARE_DIR} // dist_dir($distribution);
Condition33%1/3
$ENV{"PROTOCOL_FIX_SHARE_DIR"} // dist_dir($distribution)
l!l&&r!l&&!r
070
MC/DC0%0/2
$ENV{"PROTOCOL_FIX_SHARE_DIR"} // dist_dir($distribution)
$ENV{"PROTOCOL_FIX_SHARE_DIR"} dist_dir($distribution)
Truth table33%1/3
A // B
A= $ENV{"PROTOCOL_FIX_SHARE_DIR"}B= dist_dir($distribution)
ABresult
1X1
011
000
115 7 my $xml = path("$dir/$file")->slurp;
116 7 my $protocol_definition = xml2hash $xml;
117 7 my $obj = {
118 version => lc $version,
119 };
120 7 bless $obj, $class;
121 7 $obj->_construct_from_definition($protocol_definition);
122 7 return $obj;
123 }
124  
125 =head3 extension
126  
127 extension($self, $extension_path)
128  
129 Modifies the protocol, by loading XML extension.
130  
131 The extension might contain additional B<messages> or B<fields>. The
132 extension XML should conform the format as the protocol definition itself,
133 i.e.:
134  
135 <fix type='FIX' major='4' minor='4' servicepack='0'>
136 <messages>
137 <message name='Logon' msgtype='A' msgcat='admin'>
138 <field name='EncryptMethod' required='Y' />
139 <field name='HeartBtInt' required='Y' />
140 <field name='ResetSeqNumFlag' required='N' />
141 <field name='Username' required='N' />
142 <field name='Password' required='N' />
143 <field name='AwesomeField' required='Y' />
144 </message>
145 </messages>
146 <fields>
147 <field number='33000' name='AwesomeField' type='STRING' />
148 </fields>
149 </fix>
150  
151 =cut
152  
153 2 ▶sub extension {
Subroutine extension: called CC=2 SCAR=6.9
Pod documented
154 2 my ($self, $extension_path) = @_;
155  
156 2 my $xml = path($extension_path)->slurp;
157 2 my $definition = xml2hash $xml;
158  
159 2 my ($type, $major, $minor) = @{$definition->{fix}}{qw/-type -major -minor/};
160 2 my $extension_id = join('.', $type, $major, $minor);
161 2 my $protocol_id = $self->{id};
162 2 ▶ die("Extension ID ($extension_id) does not match Protocol ID ($protocol_id)")
Branch: 1 branch
BranchTrueFalseTotal
unless $extension_id eq $protocol_id 0 2 2
163 unless $extension_id eq $protocol_id;
164  
165 2 my $new_fields_lookup = $self->_construct_fields($definition);
166 2 _merge_lookups($self->{fields_lookup}->{by_name}, $new_fields_lookup->{by_name});
167 2 _merge_lookups($self->{fields_lookup}->{by_number}, $new_fields_lookup->{by_number});
168  
169 2 my $new_messsages_lookup = $self->_construct_messages($definition);
170 2 _merge_lookups($self->{messages_lookup}->{by_name}, $new_messsages_lookup->{by_name});
171 2 _merge_lookups($self->{messages_lookup}->{by_number}, $new_messsages_lookup->{by_number});
172  
173 2 return $self;
174 }
175  
176 =head3 serialize_message
177  
178 serialize_message($self, $message_name, $payload)
179  
180 Returns serialized string for the supplied C<$message_name> and C<$payload>.
181 Dies in case of end-user (developer) error, e.g. if mandatory field is
182 absent.
183  
184 =cut
185  
186 11 ▶sub serialize_message {
Subroutine serialize_message: called CC=1 SCAR=0.0
Pod documented
187 11 my ($self, $message_name, $payload) = @_;
188 11 my $message = $self->message_by_name($message_name);
189 11 return $message->serialize($payload);
190 }
191  
192 =head3 parse_message
193  
194 parse_message($self, $buff_ref)
195  
196 my ($message_instance, $error) = $protocol->parse($buff_ref);
197  
198 Tries to parse FIX message in the buffer refernce.
199  
200 In the case of success it returns C<MessageInstance> and C<$error> is undef.
201 The string in C<$buff_ref> will be consumed.
202  
203 In the case of B<protocol error>, the C<$message_instance> will be undef,
204 and C<$error> will contain the error description. The string in C<$buff_ref>
205 will be kept untouched.
206  
207 In the case, when there is no enough data in C<$buff_ref> both C<$error>
208 and C<$message_instance> will be undef. The string in C<$buff_ref>
209 will be kept untouched, i.e. waiting futher accumulation of bytes from
210 network.
211  
212 In other cases it dies; that indicates either end-user (developer) error
213 or bug in the module.
214  
215 =cut
216  
217 124 ▶sub parse_message {
Subroutine parse_message: called CC=1 SCAR=0.0
Pod documented
218 124 return Protocol::FIX::Parser::parse(@_);
219 }
220  
221 9 ▶sub _construct_fields {
Subroutine _construct_fields: called CC=5 SCAR=16.1
222 9 my ($self, $definition) = @_;
223  
224 9 my $fields_lookup = {
225 by_number => {},
226 by_name => {},
227 };
228  
229 9 my $fields_arr = $definition->{fix}->{fields}->{field};
230 9 ▶ $fields_arr = [$fields_arr] if ref($fields_arr) ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $fields_arr ne "ARRAY" 2 7 9
231  
232 9 for my $field_descr (@$fields_arr) {
233 6386 my ($name, $number, $type) = map { $field_descr->{$_} } qw/-name -number -type/;
234 6386 my $values;
235 6386 my $values_arr = $field_descr->{value};
236 6386 ▶ if ($values_arr) {
Branch: 1 branch
BranchTrueFalseTotal
if ($values_arr) 1715 4671 6386
237 1715 for my $value_desc (@$values_arr) {
238 11956 my ($key, $description) = map { $value_desc->{$_} } qw/-enum -description/;
239 11956 $values->{$key} = $description;
240 }
241 }
242 6386 my $field = Protocol::FIX::Field->new($number, $name, $type, $values);
243 6386 $fields_lookup->{by_number}->{$number} = $field;
244 6386 $fields_lookup->{by_name}->{$name} = $field;
245 }
246  
247 9 return $fields_lookup;
248 }
249  
250 4918 ▶sub _get_composites {
Subroutine _get_composites: called CC=4 SCAR=13.9
251 4918 my ($values, $lookup) = @_;
252 4918 ▶ return () unless $values;
Branch: 1 branch
BranchTrueFalseTotal
unless $values 2235 2683 4918
253  
254 2683 ▶ my $array = ref($values) ne 'ARRAY' ? [$values] : $values;
Branch: 1 branch
BranchTrueFalseTotal
ref $values ne 'ARRAY' ? : 539 2144 2683
255 my @composites = map {
256 2683 my $ref = $_;
257 22594 my $name = $ref->{-name};
258 22594 my $required = $ref->{-required} eq 'Y';
259 22594 my $composite = $lookup->{by_name}->{$name};
260  
261 22594 ▶ die($name) unless $composite;
Branch: 1 branch
BranchTrueFalseTotal
unless $composite 441 22153 22594
262  
263 22153 ($composite, $required);
264 } @$array;
265 2242 return @composites;
266 }
267  
268 7 ▶sub _construct_components {
Subroutine _construct_components: called CC=7 SCAR=19.5
269 7 my ($self, $definition, $fields_lookup) = @_;
270  
271 7 my $components_lookup = {
272 by_name => {},
273 };
274  
275 7 my @components_queue = map { $_->{-type} = 'component'; $_; } @{$definition->{fix}->{components}->{component}};
276 OUTER:
277 7 ▶ while (my $component_descr = shift @components_queue) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $component_descr = shift @components_queue) 1169 7 1176
278 1169 my @composites;
279 1169 my $name = $component_descr->{-name};
280  
281 1169 my $fatal = 0;
282 1169 my $eval_result = eval {
283 1169 push @composites, _get_composites($component_descr->{component}, $components_lookup);
284  
285 1127 my $group_descr = $component_descr->{group};
286 1127 ▶ if ($group_descr) {
Branch: 1 branch
BranchTrueFalseTotal
if ($group_descr) 1036 91 1127
287 1036 my @group_composites;
288  
289 # we might fail to construct group as dependent components might not be
290 # constructed yet
291 1036 push @group_composites, _get_composites($group_descr->{component}, $components_lookup);
292  
293 # now we should be able to construct group
294 637 $fatal = 1;
295 637 push @group_composites, _get_composites($group_descr->{field}, $fields_lookup);
296  
297 637 my $group_name = $group_descr->{-name};
298 637 ▶ my $base_field = $fields_lookup->{by_name}->{$group_name}
Condition50%1/2
$fields_lookup->{"by_name"}{$group_name} // die("$group_name refers field '${group_name}', which is not available")
l!l
6370
MC/DC0%0/1
$fields_lookup->{"by_name"}{$group_name} // die("$group_name refers field '${group_name}', which is not available")
$fields_lookup->{"by_name"}{$group_name}
Truth table50%1/2
A
A= $fields_lookup->{"by_name"}{$group_name}
Aresult
11
00
299 // die("${group_name} refers field '${group_name}', which is not available");
300 637 my $group = Protocol::FIX::Group->new($base_field, \@group_composites);
301  
302 637 my $group_required = $group_descr->{-required} eq 'Y';
303 637 push @composites, $group => $group_required;
304 }
305 728 1;
306 };
307 1169 ▶ if (!$eval_result) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($eval_result) 441 728 1169
308 441 ▶ die("$@") if ($fatal);
Branch: 1 branch
BranchTrueFalseTotal
if $fatal 0 441 441
309 # not constructed yet, postpone current component construction
310 441 push @components_queue, $component_descr;
311 441 next OUTER;
312 }
313  
314 728 $eval_result = eval { push @composites, _get_composites($component_descr->{field}, $fields_lookup); 1 };
315 728 ▶ if (!$eval_result) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($eval_result) 0 728 728
316 # make it human friendly
317 0 die("Cannot find field '$@' referred by '$name'");
318 }
319  
320 728 my $component = Protocol::FIX::Component->new($name, \@composites);
321 728 $components_lookup->{by_name}->{$name} = $component;
322 }
323  
324 7 return $components_lookup;
325 }
326  
327 14 ▶sub _construct_composite {
Subroutine _construct_composite: called CC=2 SCAR=7.1
328 14 my ($self, $name, $descr, $fields_lookup, $components_lookup) = @_;
329  
330 14 my @composites;
331 14 my $eval_result = eval {
332 14 push @composites, _get_composites($descr->{field}, $fields_lookup);
333 14 push @composites, _get_composites($descr->{component}, $components_lookup);
334 14 1;
335 };
336 14 ▶ if (!$eval_result) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($eval_result) 0 14 14
337 0 die("Cannot find composite '$@', referred in '$name'");
338 }
339  
340 14 return Protocol::FIX::BaseComposite->new($name, $name, \@composites);
341 }
342  
343 9 ▶sub _construct_messages {
Subroutine _construct_messages: called CC=6 SCAR=17.9
344 9 my ($self, $definition) = @_;
345  
346 9 my $messages_lookup = {
347 by_name => {},
348 by_number => {},
349 };
350 9 my $fields_lookup = $self->{fields_lookup};
351 9 my $components_lookup = $self->{components_lookup};
352  
353 9 my $messages_arr = $definition->{fix}->{messages}->{message};
354 9 ▶ $messages_arr = [$messages_arr] unless ref($messages_arr) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $messages_arr eq "ARRAY" 2 7 9
355  
356 9 my @messages_queue = @$messages_arr;
357 9 ▶ while (my $message_descr = shift @messages_queue) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $message_descr = shift @messages_queue) 653 9 662
358 653 my @composites;
359 653 my ($name, $category, $message_type) = map { $message_descr->{$_} } qw/-name -msgcat -msgtype/;
360  
361 653 my $eval_result = eval {
362 653 push @composites, _get_composites($message_descr->{field}, $fields_lookup);
363 653 push @composites, _get_composites($message_descr->{component}, $components_lookup);
364 653 1;
365 };
366 653 ▶ if (!$eval_result) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($eval_result) 0 653 653
367 # make it human friendly
368 0 die("Cannot find field '$@' referred by '$name'");
369 }
370  
371 653 my $group_descr = $message_descr->{group};
372 # no need to protect with eval, as all fields/components should be availble.
373 # if something is missing this is fatal
374 653 ▶ if ($group_descr) {
Branch: 1 branch
BranchTrueFalseTotal
if ($group_descr) 7 646 653
375 7 my @group_composites;
376  
377 7 push @group_composites, _get_composites($group_descr->{component}, $components_lookup);
378 7 push @group_composites, _get_composites($group_descr->{field}, $fields_lookup);
379  
380 7 my $group_name = $group_descr->{-name};
381 7 ▶ my $base_field = $fields_lookup->{by_name}->{$group_name} // die("${group_name} refers field '${group_name}', which is not available");
Condition50%1/2
$fields_lookup->{"by_name"}{$group_name} // die("$group_name refers field '${group_name}', which is not available")
l!l
70
MC/DC0%0/1
$fields_lookup->{"by_name"}{$group_name} // die("$group_name refers field '${group_name}', which is not available")
$fields_lookup->{"by_name"}{$group_name}
Truth table50%1/2
A
A= $fields_lookup->{"by_name"}{$group_name}
Aresult
11
00
382 7 my $group = Protocol::FIX::Group->new($base_field, \@group_composites);
383  
384 7 my $group_required = $group_descr->{-required} eq 'Y';
385 7 push @composites, $group => $group_required;
386 }
387  
388 653 my $message = Protocol::FIX::Message->new($name, $category, $message_type, \@composites, $self);
389 653 $messages_lookup->{by_name}->{$name} = $message;
390 653 $messages_lookup->{by_number}->{$message_type} = $message;
391 }
392  
393 9 return $messages_lookup;
394 }
395  
396 7 ▶sub _construct_from_definition {
Subroutine _construct_from_definition: called CC=1 SCAR=0.0
397 7 my ($self, $definition) = @_;
398  
399 7 my ($type, $major, $minor) = @{$definition->{fix}}{qw/-type -major -minor/};
400 7 my $protocol_id = join('.', $type, $major, $minor);
401  
402 7 my $fields_lookup = $self->_construct_fields($definition);
403 7 my $components_lookup = $self->_construct_components($definition, $fields_lookup);
404  
405 7 my $header_descr = $definition->{fix}->{header};
406 7 my $trailer_descr = $definition->{fix}->{trailer};
407 7 my $header = $self->_construct_composite('header', $header_descr, $fields_lookup, $components_lookup);
408 7 my $trailer = $self->_construct_composite('trailer', $trailer_descr, $fields_lookup, $components_lookup);
409  
410 7 my $serialized_begin_string = $fields_lookup->{by_name}->{BeginString}->serialize($protocol_id);
411  
412 7 $self->{id} = $protocol_id;
413 7 $self->{header} = $header;
414 7 $self->{trailer} = $trailer;
415 7 $self->{fields_lookup} = $fields_lookup;
416 7 $self->{components_lookup} = $components_lookup;
417 7 $self->{begin_string} = $serialized_begin_string;
418  
419 7 my $messages_lookup = $self->_construct_messages($definition);
420 7 $self->{messages_lookup} = $messages_lookup;
421  
422 7 return;
423 }
424  
425 8 ▶sub _merge_lookups {
Subroutine _merge_lookups: called CC=1 SCAR=0.0
426 8 my ($old, $new) = @_;
427 8 @{$old}{keys %$new} = values %$new;
428 8 return;
429 }
430  
431 =head1 METHODS (for protocol developers)
432  
433 =head3 humanize
434  
435 humanize ($buffer)
436  
437 Returns human-readable string for the buffer. I.e. is just substitutes
438 L<SOH|https://en.wikipedia.org/wiki/C0_and_C1_control_codes> to " | ".
439  
440 This might be usable during development of own FIX-client/server.
441  
442 =cut
443  
444 25 ▶sub humanize {
Subroutine humanize: called CC=1 SCAR=0.0
Pod documented
445 25 my $s = shift;
446 25 return $s =~ s/\x{01}/ | /gr;
447 }
448  
449 =head3 is_composite
450  
451 is_composite($object)
452  
453 Checks whether the supplied C<$object> conforms "composte" concept.
454 I.e. is it is L<Field>, L<LGroup>, L<Component> or L<Mesassage>.
455  
456 =cut
457  
458 39737 ▶sub is_composite {
Subroutine is_composite: called CC=4 SCAR=18.9
Pod documented
459 39737 my $obj = shift;
460 return
461 defined($obj)
462 && UNIVERSAL::can($obj, 'serialize')
463 && exists $obj->{name}
464 39737 ▶ && exists $obj->{type};
Condition33%3/9
defined $obj && UNIVERSAL::can($obj, 'serialize') && exists $obj->{'name'} && exists $obj->{'type'}
!ll&&!rl&&r
0039737
defined $obj and UNIVERSAL::can($obj, "serialize") and exists $obj->{"name"}
!ll&&!rl&&r
0039737
defined $obj and UNIVERSAL::can($obj, "serialize")
!ll&&!rl&&r
0039737
MC/DC0%0/4
defined $obj && UNIVERSAL::can($obj, 'serialize') && exists $obj->{'name'} && exists $obj->{'type'}
defined $obj UNIVERSAL::can($obj, "serialize") exists $obj->{"name"} exists $obj->{'type'}
Truth table20%1/5
A and B and C && D
A= defined $objB= UNIVERSAL::can($obj, "serialize")C= exists $obj->{"name"}D= exists $obj->{'type'}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
465 }
466  
467 =head3 field_by_name
468  
469 field_by_name($self, $field_name)
470  
471 Returns Field object by it's name or dies with error.
472  
473 =cut
474  
475 1988 ▶sub field_by_name {
Subroutine field_by_name: called CC=2 SCAR=7.4
Pod documented
476 1988 my ($self, $field_name) = @_;
477 1988 my $field = $self->{fields_lookup}->{by_name}->{$field_name};
478 1988 ▶ if (!$field) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($field) 0 1988 1988
479 0 die("Field '$field_name' is not available in protocol " . $self->{version});
480 }
481 1988 return $field;
482 }
483  
484 =head3 field_by_number
485  
486 field_by_number($self, $field_number)
487  
488 Returns Field object by it's number or dies with error.
489  
490 =cut
491  
492 2 ▶sub field_by_number {
Subroutine field_by_number: called CC=2 SCAR=7.4
Pod documented
493 2 my ($self, $field_number) = @_;
494 2 my $field = $self->{fields_lookup}->{by_number}->{$field_number};
495 2 ▶ if (!$field) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($field) 0 2 2
496 0 die("Field $field_number is not available in protocol " . $self->{version});
497 }
498 2 return $field;
499 }
500  
501 =head3 component_by_name
502  
503 component_by_name($self, $name)
504  
505 Returns Component object by it's name or dies with error.
506  
507 =cut
508  
509 11 ▶sub component_by_name {
Subroutine component_by_name: called CC=2 SCAR=7.4
Pod documented
510 11 my ($self, $name) = @_;
511 11 my $component = $self->{components_lookup}->{by_name}->{$name};
512 11 ▶ if (!$component) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($component) 0 11 11
513 0 die("Component '$name' is not available in protocol " . $self->{version});
514 }
515 11 return $component;
516 }
517  
518 =head3 message_by_name
519  
520 message_by_name($self, $name)
521  
522 Returns Message object by it's name or dies with error.
523  
524 =cut
525  
526 20 ▶sub message_by_name {
Subroutine message_by_name: called CC=2 SCAR=7.4
Pod documented
527 20 my ($self, $name) = @_;
528 20 my $message = $self->{messages_lookup}->{by_name}->{$name};
529 20 ▶ if (!$message) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($message) 0 20 20
530 0 die("Message '$name' is not available in protocol " . $self->{version});
531 }
532 20 return $message;
533 }
534  
535 =head3 header
536  
537 header($self)
538  
539 Returns Message's header
540  
541 =cut
542  
543 656 ▶sub header {
Subroutine header: called CC=1 SCAR=0.0
Pod documented
544 656 return shift->{header};
545 }
546  
547 =head3 trailer
548  
549 trailer($self)
550  
551 Returns Message's trailer
552  
553 =cut
554  
555 656 ▶sub trailer {
Subroutine trailer: called CC=1 SCAR=0.0
Pod documented
556 656 return shift->{trailer};
557 }
558  
559 =head3 id
560  
561 id($self)
562  
563 Returns Protocol's ID string, as it appears in FIX message (BeginString field).
564  
565 =cut
566  
567 1 ▶sub id {
Subroutine id: called CC=1 SCAR=0.0
Pod documented
568 1 return shift->{id};
569 }
570  
571 =head3 managed_composites
572  
573 managed_composites()
574  
575 Returns list of fields, managed by protocol. Currently the list consists of
576 fields: BeginString, MsgType, and CheckSum
577  
578 =cut
579  
580 34596 ▶sub managed_composites {
Subroutine managed_composites: called CC=1 SCAR=0.0
Pod documented
581 34596 return \%MANAGED_COMPOSITES;
582 }
583  
584 18 1;
« FIX/Message.pm ↑ Summary FIX/Group.pm »