| 1 | package Hessian::Translator::Composite; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 42 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 42 | with 'Hessian::Translator::Envelope'; | |||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | # | ||||||||||||||||||||||||||||
| 8 | 42 | ▶ | use YAML; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 42 | ▶ | use Hessian::Exception; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 42 | ▶ | use Hessian::Simple; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 42 | ▶ | use Contextual::Return; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 42 | ▶ | use feature "switch"; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | #use Smart::Comments; | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 5 | ▶ | sub assemble_class { #{{{ | ||||||||||||||||||||||||||
|
Subroutine
assemble_class: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 16 | ### assemble_class | ||||||||||||||||||||||||||||
| 17 | 5 | my ( $self, $args ) = @_; | |||||||||||||||||||||||||||
| 18 | 5 | my ( $class_definition, $class_type ) = @{$args}{qw/class_def type/}; | |||||||||||||||||||||||||||
| 19 | 5 | ▶ | my $datastructure = pop @{ $self->reference_list() } || $args->{data}; | ||||||||||||||||||||||||||
|
Condition66%2/3
pop @{$self->reference_list;} || $args->{'data'}
MC/DC0%0/2
pop @{$self->reference_list;} || $args->{'data'}
pop @{$self->reference_list;}
$args->{'data'}
Truth table66%2/3
A || B
A= pop @{$self->reference_list;}B= $args->{'data'}
| |||||||||||||||||||||||||||||
| 20 | 5 | my $simple_obj = bless $datastructure, $class_type; | |||||||||||||||||||||||||||
| 21 | 5 | push @{ $self->reference_list() }, $simple_obj; | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | # $self->reference_list()->[-1] = $simple_obj; | ||||||||||||||||||||||||||||
| 24 | { | ||||||||||||||||||||||||||||
| 25 | ## no critic | ||||||||||||||||||||||||||||
| 26 | 42 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | 5 | push @{ $class_type . '::ISA' }, 'Hessian::Simple'; | |||||||||||||||||||||||||||
| 28 | ## use critic | ||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | 5 | foreach my $field ( @{ $class_definition->{fields} } ) { | |||||||||||||||||||||||||||
| 31 | 10 | $simple_obj->meta()->add_attribute( $field, is => 'rw' ); | |||||||||||||||||||||||||||
| 32 | 10 | my $value = $self->deserialize_data(); | |||||||||||||||||||||||||||
| 33 | 10 | $simple_obj->$field($value); | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | 5 | return $simple_obj; | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 9 | ▶ | sub read_typed_list_element { #{{{ | ||||||||||||||||||||||||||
|
Subroutine
read_typed_list_element: called CC=3 SCAR=14.5
Pod
documented
| |||||||||||||||||||||||||||||
| 40 | ### read_typed_list_element | ||||||||||||||||||||||||||||
| 41 | 9 | my ( $self, $type, $args ) = @_; | |||||||||||||||||||||||||||
| 42 | 9 | my ( $element, $first_bit ); | |||||||||||||||||||||||||||
| 43 | 9 | ▶ | if ( $args->{first_bit} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | 0 | $first_bit = $args->{first_bit}; | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | else { | ||||||||||||||||||||||||||||
| 47 | 9 | $first_bit = $self->read_from_inputhandle(1); | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | 9 | ▶ | EndOfInput::X->throw( error => 'Reached end of datastructure.' ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | if $first_bit eq $self->end_of_datastructure_symbol(); | ||||||||||||||||||||||||||||
| 51 | 7 | my $map_type = 'map'; | |||||||||||||||||||||||||||
| 52 | 7 | given ($type) { | |||||||||||||||||||||||||||
| 53 | 7 | when (/boolean/) { | |||||||||||||||||||||||||||
| 54 | 0 | $element = $self->read_boolean_handle_chunk($first_bit); | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | 7 | when (/int/) { | |||||||||||||||||||||||||||
| 57 | 7 | $element = $self->read_integer_handle_chunk($first_bit); | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | 0 | when (/long/) { | |||||||||||||||||||||||||||
| 60 | 0 | $element = $self->read_long_handle_chunk($first_bit); | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | 0 | when (/double/) { | |||||||||||||||||||||||||||
| 63 | 0 | $element = $self->read_double_handle_chunk($first_bit); | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | 0 | when (/date/) { | |||||||||||||||||||||||||||
| 66 | 0 | $element = $self->read_date_handle_chunk($first_bit); | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | 0 | when (/string/) { | |||||||||||||||||||||||||||
| 69 | 0 | $element = $self->read_string_handle_chunk($first_bit); | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | 0 | when (/binary/) { | |||||||||||||||||||||||||||
| 72 | 0 | $element = $self->read_binary_handle_chunk($first_bit); | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | 0 | when (/list/) { | |||||||||||||||||||||||||||
| 75 | 0 | $element = $self->read_composite_datastructure($first_bit); | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | 7 | return $element; | |||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 0 | ▶ | sub read_list_type { #{{{ | ||||||||||||||||||||||||||
|
Subroutine
read_list_type: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 82 | ### read_list_type | ||||||||||||||||||||||||||||
| 83 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 84 | 0 | my $type_length = $self->read_from_inputhandle(1); | |||||||||||||||||||||||||||
| 85 | 0 | my $type = $self->read_string_handle_chunk($type_length); | |||||||||||||||||||||||||||
| 86 | 0 | return $type; | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 8 | ▶ | sub store_fetch_type { #{{{ | ||||||||||||||||||||||||||
|
Subroutine
store_fetch_type: called CC=3 SCAR=12.6
Pod
documented
| |||||||||||||||||||||||||||||
| 90 | ### store_fetch_type | ||||||||||||||||||||||||||||
| 91 | 8 | my ( $self, $entity_type ) = @_; | |||||||||||||||||||||||||||
| 92 | 8 | my $type; | |||||||||||||||||||||||||||
| 93 | 8 | ▶ | if ( $entity_type =~ /^([^\x00-\x0f].*)/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | 8 | $type = $1; | |||||||||||||||||||||||||||
| 95 | 8 | push @{ $self->type_list() }, $type; | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | else { | ||||||||||||||||||||||||||||
| 98 | 0 | my $integer = unpack 'C*', $entity_type; | |||||||||||||||||||||||||||
| 99 | 0 | ▶ | $type = $self->type_list()->[$integer] if $integer; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | 8 | return $type; | |||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 5 | ▶ | sub store_class_definition { #{{{ | ||||||||||||||||||||||||||
|
Subroutine
store_class_definition: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 106 | ### store_class_definition | ||||||||||||||||||||||||||||
| 107 | 5 | my ( $self, $class_type ) = @_; | |||||||||||||||||||||||||||
| 108 | 5 | my $length = $self->read_from_inputhandle(1); | |||||||||||||||||||||||||||
| 109 | 5 | my $number_of_fields = $self->read_integer_handle_chunk($length); | |||||||||||||||||||||||||||
| 110 | 5 | my @field_list; | |||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 5 | foreach my $field_index ( 1 .. $number_of_fields ) { | |||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | # using the wrong function here, but who cares? | ||||||||||||||||||||||||||||
| 115 | 12 | my $field = $self->read_hessian_chunk(); | |||||||||||||||||||||||||||
| 116 | 12 | push @field_list, $field; | |||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 5 | my $class_definition = { type => $class_type, fields => \@field_list }; | |||||||||||||||||||||||||||
| 121 | 5 | push @{ $self->class_definitions() }, $class_definition; | |||||||||||||||||||||||||||
| 122 | 5 | return $class_definition; | |||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 196 | ▶ | sub read_hessian_chunk { #{{{ | ||||||||||||||||||||||||||
|
Subroutine
read_hessian_chunk: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 126 | ### read_hessian_chunk | ||||||||||||||||||||||||||||
| 127 | 196 | my ( $self, $args ) = @_; | |||||||||||||||||||||||||||
| 128 | 196 | my ( $first_bit, $element ); | |||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | # my $end_symbol = $self->end_of_datastructure_symbol(); | ||||||||||||||||||||||||||||
| 131 | 196 | ▶ | if ( 'HASH' eq ( ref $args ) and $args->{first_bit} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
"HASH" eq ref $args and $args->{"first_bit"}
MC/DC100%2/2
"HASH" eq ref $args and $args->{"first_bit"}
"HASH" eq ref $args
$args->{"first_bit"}
Truth table100%3/3
A and B
A= "HASH" eq ref $argsB= $args->{"first_bit"}
| |||||||||||||||||||||||||||||
| 132 | 26 | $first_bit = $args->{first_bit}; | |||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | else { | ||||||||||||||||||||||||||||
| 135 | 170 | $first_bit = $self->read_from_inputhandle(1); | |||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | 196 | ▶ | EndOfInput::X->throw( error => 'Reached end of datastructure.' ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 138 | if $first_bit eq $self->end_of_datastructure_symbol(); | ||||||||||||||||||||||||||||
| 139 | 178 | return $self->read_simple_datastructure($first_bit); | |||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | 2 | ▶ | sub fetch_class_for_data { #{{{ | ||||||||||||||||||||||||||
|
Subroutine
fetch_class_for_data: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 143 | ### fetch_class_for_data | ||||||||||||||||||||||||||||
| 144 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 145 | 2 | my $length = $self->read_from_inputhandle(1); | |||||||||||||||||||||||||||
| 146 | 2 | my $class_definition_number = $self->read_integer_handle_chunk($length); | |||||||||||||||||||||||||||
| 147 | 2 | return $self->instantiate_class($class_definition_number); | |||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | 4 | ▶ | sub instantiate_class { #{{{ | ||||||||||||||||||||||||||
|
Subroutine
instantiate_class: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 152 | ### instantiate_class | ||||||||||||||||||||||||||||
| 153 | 4 | my ( $self, $index ) = @_; | |||||||||||||||||||||||||||
| 154 | 4 | my $class_definitions = $self->class_definitions; | |||||||||||||||||||||||||||
| 155 | 4 | my $class_definition = $self->class_definitions()->[$index]; | |||||||||||||||||||||||||||
| 156 | 4 | my $class_type = $class_definition->{type}; | |||||||||||||||||||||||||||
| 157 | 4 | ▶ | return unless $class_type; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 158 | 4 | return $self->assemble_class( | |||||||||||||||||||||||||||
| 159 | { | ||||||||||||||||||||||||||||
| 160 | class_def => $class_definition, | ||||||||||||||||||||||||||||
| 161 | type => $class_type | ||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||
| 163 | ); | ||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | 9 | ▶ | sub read_list_length { #{{{ | ||||||||||||||||||||||||||
|
Subroutine
read_list_length: called CC=5 SCAR=17.6
Pod
documented
| |||||||||||||||||||||||||||||
| 167 | ### read_list_length | ||||||||||||||||||||||||||||
| 168 | 9 | my ( $self, $first_bit ) = @_; | |||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | 9 | my $array_length; | |||||||||||||||||||||||||||
| 171 | 9 | ▶ | if ( $first_bit =~ /[\x56\x58]/ ) { # read array length | ||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||
| 172 | 2 | my $length = $self->read_from_inputhandle(1); | |||||||||||||||||||||||||||
| 173 | 2 | $array_length = $self->read_integer_handle_chunk($length); | |||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||
| 175 | elsif ( $first_bit =~ /[\x70-\x77]/ ) { | ||||||||||||||||||||||||||||
| 176 | 0 | my $hex_bit = unpack 'C*', $first_bit; | |||||||||||||||||||||||||||
| 177 | 0 | $array_length = $hex_bit - 0x70; | |||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||
| 179 | elsif ( $first_bit =~ /[\x78-\x7f]/ ) { | ||||||||||||||||||||||||||||
| 180 | 0 | my $hex_bit = unpack 'C*', $first_bit; | |||||||||||||||||||||||||||
| 181 | 0 | $array_length = $hex_bit - 0x78; | |||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||
| 183 | elsif ( $first_bit =~ /\x6c/ ) { | ||||||||||||||||||||||||||||
| 184 | 2 | $array_length = $self->read_integer_handle_chunk('I'); | |||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||
| 186 | ### found array length: $array_length | ||||||||||||||||||||||||||||
| 187 | 9 | return $array_length; | |||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | 49 | ▶ | sub write_hessian_chunk { #{{{ | ||||||||||||||||||||||||||
|
Subroutine
write_hessian_chunk: called CC=5 SCAR=16.4
Pod
documented
| |||||||||||||||||||||||||||||
| 191 | ### write_hessian_chunk | ||||||||||||||||||||||||||||
| 192 | 49 | my ( $self, $element ) = @_; | |||||||||||||||||||||||||||
| 193 | 49 | my $hessian_element; | |||||||||||||||||||||||||||
| 194 | 49 | ▶ | my $element_type = ref $element ? ref $element : \$element; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 195 | 49 | given ("$element_type") { | |||||||||||||||||||||||||||
| 196 | 49 | when (/SCALAR/) { | |||||||||||||||||||||||||||
| 197 | 37 | $hessian_element = $self->write_scalar_element($element); | |||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||
| 199 | 12 | when (/DateTime/) { | |||||||||||||||||||||||||||
| 200 | 2 | $hessian_element = $self->write_date($element); | |||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||
| 202 | 10 | default { | |||||||||||||||||||||||||||
| 203 | 10 | my $reference_list = $self->reference_list(); | |||||||||||||||||||||||||||
| 204 | 10 | my @list = @{$reference_list}; | |||||||||||||||||||||||||||
| 205 | 10 | my ( $referenced_index, $found_reference ); | |||||||||||||||||||||||||||
| 206 | 10 | foreach my $index ( 0 .. $#{$reference_list} ) { | |||||||||||||||||||||||||||
| 207 | 2 | my $referenced_element = $reference_list->[$index]; | |||||||||||||||||||||||||||
| 208 | 2 | ▶ | if ( $element == $referenced_element ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 209 | 0 | $found_reference = 1; | |||||||||||||||||||||||||||
| 210 | 0 | $referenced_index = $index; | |||||||||||||||||||||||||||
| 211 | 0 | last; | |||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||
| 214 | 10 | ▶ | if ($found_reference) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 215 | 0 | $hessian_element = | |||||||||||||||||||||||||||
| 216 | $self->write_referenced_data($referenced_index); | ||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||
| 218 | else { | ||||||||||||||||||||||||||||
| 219 | 10 | push @{ $self->reference_list() }, $element; | |||||||||||||||||||||||||||
| 220 | 10 | $hessian_element = $self->write_composite_element($element); | |||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||
| 224 | 49 | return $hessian_element; | |||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | 10 | ▶ | sub write_composite_element { #{{{ | ||||||||||||||||||||||||||
|
Subroutine
write_composite_element: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 228 | ### write_composite_element | ||||||||||||||||||||||||||||
| 229 | 10 | my ( $self, $datastructure ) = @_; | |||||||||||||||||||||||||||
| 230 | 10 | ▶ | my $element_type = | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 231 | ref $datastructure ? ref $datastructure : \$datastructure; | ||||||||||||||||||||||||||||
| 232 | ### element type: $element_type | ||||||||||||||||||||||||||||
| 233 | 10 | my $hessian_string; | |||||||||||||||||||||||||||
| 234 | 10 | given ($element_type) { | |||||||||||||||||||||||||||
| 235 | 10 | when (/HASH/) { | |||||||||||||||||||||||||||
| 236 | 4 | $hessian_string = $self->write_hessian_hash($datastructure); | |||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||
| 238 | 6 | when (/ARRAY/) { | |||||||||||||||||||||||||||
| 239 | 4 | $hessian_string = $self->write_hessian_array($datastructure); | |||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||
| 241 | 2 | default { | |||||||||||||||||||||||||||
| 242 | 2 | $hessian_string = $self->write_object($datastructure); | |||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||
| 245 | 10 | return $hessian_string; | |||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||
| 248 | 60 | ▶ | sub write_scalar_element { #{{{ | ||||||||||||||||||||||||||
|
Subroutine
write_scalar_element: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 249 | 60 | my ( $self, $element ) = @_; | |||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||
| 251 | 60 | my $hessian_element; | |||||||||||||||||||||||||||
| 252 | 60 | given ($element) { # Integer or String | |||||||||||||||||||||||||||
| 253 | 60 | when (/^-?[0-9]+$/) { | |||||||||||||||||||||||||||
| 254 | 23 | $hessian_element = $self->write_integer($element); | |||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||
| 256 | 37 | when (/^-?[0-9]*\.[0-9]+/) { | |||||||||||||||||||||||||||
| 257 | 2 | $hessian_element = $self->write_double($element); | |||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||
| 259 | 35 | when (/^[\x20-\x7e\xa1-\xff]+$/) { # a string | |||||||||||||||||||||||||||
| 260 | 35 | my @chunks = $element =~ /(.{1,66})/g; | |||||||||||||||||||||||||||
| 261 | 35 | $hessian_element = $self->write_hessian_string( \@chunks ); | |||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||
| 264 | 60 | return $hessian_element; | |||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||
| 267 | 0 | ▶ | sub write_hessian_array { #{{{ | ||||||||||||||||||||||||||
|
Subroutine
write_hessian_array: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 268 | 0 | my ( $self, $datastructure ) = @_; | |||||||||||||||||||||||||||
| 269 | 0 | my $anonymous_array_string = "V"; | |||||||||||||||||||||||||||
| 270 | 0 | foreach my $element ( @{$datastructure} ) { | |||||||||||||||||||||||||||
| 271 | 0 | my $hessian_element = $self->write_hessian_chunk($element); | |||||||||||||||||||||||||||
| 272 | 0 | $anonymous_array_string .= $hessian_element; | |||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||
| 274 | 0 | $anonymous_array_string .= "z"; | |||||||||||||||||||||||||||
| 275 | 0 | return $anonymous_array_string; | |||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||
| 278 | 32 | ▶ | sub read_composite_datastructure { #{{{ | ||||||||||||||||||||||||||
|
Subroutine
read_composite_datastructure: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 279 | 32 | my ( $self, $first_bit ) = @_; | |||||||||||||||||||||||||||
| 280 | 32 | return $self->read_composite_data($first_bit); | |||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||
| 283 | #sub read_map_handle { #{{{ | ||||||||||||||||||||||||||||
| 284 | # my $self = shift; | ||||||||||||||||||||||||||||
| 285 | # my $v1_type = $self->read_v1_type(); | ||||||||||||||||||||||||||||
| 286 | # my ( $entity_type, $next_bit ) = @{$v1_type}{qw/type next_bit/}; | ||||||||||||||||||||||||||||
| 287 | # my $type; | ||||||||||||||||||||||||||||
| 288 | # $type = $self->store_fetch_type($entity_type) if $entity_type; | ||||||||||||||||||||||||||||
| 289 | # my $key; | ||||||||||||||||||||||||||||
| 290 | # if ($next_bit) { | ||||||||||||||||||||||||||||
| 291 | # $key = $self->read_hessian_chunk( { first_bit => $next_bit } ); | ||||||||||||||||||||||||||||
| 292 | # } | ||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||
| 294 | # # For now only accept integers or strings as keys | ||||||||||||||||||||||||||||
| 295 | # my @key_value_pairs; | ||||||||||||||||||||||||||||
| 296 | # MAPLOOP: | ||||||||||||||||||||||||||||
| 297 | # { | ||||||||||||||||||||||||||||
| 298 | # eval { $key = $self->read_hessian_chunk(); } unless $key; | ||||||||||||||||||||||||||||
| 299 | # last MAPLOOP | ||||||||||||||||||||||||||||
| 300 | # if Exception::Class->caught('EndOfInput::X') | ||||||||||||||||||||||||||||
| 301 | # or Exception::Class->caught('MessageIncomplete::X'); | ||||||||||||||||||||||||||||
| 302 | # my $value = $self->read_hessian_chunk(); | ||||||||||||||||||||||||||||
| 303 | # push @key_value_pairs, $key => $value; | ||||||||||||||||||||||||||||
| 304 | # undef $key; | ||||||||||||||||||||||||||||
| 305 | # redo MAPLOOP; | ||||||||||||||||||||||||||||
| 306 | # } | ||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||
| 308 | # # should throw an exception if @key_value_pairs has an odd number of | ||||||||||||||||||||||||||||
| 309 | # # elements | ||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||
| 311 | # my $datastructure = $self->reference_list()->[-1]; | ||||||||||||||||||||||||||||
| 312 | # my $hash = {@key_value_pairs}; | ||||||||||||||||||||||||||||
| 313 | # foreach my $key ( keys %{$hash} ) { | ||||||||||||||||||||||||||||
| 314 | # $datastructure->{$key} = $hash->{$key}; | ||||||||||||||||||||||||||||
| 315 | # } | ||||||||||||||||||||||||||||
| 316 | # my $map = defined $type ? bless $datastructure => $type : $datastructure; | ||||||||||||||||||||||||||||
| 317 | # return $map; | ||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||
| 319 | #} | ||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||
| 321 | 0 | ▶ | sub read_v1_type { #{{{ | ||||||||||||||||||||||||||
|
Subroutine
read_v1_type: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 322 | 0 | my ( $self, $list_bit ) = @_; | |||||||||||||||||||||||||||
| 323 | 0 | my ( $type, $first_bit, $array_length ); | |||||||||||||||||||||||||||
| 324 | 0 | ▶ | if ( $list_bit and $list_bit =~ /\x76/ ) { # v | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$list_bit and $list_bit =~ /\x76/
MC/DC0%0/2
$list_bit and $list_bit =~ /\x76/
$list_bit
$list_bit =~ /\x76/
Truth table0%0/3
A and B
A= $list_bitB= $list_bit =~ /\x76/
| |||||||||||||||||||||||||||||
| 325 | 0 | $type = $self->read_from_inputhandle(1); | |||||||||||||||||||||||||||
| 326 | 0 | $array_length = $self->read_from_inputhandle(1); | |||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||
| 328 | else { | ||||||||||||||||||||||||||||
| 329 | 0 | $first_bit = $self->read_from_inputhandle(1); | |||||||||||||||||||||||||||
| 330 | 0 | ▶ | if ( $first_bit =~ /t/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 331 | 0 | $type = $self->read_hessian_chunk( { first_bit => 'S' } ); | |||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||
| 335 | 0 | ▶ | return { type => $type, next_bit => $array_length } if $type; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 336 | 0 | return { next_bit => $first_bit }; | |||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||
| 339 | #sub read_remote_object { #{{{ | ||||||||||||||||||||||||||||
| 340 | # my $self = shift; | ||||||||||||||||||||||||||||
| 341 | # ### read_remote_object | ||||||||||||||||||||||||||||
| 342 | # my $remote_type = $self->read_v1_type()->{type}; | ||||||||||||||||||||||||||||
| 343 | # $remote_type =~ s/\./::/g; | ||||||||||||||||||||||||||||
| 344 | # my $class_definition = { | ||||||||||||||||||||||||||||
| 345 | # type => $remote_type, | ||||||||||||||||||||||||||||
| 346 | # fields => ['remote_url'] | ||||||||||||||||||||||||||||
| 347 | # }; | ||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||
| 349 | # ### class definition: Dump($class_definition) | ||||||||||||||||||||||||||||
| 350 | # return $self->assemble_class( | ||||||||||||||||||||||||||||
| 351 | # { | ||||||||||||||||||||||||||||
| 352 | # type => $remote_type, | ||||||||||||||||||||||||||||
| 353 | # data => {}, | ||||||||||||||||||||||||||||
| 354 | # class_def => $class_definition | ||||||||||||||||||||||||||||
| 355 | # } | ||||||||||||||||||||||||||||
| 356 | # ); | ||||||||||||||||||||||||||||
| 357 | #} | ||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||
| 359 | 42 | "one, but we're not the same"; | |||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||
| 361 | __END__ | ||||||||||||||||||||||||||||