Serialized.pm

filter: Statementstmt 96.0% 73 / 76 Branchbran 74.0% 37 / 50 Conditioncond 40.4% 17 / 42 MC/DCmcdc 12.5% 3 / 24 Subroutinesub 100% 14 / 14 Podpod 66.6% 2 / 3 totaltotal 69.8% 146 / 209 CC 40 SCAR 22.4
CC
40
Cov
76%
recv
16.2
_is_valid_output_handle
9.7
send
9.6
CRAP 9.4
↑ Summary Serialized/Server.pm »
1 package RPC::Serialized;
2 {
3 26 $RPC::Serialized::VERSION = '1.123630';
4 }
5  
6 26 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 26 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 26 ▶use base 'Class::Accessor::Fast::Contained';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 26 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 26 ▶use Data::Serializer;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 26 ▶use RPC::Serialized::Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 26 ▶use RPC::Serialized::Exceptions;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 26 __PACKAGE__->mk_ro_accessors(qw/
17 debug
18 /);
19 26 __PACKAGE__->mk_accessors(qw/
20 ds
21 ifh ofh
22 /);
23  
24 # this is the record separator in our data stream,
25 # used if debug is enabled
26 26 Readonly my $TERMINATOR => '...';
27  
28 17 ▶sub new {
Subroutine new: called CC=6 SCAR=20.5
Pod documented
29 17 my $class = shift;
30 17 my $params = RPC::Serialized::Config->parse(@_);
31  
32 throw_app 'Missing or invalid input handle'
33 if exists $params->me->{ifh}
34 17 ▶ and ! _is_valid_input_handle( $params->me->{ifh} );
Branch: 1 branch
BranchTrueFalseTotal
if exists $params->me->{"ifh"} and not _is_valid_input_handle($params->me->{"ifh"}) 0 17 17
Condition33%1/3
exists $params->me->{"ifh"} and not _is_valid_input_handle($params->me->{"ifh"})
!ll&&!rl&&r
0170
MC/DC0%0/2
exists $params->me->{"ifh"} and not _is_valid_input_handle($params->me->{"ifh"})
exists $params->me->{"ifh"} not _is_valid_input_handle($params->me->{"ifh"})
Truth table33%1/3
A and not(B)
A= exists $params->me->{"ifh"}B= not _is_valid_input_handle($params->me->{"ifh"})
ABresult
0X0
100
111
35  
36 throw_app 'Missing or invalid output handle'
37 if exists $params->me->{ofh}
38 17 ▶ and ! _is_valid_output_handle( $params->me->{ofh} );
Branch: 1 branch
BranchTrueFalseTotal
if exists $params->me->{"ofh"} and not _is_valid_output_handle($params->me->{"ofh"}) 0 17 17
Condition33%1/3
exists $params->me->{"ofh"} and not _is_valid_output_handle($params->me->{"ofh"})
!ll&&!rl&&r
0170
MC/DC0%0/2
exists $params->me->{"ofh"} and not _is_valid_output_handle($params->me->{"ofh"})
exists $params->me->{"ofh"} not _is_valid_output_handle($params->me->{"ofh"})
Truth table33%1/3
A and not(B)
A= exists $params->me->{"ofh"}B= not _is_valid_output_handle($params->me->{"ofh"})
ABresult
0X0
100
111
39  
40 17 ▶ $params->me->{ofh}->autoflush(1) if exists $params->me->{ofh};
Branch: 1 branch
BranchTrueFalseTotal
if exists $params->me->{"ofh"} 17 0 17
41 17 $params->me->{ds} = Data::Serializer->new($params->data_serializer);
42  
43 17 return $class->SUPER::new({ $params->me });
44 }
45  
46 34 ▶sub _is_valid_handle {
Subroutine _is_valid_handle: called CC=4 SCAR=18.9
47 34 my $h = shift;
48 34 ▶ return 1
Branch: 1 branch
BranchTrueFalseTotal
if defined $h and ref $h and $h->can("error") 34 0 34
Condition33%2/6
defined $h and ref $h and $h->can("error")
!ll&&!rl&&r
0034
defined $h and ref $h
!ll&&!rl&&r
0034
MC/DC0%0/3
defined $h and ref $h and $h->can("error")
defined $h ref $h $h->can("error")
Truth table25%1/4
A and B and C
A= defined $hB= ref $hC= $h->can("error")
ABCresult
0XX0
10X0
1100
1111
49 if defined $h
50 and ref $h
51 and $h->can('error');
52 0 return 0;
53 }
54  
55 17 ▶sub _is_valid_input_handle {
Subroutine _is_valid_input_handle: called CC=4 SCAR=18.9
56 17 my $h = shift;
57 17 ▶ return 1
Branch: 1 branch
BranchTrueFalseTotal
if _is_valid_handle($h) and $h->can("getline") and $h->can("eof") 17 0 17
Condition33%2/6
_is_valid_handle($h) and $h->can("getline") and $h->can("eof")
!ll&&!rl&&r
0017
_is_valid_handle($h) and $h->can("getline")
!ll&&!rl&&r
0017
MC/DC0%0/3
_is_valid_handle($h) and $h->can("getline") and $h->can("eof")
_is_valid_handle($h) $h->can("getline") $h->can("eof")
Truth table25%1/4
A and B and C
A= _is_valid_handle($h)B= $h->can("getline")C= $h->can("eof")
ABCresult
0XX0
10X0
1100
1111
58 if _is_valid_handle($h)
59 and $h->can('getline')
60 and $h->can('eof');
61 0 return 0;
62 }
63  
64 17 ▶sub _is_valid_output_handle {
Subroutine _is_valid_output_handle: called CC=5 SCAR=22.7
65 17 my $h = shift;
66 17 ▶ return 1
Branch: 1 branch
BranchTrueFalseTotal
if _is_valid_handle($h) and $h->can("print") and $h->can("autoflush") and $h->can("error") 17 0 17
Condition33%3/9
_is_valid_handle($h) and $h->can("print") and $h->can("autoflush") and $h->can("error")
!ll&&!rl&&r
0017
_is_valid_handle($h) and $h->can("print") and $h->can("autoflush")
!ll&&!rl&&r
0017
_is_valid_handle($h) and $h->can("print")
!ll&&!rl&&r
0017
MC/DC0%0/4
_is_valid_handle($h) and $h->can("print") and $h->can("autoflush") and $h->can("error")
_is_valid_handle($h) $h->can("print") $h->can("autoflush") $h->can("error")
Truth table20%1/5
A and B and C and D
A= _is_valid_handle($h)B= $h->can("print")C= $h->can("autoflush")D= $h->can("error")
ABCDresult
0XXX0
10XX0
110X0
11100
11111
67 if _is_valid_handle($h)
68 and $h->can('print')
69 and $h->can('autoflush')
70 and $h->can('error');
71 0 return 0;
72 }
73  
74 46 ▶sub send {
Subroutine send: called CC=8 SCAR=22.6
Pod documented
75 46 my $self = shift;
76 46 my $data = shift;
77  
78 46 ▶ throw_proto 'Data not a hash reference'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $data eq "HASH" 4 42 46
79 unless ref($data) eq 'HASH';
80  
81 42 my $io = $self->ofh;
82  
83 42 ▶ if ($self->debug) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->debug) { } 2 40 42
84 2 my $send_data = $self->ds->raw_serialize($data);
85 2 ▶ $io->print( $send_data .
Branch: 2 branches
BranchTrueFalseTotal
$io->print($send_data . ($send_data =~ /\n$/ ? "" : "\n") . "$TERMINATOR\n") and not $io->error or throw_system("Failed to send data: $!") 2 0 2
$send_data =~ /\n$/ ? : 0 2 2
Condition33%1/3
$io->print($send_data . ($send_data =~ /\n$/ ? "" : "\n") . "$TERMINATOR\n") and not $io->error
!ll&&!rl&&r
002
MC/DC0%0/2
$io->print($send_data . ($send_data =~ /\n$/ ? "" : "\n") . "$TERMINATOR\n") and not $io->error
$io->print($send_data . ($send_data =~ /\n$/ ? "" : "\n") . "$TERMINATOR\n") not $io->error
Truth table33%1/3
A and not(B)
A= $io->print($send_data . ($send_data =~ /\n$/ ? "" : "\n") . "$TERMINATOR\n")B= not $io->error
ABresult
0X0
100
111
86 ($send_data =~ m/\n$/ ? '' : "\n") . "$TERMINATOR\n" )
87 and not $io->error
88 or throw_system "Failed to send data: $!";
89 }
90 else {
91 40 ▶ $io->print( $self->ds->serialize($data) . "\n" )
Branch: 1 branch
BranchTrueFalseTotal
$io->print($self->ds->serialize($data) . "\n") and not $io->error or throw_system("Failed to send data: $!") 40 0 40
Condition33%1/3
$io->print($self->ds->serialize($data) . "\n") and not $io->error
!ll&&!rl&&r
0040
MC/DC0%0/2
$io->print($self->ds->serialize($data) . "\n") and not $io->error
$io->print($self->ds->serialize($data) . "\n") not $io->error
Truth table33%1/3
A and not(B)
A= $io->print($self->ds->serialize($data) . "\n")B= not $io->error
ABresult
0X0
100
111
92 and not $io->error
93 or throw_system "Failed to send data: $!";
94 }
95 }
96  
97 51 ▶sub recv {
Subroutine recv: called CC=16 SCAR=27.8
Pod undocumented
98 51 my $self = shift;
99 51 my $data = '';
100 51 my $io = $self->ifh;
101  
102 51 ▶ if ($self->debug) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->debug) { } 4 47 51
103 4 ▶ while ( $_ = $io->getline and not $io->error ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ = $io->getline and not $io->error) 10 2 12
Condition66%2/3
$_ = $io->getline and not $io->error
!ll&&!rl&&r
2010
MC/DC50%1/2
$_ = $io->getline and not $io->error
$_ = $io->getline not $io->error
Truth table66%2/3
A and not(B)
A= $_ = $io->getlineB= not $io->error
ABresult
0X0
100
111
104 10 ▶ last if /^\Q$TERMINATOR\E$/o;
Branch: 1 branch
BranchTrueFalseTotal
if /^\Q$TERMINATOR\E$/o 2 8 10
105 8 $data .= $_;
106 }
107 }
108 else {
109 47 $data = $io->getline;
110 }
111  
112 51 ▶ throw_system "Failed to read data: $!"
Branch: 1 branch
BranchTrueFalseTotal
if $io->error 0 51 51
113 if $io->error;
114  
115 51 ▶ chomp $data if defined $data;
Branch: 1 branch
BranchTrueFalseTotal
if defined $data 46 5 51
116 51 ▶ return unless defined($data) && length($data);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data and length $data 5 46 51
Condition66%2/3
defined $data and length $data
!ll&&!rl&&r
5046
MC/DC50%1/2
defined $data and length $data
defined $data length $data
Truth table66%2/3
A and B
A= defined $dataB= length $data
ABresult
0X0
100
111
117  
118 46 my @token = ();
119 46 eval {
120 46 ▶ if ($self->debug) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->debug) { } 4 42 46
121 4 $data = $self->ds->raw_deserialize($data);
122 }
123 else {
124 42 my $token = $self->ds->_get_token($data);
125 42 ▶ @token = $self->ds->_extract_token($token) if defined $token;
Branch: 1 branch
BranchTrueFalseTotal
if defined $token 40 2 42
126  
127 42 $data = $self->ds->deserialize($data);
128 }
129 };
130 46 ▶ throw_proto "Data::Serializer error: $@"
Branch: 1 branch
BranchTrueFalseTotal
if $@ 3 43 46
131 if $@;
132  
133 43 ▶ throw_proto 'Serializer parse error'
Branch: 1 branch
BranchTrueFalseTotal
if not defined $data or $data == 1 1 42 43
Condition66%2/3
not defined $data or $data == 1
l!l&&r!l&&!r
1042
MC/DC50%1/2
not defined $data or $data == 1
not defined $data $data == 1
Truth table66%2/3
not(A) or B
A= not defined $dataB= $data == 1
ABresult
1X1
011
000
134 if !defined $data or $data == 1;
135  
136 42 ▶ throw_proto 'Data not a hash reference'
Branch: 1 branch
BranchTrueFalseTotal
if ref $data ne "HASH" 0 42 42
137 if ref($data) ne 'HASH';
138  
139 return (wantarray
140 42 ▶ ? ($data, @token)
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 19 23 42
141 : $data);
142 }
143  
144 17 ▶sub DESTROY {
Subroutine DESTROY: called CC=3 SCAR=11.7
145 17 my $self = shift;
146 17 ▶ $self->ifh->close if $self->ifh;
Branch: 1 branch
BranchTrueFalseTotal
if $self->ifh 17 0 17
147 17 ▶ $self->ofh->close if $self->ofh;
Branch: 1 branch
BranchTrueFalseTotal
if $self->ofh 17 0 17
148 }
149  
150 26 1;
151  
152 # ABSTRACT: Subroutine calls over the network using common serialization
153  
154  
155 # Here are some of the less common error messages. When more time is available
156 # these will be futher documented:
157 #
158 # =over 4
159 #
160 # =item C<Permission denied> in an C<X::Authorization>
161 #
162 # The authorization scheme loaded has refused to permit the current subject to
163 # make the current call.
164 #
165 # =item C<TCPREMOTEINFO not set> in an C<X::Authorization>
166 #
167 # The C<UCSPI/TCP> server will look for the C<TCPREMOTEINFO> environment
168 # variable, if authorization is enabled. See the C<ucspi-tcp> documentation for
169 # details if you don't know how to enable this.
170 #
171 # =item C<IPCREMOTEEUID not set> in an C<X::Authorization>
172 #
173 # The C<UCSPI/IPC> server will look for the C<IPCREMOTEINFO> environment
174 # variable, if authorization is enabled. See the <ucspi-ipc> documentation for
175 # details if you don't know how to enable this.
176 #
177 # =item C<getpwuid $uid failed> in an C<X::Authorization>
178 #
179 # The C<UCSPI/IPC> server failed to get the username for the calling user. Only
180 # happens if authorization has been enabled.
181 #
182 # =item C<Not a RPC::Serialized::AuthzHandler> in an C<X::Application>
183 #
184 # Server authorization is enabled but the specified handler does not inherit
185 # from L<RPC::Serialized::AuthzHandler>.
186 #
187 # =item C<Failed to open GDBM file...> in an C<X::System>
188 #
189 # =item C<Missing or invalid URI> in an C<X::Application>
190 #
191 # =item C<Can't determine path from URI ...> in an C<X::Application>
192 #
193 # =item C<Failed to open ...> in an C<X::System>
194 #
195 # =item C<Target name not specified> in an C<X::Application>
196 #
197 # =item C<Failed to parse scheme from URI ...> in an C<X::Application>
198 #
199 # =item C<Unsupported URI scheme ...> in an C<X::Application>
200 #
201 # =item C<Failed to load ...> in an C<X::System>
202 #
203 # =item C<Subject name not specified> in an C<X::Application>
204 #
205 # =item C<Operation name not specified> in an C<X::Application>
206 #
207 # =item C<Open $acl_path failed: ...> in an C<X::System>
208 #
209 # =item C<Failed to parse ACLs at ...> in an C<X::Application>
210 #
211 # =item C<ACL path not specified> in an C<X::Application>
212 #
213 # =back
214  
215  
216 __END__
↑ Summary Serialized/Server.pm »