Translator/Envelope.pm

filter: Statementstmt 33.0% 42 / 127 Branchbran 20.0% 2 / 10 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 58.8% 10 / 17 Podpod 100% 9 / 9 totaltotal 38.1% 64 / 168 CC 10 SCAR 24.4
CC
10
Cov
32%
read_envelope
42.0
write_hessian_packet
6.0
write_hessian_message
3.7
CRAP 11.4
« Serializer/Numeric.pm ↑ Summary Translator/Composite.pm »
1 package Hessian::Translator::Envelope;
2  
3 42 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 #
6 42 ▶use YAML;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 42 ▶use Contextual::Return;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 42 ▶use List::MoreUtils qw/any/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 42 ▶use feature "switch";
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 42 ▶use Hessian::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 12 ▶sub read_message_chunk { #{{{
Subroutine read_message_chunk: called CC=2 SCAR=7.0
Pod documented
14 12 my $self = shift;
15 12 my ($first_bit);
16 12 $first_bit = $self->read_from_inputhandle(1);
17 12 ▶ EndOfInput::X->throw( error => "Encountered end of datastructure." )
Branch: 1 branch
BranchTrueFalseTotal
if $first_bit eq $self->end_of_datastructure_symbol 0 12 12
18 if $first_bit eq $self->end_of_datastructure_symbol();
19 12 my $datastructure = $self->read_message_chunk_data($first_bit);
20 12 return $datastructure;
21 }
22  
23 1 ▶sub read_version { #{{{
Subroutine read_version: called CC=1 SCAR=0.0
Pod documented
24 1 my $self = shift;
25 1 my $version;
26 1 $version = $self->read_from_inputhandle(2);
27 1 my @values = unpack 'C*', $version;
28 1 my $hessian_version = join "." => @values;
29 1 return $hessian_version;
30  
31 }
32  
33 0 ▶sub read_envelope { #{{{
Subroutine read_envelope: not called CC=6 SCAR=37.4
Pod documented
34 0 my $self = shift;
35 0 my ( $first_bit, $packet_body, @chunks );
36 0 $first_bit = $self->read_from_inputhandle(1);
37 0 ▶ EndOfInput::X->throw( error => 'End of datastructure.' )
Branch: 1 branch
BranchTrueFalseTotal
if $first_bit =~ /z/i 0 0 0
38 if $first_bit =~ /z/i;
39  
40 # Just the word "Header" as far as I understand
41 0 my $header_string = $self->read_string_handle_chunk($first_bit);
42 ENVELOPECHUNKS: {
43 0 my ( $header_count, $footer_count, $packet_size );
44 0 my ( @headers, @footers, @packets );
45 0 $first_bit = $self->read_from_inputhandle(1);
46 0 ▶ last ENVELOPECHUNKS if $first_bit =~ /z/i;
Branch: 1 branch
BranchTrueFalseTotal
if $first_bit =~ /z/i 0 0 0
47 0 $header_count = $self->read_integer_handle_chunk( $first_bit, );
48 0 foreach ( 1 .. $header_count ) {
49 0 push @headers, $self->read_header_or_footer();
50 }
51  
52 PACKETCHUNKS: {
53  
54 0 $first_bit = $self->read_from_inputhandle(1);
55 0 ▶ if ( $first_bit =~ /[\x70-\x7f\x80-\x8f\x4f\x50]/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($first_bit =~ /[\x70-\x7f\x80-\x8f\x4f\x50]/) 0 0 0
56 0 my $packet_string = $self->read_packet_chunk($first_bit);
57 0 $packet_body .= $packet_string;
58
59 0 $first_bit = $self->read_from_inputhandle(1);
60 }
61 } # PACKETCHUNKS
62  
63 0 $footer_count = $self->read_integer_handle_chunk( $first_bit, );
64 0 foreach ( 1 .. $footer_count ) {
65 0 push @footers, $self->read_header_or_footer();
66 }
67 0 push @chunks,
68 {
69 headers => \@headers,
70 footers => \@footers
71 };
72 0 redo ENVELOPECHUNKS;
73 }
74 0 my $packet = $self->read_packet($packet_body);
75 0 return { envelope => { packet => $packet, meta => \@chunks } };
76 }
77  
78 0 ▶sub read_header_or_footer { #{{{
Subroutine read_header_or_footer: not called CC=1 SCAR=6.9
Pod documented
79 0 my $self = shift;
80  
81 0 my $first_bit;
82 0 $first_bit = $self->read_from_inputhandle(1);
83 0 my $header = $self->read_string_handle_chunk($first_bit);
84 0 return $header;
85 }
86  
87 0 ▶sub read_packet_chunk { #{{{
Subroutine read_packet_chunk: not called CC=1 SCAR=6.9
Pod documented
88 0 my ( $self, $first_bit ) = @_;
89  
90 0 my ($packet_string);
91 0 given ($first_bit) {
92 0 when (/[\x70-\x7f]/) {
93 0 my $length = unpack "C*", $first_bit;
94 0 my $packet_size = $length - 0x70;
95 0 $packet_string = $self->read_from_inputhandle($packet_size);
96  
97 }
98 0 when (/[\x80-\x8f]/) {
99 0 my $length = unpack "C*", $first_bit;
100 0 my $packet_size = $length - 0x80;
101 0 $packet_string = $self->read_from_inputhandle($packet_size);
102 }
103 0 when (/[\x4f\x50]/) {
104 0 print "Reading packet chunk\n";
105 0 $packet_string = $self->read_string_handle_chunk('S');
106  
107 }
108 0 return $packet_string;
109 }
110  
111 0 return $packet_string;
112 }
113  
114 0 ▶sub read_packet { #{{{
Subroutine read_packet: not called CC=1 SCAR=6.9
Pod documented
115 0 my ( $self, $packet_string ) = @_;
116 0 ▶ return FIXED NONVOID {
Subroutine __ANON__: not called CC=1 SCAR=6.9
117 0 $self->deserialize_message( { input_string => $packet_string } );
118 0 };
119 }
120  
121 0 ▶sub write_hessian_packet { #{{{
Subroutine write_hessian_packet: not called CC=2 SCAR=17.9
Pod documented
122 0 my ( $self, $packet ) = @_;
123 0 my $max_packet_size = 15; #$self->max_packet_size() - 4;
124 0 my $serialized_packet = $self->write_hessian_message($packet);
125 0 my @chunks =
126 $serialized_packet =~ /([\x00-\xff]{1,$max_packet_size})/g;
127 0 my @packets;
128 0 foreach my $chunk (@chunks) {
129 0 my $packaged_string = $self->write_hessian_string([ $chunk ]);
130 0 $packaged_string =~ s/S/P/;
131 0 push @packets, $packaged_string;
132 }
133 0 return \@packets;
134  
135
136 }
137  
138 3 ▶sub write_hessian_message { #{{{
Subroutine write_hessian_message: called CC=3 SCAR=13.2
Pod documented
139 3 my ( $self, $hessian_data ) = @_;
140  
141 3 my $hessian_message;
142 3 ▶ if ( ( ref $hessian_data ) eq 'HASH'
Branch: 1 branch
BranchTrueFalseTotal
if (ref $hessian_data eq 'HASH' and &any(sub { exists $hessian_data->{$_}; } , 'call', 'envelope', 'packet', 'data')) { } 3 0 3
Condition33%1/3
ref $hessian_data eq "HASH" and &any(sub { exists $hessian_data->{$_}; } , "call", "envelope", "packet", "data")
!ll&&!rl&&r
003
MC/DC0%0/2
ref $hessian_data eq "HASH" and &any(sub { exists $hessian_data->{$_}; } , "call", "envelope", "packet", "data")
ref $hessian_data eq "HASH" &any(sub { exists $hessian_data->{$_}; } , "call", "envelope", "packet", "data")
Truth table33%1/3
A and B
A= ref $hessian_data eq "HASH"B= &any(sub { exists $hessian_data->{$_}; } , "call", "envelope", "packet", "data")
ABresult
0X0
100
111
143 3 ▶ and any { exists $hessian_data->{$_} } qw/call envelope packet data/ )
Subroutine __ANON__: called CC=1 SCAR=0.0
144 {
145 3 my @keys = keys %{$hessian_data};
146 3 my $datastructure = $hessian_data->{ $keys[0] };
147 3 given ( $keys[0] ) {
148 3 when (/call/) {
149 3 $hessian_message = $self->write_hessian_call($datastructure);
150 }
151 0 when (/envelope/) {
152 0 $hessian_message =
153 $self->write_hessian_envelope($datastructure);
154 }
155 0 when (/packet/) {
156 0 $hessian_message = $self->write_hessian_packet($datastructure);
157 }
158 0 when (/data/) {
159 0 $hessian_message = $self->write_hessian_chunk($hessian_data);
160 }
161 }
162 }
163 else {
164 0 $hessian_message = $self->write_hessian_chunk($hessian_data);
165 }
166 3 return $hessian_message;
167 }
168  
169 0 ▶sub write_hessian_envelope { #{{{
Subroutine write_hessian_envelope: not called CC=1 SCAR=6.9
Pod documented
170 0 my ( $self, $envelope ) = @_;
171 0 my $meta = 'Header';
172 0 my $headers = delete $envelope->{headers};
173 0 my $footers = delete $envelope->{footers};
174 0 my $envelope_string = "E";
175  
176 0 my $envelope_meta = $self->write_hessian_string( [$meta] );
177 0 $envelope_string .= $envelope_meta;
178 0 my $header_count = $self->write_integer( scalar @{$headers} );
179 0 my $footer_count = $self->write_integer( scalar @{$footers} );
180  
181 0 my $serialized_message = $self->write_hessian_message($envelope);
182  
183 my @wrapped_body =
184 0 map { $header_count . $_ . $footer_count } @{$serialized_message};
185 0 $envelope_string .= join "" => @wrapped_body;
186 0 $envelope_string .= $self->end_of_datastructure_symbol();
187 0 return $envelope_string;
188  
189 }
190  
191 42 "one, but we're not the same";
192  
193 __END__
« Serializer/Numeric.pm ↑ Summary Translator/Composite.pm »