RRP/Protocol.pm

filter: Statementstmt 33.3% 20 / 60 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 14 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 40.0% 6 / 15 Podpod 100% 7 / 7 totaltotal 27.7% 33 / 119 CC 13 SCAR 26.3
CC
13
Cov
23%
_getLinesFromSocket
30.0
sendHello
30.0
new
12.0
CRAP 13.9
« RRP/Codec.pm ↑ Summary RRP/Request/Add.pm »
1 package Net::RRP::Protocol;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 $Net::RRP::Protocol::VERSION = (split " ", '# $Id: Protocol.pm,v 1.9 2000/10/12 12:06:50 mkul Exp $ ')[3];
5  
6 =head1 NAME
7  
8 Net::RRP::Protocol - rrp protocol
9  
10 =head1 SYNOPSIS
11  
12 use Net::RRP::Protocol;
13 my $protocol = new Net::RRP::Protocol ( %parameters_for_IO_Socket_SSL_new );
14 my $protocol1 = new Net::RRP::Protocol ( socket => $io_socket_ssl_object );
15  
16 =head1 DESCRIPTION
17  
18 This class implements rrp command ( request/response ) communications over
19 socket ( IO::Socket::SSL )
20  
21 =cut
22  
23 #use IO::Socket::SSL;
24 1 ▶use IO::Socket::INET;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 1 ▶use Net::RRP::Codec;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 1 ▶use Net::RRP::Toolkit;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 1 ▶use Net::RRP::Exception::ServerError;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 1 ▶use Net::RRP::Exception::IOError;
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 =head2 new
31  
32 This is a comstructor. You must setup complete paraters for initiliaze of IO::Socket::SSL
33 instance or pass already initilized socket at 'socket' key.
34  
35 use Net::RRP::Protocol;
36 my $protocol = new Net::RRP::Protocol ( %parameters_for_IO_Socket_SSL_new );
37 my $protocol1 = new Net::RRP::Protocol ( socket => $io_socket_ssl_object );
38  
39 See L<IO::Socket::SSL(3)> for more details about IO::Socket::SSL parameters.
40  
41 =cut
42  
43 sub new
44 0 ▶{
Subroutine new: not called CC=3 SCAR=24.8
Pod documented
45 0 my ( $class, %options ) = @_;
46 0 my $this = bless{}, $class;
47 0 ▶ $this->{socket} = $options{socket} || new IO::Socket::INET ( %options );
Condition0%0/3
$options{'socket'} || 'IO::Socket::INET'->new(%options)
l!l&&r!l&&!r
000
MC/DC0%0/2
$options{'socket'} || 'IO::Socket::INET'->new(%options)
$options{'socket'} 'IO::Socket::INET'->new(%options)
Truth table0%0/3
A || B
A= $options{'socket'}B= 'IO::Socket::INET'->new(%options)
ABresult
1X1
011
000
48 0 ▶ $this->{socket} || die "can't get socket: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
$this->{"socket"} or die "can't get socket: $!\n" 0 0 0
49 0 $this->{codec} = new Net::RRP::Codec();
50 0 $this;
51 }
52  
53 sub _getLinesFromSocket
54 0 ▶{
Subroutine _getLinesFromSocket: not called CC=5 SCAR=34.0
55 0 my $this = shift;
56  
57 0 my $socket = $this->{socket};
58 0 ▶ my $buffer = ( $this->{_lineBuffer} ||= '' );
Condition0%0/2
$this->{"_lineBuffer"} ||= ""
l!l
00
MC/DC0%0/1
$this->{"_lineBuffer"} ||= ""
$this->{"_lineBuffer"}
Truth table0%0/2
A
A= $this->{"_lineBuffer"}
Aresult
11
00
59 0 my $signarute = Net::RRP::Codec::CRLF . '\.' . Net::RRP::Codec::CRLF;
60 0 my $line;
61  
62 my $length;
63  
64 0 ▶ while ( $length = Net::RRP::Toolkit::safeCall ( sub { $socket->sysread ( $line, 64 ) } ) )
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if ($length = Net::RRP::Toolkit::safeCall(sub { $socket->sysread($line, 64); } )) 0 0 0
65 {
66 0 $buffer .= $line;
67 0 ▶ if ( $buffer =~ m/$signarute/s )
Branch: 1 branch
BranchTrueFalseTotal
if ($buffer =~ /$signarute/s) { } 0 0 0
68 {
69 0 $this->{_lineBuffer} = $';
70 0 $buffer = $` . Net::RRP::Codec::CRLF . '.' . Net::RRP::Codec::CRLF;
71 0 last;
72 } else {
73 0 $this->{_lineBuffer} = $buffer;
74 }
75 }
76  
77 0 ▶ throw Net::RRP::Exception::IOError unless $length;
Branch: 1 branch
BranchTrueFalseTotal
unless $length 0 0 0
78  
79 0 $buffer;
80 }
81  
82 =head2 getRequest
83  
84 Get Net::RRP::Request class instance from socket. See L<Net::RRP::Codec(3)> for
85 more details about parsing of stream && get Net::RRP::Request instance.
86  
87 my $request = $protocol->getRequest ();
88  
89 =cut
90  
91 sub getRequest
92 0 ▶{
Subroutine getRequest: not called CC=1 SCAR=6.9
Pod documented
93 0 my $this = shift;
94 0 $this->{codec}->decodeRequest ( $this->_getLinesFromSocket() );
95 }
96  
97 =head2 getResponse
98  
99 Get Net::RRP::Response class instance from socket. See L<Net::RRP::Codec(3)> for
100 more details about parsing of stream && get Net::RRP::Response instance.
101  
102 my $response = $protocol->getResponse ();
103  
104 =cut
105  
106 sub getResponse
107 0 ▶{
Subroutine getResponse: not called CC=1 SCAR=6.9
Pod documented
108 0 my $this = shift;
109 0 $this->{codec}->decodeResponse ( $this->_getLinesFromSocket() );
110 }
111  
112 =head2 sendRequest
113  
114 Send rrp request to socket. Example:
115  
116 $protocol->sendRequest ( $request );
117  
118 throw throw Net::RRP::Exception::IOError if io errors.
119  
120 =cut
121  
122 sub sendRequest
123 0 ▶{
Subroutine sendRequest: not called CC=2 SCAR=17.9
Pod documented
124 0 my ( $this, $request ) = @_;
125 0 ▶ Net::RRP::Toolkit::safeWrite ( $this->{socket}, $this->{codec}->encodeRequest ( $request ) ) ||
Branch: 1 branch
BranchTrueFalseTotal
Net::RRP::Toolkit::safeWrite($this->{"socket"}, $this->{"codec"}->encodeRequest($request)) or "Net::RRP::Exception::IOError"->throw 0 0 0
126 throw Net::RRP::Exception::IOError ();
127 }
128  
129 =head2 sendResponse
130  
131 Send rrp response to socket. Example:
132  
133 $protocol->sendResponse ( $response );
134  
135 throw throw Net::RRP::Exception::IOError if io errors.
136  
137 =cut
138  
139 sub sendResponse
140 0 ▶{
Subroutine sendResponse: not called CC=2 SCAR=17.9
Pod documented
141 0 my ( $this, $response ) = @_;
142 0 ▶ Net::RRP::Toolkit::safeWrite ( $this->{socket}, $this->{codec}->encodeResponse ( $response ) ) ||
Branch: 1 branch
BranchTrueFalseTotal
Net::RRP::Toolkit::safeWrite($this->{"socket"}, $this->{"codec"}->encodeResponse($response)) or "Net::RRP::Exception::IOError"->throw 0 0 0
143 throw Net::RRP::Exception::IOError();
144 }
145  
146 =head2 sendHello()
147  
148 Send a "hello" message to a socket at the server part. You can pass registryName, version and buildDate parameters to this call.
149  
150 $protocol->hello ( registryName => "RU",
151 version => '1.1.0',
152 buildDate => 'Mon Jun 19 14:04:00 MSK 2000' ).
153  
154 Return true if ok and false at errors.
155  
156 =cut
157  
158 sub sendHello
159 0 ▶{
Subroutine sendHello: not called CC=5 SCAR=34.0
Pod documented
160 0 my ( $this, %params ) = @_;
161 0 ▶ my $registryName = $params{registryName} || $this->{registryName};
Condition0%0/3
$params{'registryName'} || $this->{'registryName'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$params{'registryName'} || $this->{'registryName'}
$params{'registryName'} $this->{'registryName'}
Truth table0%0/3
A || B
A= $params{'registryName'}B= $this->{'registryName'}
ABresult
1X1
011
000
162 0 ▶ my $buildDate = $params{buildDate} || $this->{buildDate};
Condition0%0/3
$params{'buildDate'} || $this->{'buildDate'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$params{'buildDate'} || $this->{'buildDate'}
$params{'buildDate'} $this->{'buildDate'}
Truth table0%0/3
A || B
A= $params{'buildDate'}B= $this->{'buildDate'}
ABresult
1X1
011
000
163 0 ▶ my $version = $params{version} || $this->{version};
Condition0%0/3
$params{'version'} || $this->{'version'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$params{'version'} || $this->{'version'}
$params{'version'} $this->{'version'}
Truth table0%0/3
A || B
A= $params{'version'}B= $this->{'version'}
ABresult
1X1
011
000
164 0 my $crlf = Net::RRP::Codec::CRLF;
165 0 my $buffer = "$registryName RRP Server version $version" . $crlf . "$buildDate" . $crlf . '.' . $crlf;
166  
167 0 ▶ Net::RRP::Toolkit::safeWrite ( $this->{socket}, $buffer ) || return throw Net::RRP::Exception::IOError;
Branch: 1 branch
BranchTrueFalseTotal
Net::RRP::Toolkit::safeWrite($this->{"socket"}, $buffer) or return "Net::RRP::Exception::IOError"->throw 0 0 0
168  
169 0 1;
170 }
171  
172 =head2 getHello
173  
174 Get "hello" from scream
175  
176 $protocol->getHello();
177  
178 =cut
179  
180 sub getHello
181 0 ▶{
Subroutine getHello: not called CC=1 SCAR=6.9
Pod documented
182 0 my $this = shift;
183 0 my $buffer = $this->_getLinesFromSocket();
184 0 $buffer;
185 }
186  
187 1 1;
188  
189 =head1 AUTHOR AND COPYRIGHT
190  
191 Net::RRP::Protocol (C) Michael Kulakov, Zenon N.S.P. 2000
192 125124, 19, 1-st Jamskogo polja st,
193 Moscow, Russian Federation
194  
195 mkul@cpan.org
196  
197 All rights reserved.
198  
199 You may distribute this package under the terms of either the GNU
200 General Public License or the Artistic License, as specified in the
201 Perl README file.
202  
203 =head1 SEE ALSO
204  
205 L<Net::RRP::Request(3)>, L<Net::RRP::Response(3)>, L<Net::RRP::Codec(3)>, RFC 2832
206  
207 =cut
208  
209 __END__
« RRP/Codec.pm ↑ Summary RRP/Request/Add.pm »