Translator.pm

filter: Statementstmt 84.5% 82 / 97 Branchbran 68.1% 15 / 22 Conditioncond 100% 6 / 6 MC/DCmcdc 100% 4 / 4 Subroutinesub 88.8% 16 / 18 Podpod 100% 4 / 4 totaltotal 84.1% 127 / 151 CC 14 SCAR 12.0
CC
14
Cov
82%
__ANON__
7.0
append_input_buffer
6.0
BUILD
4.1
CRAP 3.3
« Translator/V1.pm ↑ Summary Deserializer/Numeric.pm »
1 package Hessian::Translator;
2  
3 ## no critic
4 45 our $VERSION = '1.06';
5 45 $VERSION = eval $VERSION;
6 ## use critic
7 #
8 45 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 45 ▶use Module::Load;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 45 ▶use YAML;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 45 ▶use List::MoreUtils qw/any/;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 45 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 #use Smart::Comments;
15  
16 45 ▶use Hessian::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 45 has 'is_big_endian' => ( is => 'rw', isa => 'Bool', default => 0 );
19 45 has 'original_position' => ( is => 'rw', isa => 'Int', default => 0 );
20 45 ▶has 'class_definitions' => ( is => 'rw', default => sub { [] } );
Subroutine __ANON__: called CC=1 SCAR=0.0
21 has 'type_list' => ( #{{{
22 is => 'rw',
23 isa => 'ArrayRef',
24 lazy => 1,
25 7 ▶ default => sub { [] }
Subroutine __ANON__: called CC=1 SCAR=0.0
26 45 );
27 45 ▶has 'reference_list' => ( is => 'rw', default => sub { [] } );
Subroutine __ANON__: called CC=1 SCAR=0.0
28 45 has 'input_string' => ( #{{{
29 is => 'rw',
30 isa => 'Str',
31 );
32 45 has 'version' => ( is => 'ro', isa => 'Int' );
33 45 has 'binary_mode' => ( is => 'ro', isa => 'Bool', default => 0 );
34 45 has 'chunked' => ( is => 'ro', isa => 'Bool', default => 0 );
35 45 has 'serializer' => (
36 is => 'rw',
37 isa => 'Bool',
38 );
39 45 has 'in_interior' => ( is => 'rw', isa => 'Bool', default => 0 );
40  
41 87 ▶before 'input_string' => sub { #{{{
Subroutine __ANON__: called CC=2 SCAR=6.9
42 87 my $self = shift;
43 87 ▶ if ( not $self->does('Hessian::Deserializer') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->does("Hessian::Deserializer")) 30 57 87
44 30 load 'Hessian::Deserializer';
45 30 Hessian::Deserializer->meta()->apply($self);
46 }
47 87 $self->version();
48 45 };
49  
50 0 ▶sub append_input_buffer { #{{{
Subroutine append_input_buffer: not called CC=2 SCAR=17.9
Pod documented
51 0 my ( $self, $hessian_string ) = @_;
52 0 ▶ if ( $self->{input_string} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'input_string'}) { } 0 0 0
53 0 my $fh_pos = tell $self->input_handle();
54 0 my $input_string = substr $self->{input_string}, $fh_pos;
55  
56 0 my $entire_string = $input_string . $hessian_string;
57 0 $self->input_string($entire_string);
58 }
59 else {
60 0 $self->input_string($hessian_string);
61 }
62 }
63  
64 10 ▶before 'serializer' => sub { #{{{
Subroutine __ANON__: called CC=2 SCAR=6.9
65 10 my $self = shift;
66 10 ▶ if ( !$self->does('Hessian::Serializer') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->does("Hessian::Serializer")) 2 8 10
67 2 load 'Hessian::Serializer';
68 2 Hessian::Serializer->meta()->apply($self);
69 }
70 10 $self->version();
71 45 };
72  
73 144 ▶after 'version' => sub { #{{{
Subroutine __ANON__: called CC=7 SCAR=19.5
74 144 my ($self) = @_;
75 144 my $version = $self->{version};
76 PROCESSVERSION: {
77 144 ▶ last PROCESSVERSION unless $version;
Branch: 1 branch
BranchTrueFalseTotal
unless $version 0 144 144
78 144 ▶ Parameter::X->throw( error => "Version should be either 1 or 2." )
Branch: 1 branch
BranchTrueFalseTotal
unless $version =~ /^(?:1|2)$/ 0 144 144
79 if $version !~ /^(?:1|2)$/;
80 last PROCESSVERSION
81 144 ▶ if $self->does('Hessian::Translator::V1')
Branch: 1 branch
BranchTrueFalseTotal
if $self->does("Hessian::Translator::V1") or $self->does("Hessian::Translator::V2") 97 47 144
Condition100%3/3
$self->does("Hessian::Translator::V1") or $self->does("Hessian::Translator::V2")
l!l&&r!l&&!r
336447
MC/DC100%2/2
$self->does("Hessian::Translator::V1") or $self->does("Hessian::Translator::V2")
$self->does("Hessian::Translator::V1") $self->does("Hessian::Translator::V2")
Truth table100%3/3
A or B
A= $self->does("Hessian::Translator::V1")B= $self->does("Hessian::Translator::V2")
ABresult
1X1
011
000
82 or $self->does('Hessian::Translator::V2');
83 last PROCESSVERSION
84 47 ▶ if not( $self->does('Hessian::Serializer')
Branch: 1 branch
BranchTrueFalseTotal
unless $self->does("Hessian::Serializer") or $self->does("Hessian::Deserializer") 43 4 47
Condition100%3/3
$self->does("Hessian::Serializer") or $self->does("Hessian::Deserializer")
l!l&&r!l&&!r
2243
MC/DC100%2/2
$self->does("Hessian::Serializer") or $self->does("Hessian::Deserializer")
$self->does("Hessian::Serializer") $self->does("Hessian::Deserializer")
Truth table100%3/3
A or B
A= $self->does("Hessian::Serializer")B= $self->does("Hessian::Deserializer")
ABresult
1X1
011
000
85 or $self->does('Hessian::Deserializer') );
86 4 my $version_role = 'Hessian::Translator::V' . $version;
87 4 load $version_role;
88 4 $version_role->meta()->apply($self);
89 } #PROCESSVERSION
90 45 };
91  
92 370 ▶sub read_from_inputhandle { #{{{
Subroutine read_from_inputhandle: called CC=2 SCAR=7.1
Pod documented
93 370 my ( $self, $read_length ) = @_;
94 ### Reading from input handle: $read_length;
95  
96 370 my $input_handle = $self->input_handle();
97 370 binmode( $input_handle, 'bytes' );
98 370 my $original_pos = $self->original_position();
99 370 my $current_position = ( tell $input_handle ) - 1;
100 370 my $sub_string = $self->{input_string};
101 my $remaining_string_buffer = substr $self->{input_string},
102 370 $current_position;
103  
104 370 my $remaining_length = length $remaining_string_buffer;
105 ### remaining: $remaining_length
106 370 my $result;
107 370 ▶ if ( $read_length > $remaining_length ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($read_length > $remaining_length) { } 0 370 370
108  
109 # Set filehandle back to the original position
110 my $message =
111 "Input buffer does not contain"
112 . " a complete message.\n$remaining_string_buffer\n"
113 . "Current position $current_position\n"
114 . "read length: $read_length\nremaining: $remaining_length\n"
115 . "string: "
116 0 . $self->{input_string} . ".\n";
117  
118 # print $message;
119  
120 # seek $input_handle, $original_pos, 0;
121 # Throw an exception that will be caught by the caller
122 0 MessageIncomplete::X->throw( error => $message );
123 }
124 else {
125 370 read $self->input_handle(), $result, $read_length;
126 }
127 370 return $result;
128  
129 }
130  
131 0 ▶sub set_current_position { #{{{
Subroutine set_current_position: not called CC=1 SCAR=6.9
Pod documented
132 0 my ( $self, $offset ) = @_;
133 0 my $input_handle = $self->input_handle();
134 0 my $current_position = ( tell $input_handle ) + $offset;
135 0 $self->original_position($current_position);
136 }
137  
138 45 ▶sub BUILD { #{{{
Subroutine BUILD: called CC=4 SCAR=14.2
Pod documented
139 45 my ( $self, $params ) = @_;
140 45 load 'Hessian::Translator::Composite';
141 45 Hessian::Translator::Composite->meta()->apply($self);
142 45 ▶ if ( any { defined $params->{$_} } qw/input_string input_handle/ ) {
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if (&any(sub { defined $params->{$_}; } , "input_string", "input_handle")) 2 43 45
143 2 load 'Hessian::Deserializer';
144 2 Hessian::Deserializer->meta()->apply($self);
145  
146 }
147  
148 45 ▶ if ( any { defined $params->{$_} } qw/service/ ) {
Subroutine __ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
BranchTrueFalseTotal
if (&any(sub { defined $params->{$_}; } , "service")) 0 45 45
149 0 load 'Hessian::Serializer';
150 0 Hessian::Serializer->meta()->apply($self);
151 }
152 45 $self->version();
153 45 my $byteorder = $Config{byteorder};
154 45 ▶ $self->is_big_endian(1) if $byteorder =~ /4321/;
Branch: 1 branch
BranchTrueFalseTotal
if $byteorder =~ /4321/ 0 45 45
155  
156 }
157  
158 45 "one, but we're not the same";
159  
160 __END__
« Translator/V1.pm ↑ Summary Deserializer/Numeric.pm »