| 1 | package Protocol::FIX::Message; | ||||||||||||||||||||||||||||
| 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 | ▶ | use mro; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 18 | ▶ | use parent qw/Protocol::FIX::BaseComposite/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 18 | our $VERSION = '0.08'; ## VERSION | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | =head1 NAME | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | Protocol::FIX::Message - FIX protocol message definition | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | =cut | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | =head1 METHODS | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | =head3 serialize | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | serialize($self, $values) | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | Serializes provided values into string. | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | $message->serialize([ | ||||||||||||||||||||||||||||
| 28 | field => 'value', | ||||||||||||||||||||||||||||
| 29 | component => [ | ||||||||||||||||||||||||||||
| 30 | other_field => 'value-2', | ||||||||||||||||||||||||||||
| 31 | group_field => [ | ||||||||||||||||||||||||||||
| 32 | [some_field_1 => 'value-3.1.1', some_field_1 => 'value-3.1.2'], | ||||||||||||||||||||||||||||
| 33 | [some_field_1 => 'value-3.2.1', some_field_1 => 'value-3.2.2'], | ||||||||||||||||||||||||||||
| 34 | ], | ||||||||||||||||||||||||||||
| 35 | ], | ||||||||||||||||||||||||||||
| 36 | ]); | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | Error will be thrown if values do not conform the specification (e.g. | ||||||||||||||||||||||||||||
| 39 | string provided, while integer is expected). | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | The B<managed fields> (BeginString, MsgType, and CheckSum) are calculated and | ||||||||||||||||||||||||||||
| 42 | added to serialized string automatically. | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | =cut | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 17 | ▶ | sub serialize { | ||||||||||||||||||||||||||
|
Subroutine
serialize: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 47 | 17 | my ($self, $values) = @_; | |||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | # the SOH / trailing separator is part of the body, and it is included | ||||||||||||||||||||||||||||
| 50 | # in body length and checksum | ||||||||||||||||||||||||||||
| 51 | 17 | my $body = join($Protocol::FIX::SEPARATOR, $self->{serialized}->{message_type}, $self->next::method($values), ''); | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 10 | my $body_length = $self->{managed_composites}->{BodyLength}->serialize(length($body)); | |||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 10 | my $header_body = join($Protocol::FIX::SEPARATOR, $self->{serialized}->{begin_string}, $body_length, $body); | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 10 | my $sum = 0; | |||||||||||||||||||||||||||
| 58 | 10 | $sum += ord $_ for split //, $header_body; | |||||||||||||||||||||||||||
| 59 | 10 | $sum %= 256; | |||||||||||||||||||||||||||
| 60 | 10 | my $checksum = $self->{managed_composites}->{CheckSum}->serialize(sprintf('%03d', $sum)); | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 10 | return $header_body . join($Protocol::FIX::SEPARATOR, $checksum, ''); | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | =head1 METHODS (for protocol developers) | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | =head3 new | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | new($class, $name, $category, $message_type, $composites, $protocol) | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | Creates new Message (performed by Protocol, when it parses XML definition) | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | =cut | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 655 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=6 SCAR=18.1
Pod
documented
| |||||||||||||||||||||||||||||
| 76 | 655 | my ($class, $name, $category, $message_type, $composites, $protocol) = @_; | |||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 655 | my $message_type_field = $protocol->field_by_name('MsgType'); | |||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 655 | my $message_type_string = $message_type_field->{values}->{by_id}->{$message_type}; | |||||||||||||||||||||||||||
| 81 | 655 | ▶ | die "specified message type '$message_type' is not available in protocol" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | unless defined $message_type_string; | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 655 | my $serialized_message_type = $message_type_field->serialize($message_type_string); | |||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 655 | ▶ | die "message category must be defined" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $category and $category =~ /.+/
MC/DC0%0/2
defined $category and $category =~ /.+/
defined $category
$category =~ /.+/
Truth table33%1/3
A and B
A= defined $categoryB= $category =~ /.+/
| |||||||||||||||||||||||||||||
| 87 | if (!defined($category) || $category !~ /.+/); | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 655 | my @all_composites = (@{$protocol->header->{composites}}, @$composites, @{$protocol->trailer->{composites}}); | |||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 655 | my @body_composites; | |||||||||||||||||||||||||||
| 92 | 655 | ▶ | for (my $idx = 0; $idx < @all_composites; $idx += 2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | 34596 | my $c = $all_composites[$idx]; | |||||||||||||||||||||||||||
| 94 | 34596 | ▶ | next if exists $protocol->managed_composites->{$c->{name}}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 31976 | push @body_composites, $c, $all_composites[$idx + 1]; | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 655 | my $obj = next::method($class, $name, 'message', \@body_composites); | |||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 655 | $obj->{category} = $category; | |||||||||||||||||||||||||||
| 102 | $obj->{serialized} = { | ||||||||||||||||||||||||||||
| 103 | begin_string => $protocol->{begin_string}, | ||||||||||||||||||||||||||||
| 104 | 655 | message_type => $serialized_message_type, | |||||||||||||||||||||||||||
| 105 | }; | ||||||||||||||||||||||||||||
| 106 | $obj->{managed_composites} = { | ||||||||||||||||||||||||||||
| 107 | 655 | BodyLength => $protocol->field_by_name('BodyLength'), | |||||||||||||||||||||||||||
| 108 | CheckSum => $protocol->field_by_name('CheckSum'), | ||||||||||||||||||||||||||||
| 109 | }; | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 655 | return $obj; | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 18 | 1; | |||||||||||||||||||||||||||