blib/lib/VCS/LibCVS/Client/Connection.pm

filter: Statementstmt 27.1% 16 / 59 Branchbran 0.0% 0 / 22 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 35.7% 5 / 14 Podpod 100% 8 / 8 totaltotal 28.1% 29 / 103 CC 12 SCAR 20.9
CC
12
Cov
20%
new
12.0
connect_fin
12.0
get_ioh_to_server
12.0
CRAP 8.1
« blib/lib/VCS/LibCVS/FileRevision.pm ↑ Summary blib/lib/VCS/LibCVS/WorkingDirectory.pm »
1 #
2 # Copyright (c) 2003,2004,2005 Alexander Taler (dissent@0--0.org)
3 #
4 # All rights reserved. This program is free software; you can redistribute it
5 # and/or modify it under the same terms as Perl itself.
6 #
7  
8 package VCS::LibCVS::Client::Connection;
9  
10 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 # If protocol debugging is enabled, use a subclass of IO::Handle which logs
14 # traffic.
15 1 ▶use VCS::LibCVS::Client::LoggingIOHandle;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 =head1 NAME
18  
19 VCS::LibCVS::Client::Connection - a connection to a CVS server
20  
21 =head1 SYNOPSIS
22  
23 my $conn = VCS::LibCVS::Client::Connection->new($root);
24 my $client = VCS::LibCVS::Client->new($conn, "/home/cvs");
25  
26 =head1 DESCRIPTION
27  
28 A connection to a CVS server. Its only real use is to construct a CVS client.
29 It represents a generic connection, but has a constructor, which will
30 instantiate the appropriate subclass.
31  
32 Once the connection is established, communication with the server takes place
33 through a pair of IO::Handles.
34  
35 =cut
36  
37 ###############################################################################
38 # Class constants
39 ###############################################################################
40  
41 1 ▶use constant REVISION => '$Header: /cvsroot/libcvs-perl/libcvs-perl/VCS/LibCVS/Client/Connection.pm,v 1.20 2005/10/10 12:52:11 dissent Exp $ ';
Subroutine BEGIN: called CC=1 SCAR=0.0
42  
43 # Protocol_map is a map from protocol strings to subclasses of connection.
44 # It's filled in by the subclasses, and accessed by the new_for_proto()
45 # constructor
46 1 ▶use vars ('%Protocol_map');
Subroutine BEGIN: called CC=1 SCAR=0.0
47  
48 ###############################################################################
49 # Private variables
50 ###############################################################################
51  
52 # Connection is a hash, and uses the following private entries. The first
53 # group can be accesed by the subclasses, the second group should not be.
54 #
55 # Used by subclasses:
56 #
57 # SubFromServer => An IO::Handle to read information from the server
58 # SubToServer => An IO::Handle to write information to the server
59 # These both must be set by subclasses upon connect(). They
60 # may be destroyed by them on disconnect()
61 #
62 # Root => VCS::LibCVS::Datum::Root object
63 #
64 # Not Used by subclasses:
65 #
66 # These file handles may be the same as the ones set by the subclass, or may be
67 # derived from them in order to do something else, like logging.
68 #
69 # FromServer => An IO::Handle to read information from the server
70 # ToServer => An IO::Handle to write information to the server
71 #
72 # Connected => boolean, true if the Connection is connected
73 # managed in connect() and disconnect()
74  
75 ###############################################################################
76 # Class routines
77 ###############################################################################
78  
79 =head1 CLASS ROUTINES
80  
81 =head2 B<new()>
82  
83 $connection = VCS::LibCVS::Client::Connection->new($root);
84  
85 =over 4
86  
87 =item argument 1 type: VCS::LibCVS::Datum::Root
88  
89 =item return type: VCS::LibCVS::Client::Connection
90  
91 =back
92  
93 If the protocol is not supported, an exception will be thrown.
94  
95 =cut
96  
97 0 ▶sub new {
Subroutine new: not called CC=3 SCAR=24.8
Pod documented
98 0 my $class = shift;
99 0 my $root = shift;
100  
101 # Instances of this class are never created, an instance of a subclass is
102 # created instead.
103 0 ▶ if ($class eq "VCS::LibCVS::Client::Connection") {
Branch: 1 branch
BranchTrueFalseTotal
if ($class eq "VCS::LibCVS::Client::Connection") 0 0 0
104 0 $class = $Protocol_map{$root->{Protocol}};
105 0 ▶ confess "Protocol $root->{Protocol} not supported" unless defined $class;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $class 0 0 0
106 0 return $class->new($root);
107 }
108  
109 # But there is a default constructor that subclasses can inherit.
110 0 my $that = bless {}, $class;
111 0 $that->{Root} = $root;
112 0 return $that;
113 }
114  
115 ###############################################################################
116 # Instance routines
117 ###############################################################################
118  
119 =head1 INSTANCE ROUTINES
120  
121 =head2 B<connect()>
122  
123 $connection->connect()
124  
125 =over 4
126  
127 =item return type: undef
128  
129 =back
130  
131 Connect to the server. After this, get_ioh_to_server and get_ioh_from_server
132 may be called. When the connection is no longer necessary, disconnect will get
133 rid of it.
134  
135 Subclasses must override this method, and use it to set the SubFromServer and
136 SubToServer private variables. They must call this method at the beginning of
137 their implementation, and connect_fin() at the end of it.
138  
139 =cut
140  
141 0 ▶sub connect {
Subroutine connect: not called CC=1 SCAR=6.9
Pod documented
142 0 my $self = shift;
143 0 return;
144 }
145  
146 =pod
147  
148 =head2 B<connect_fin()>
149  
150 $connection->connect_fin()
151  
152 =over 4
153  
154 =item return type: undef
155  
156 =back
157  
158 Called by subclasses, once they have established the connection, and created
159 the SubFromServer and SubToServer private variables.
160  
161 =cut
162  
163 0 ▶sub connect_fin {
Subroutine connect_fin: not called CC=3 SCAR=24.8
Pod documented
164 0 my $self = shift;
165  
166 0 ▶ return if $self->{Connected};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"Connected"} 0 0 0
167 0 $self->{Connected} = 1;
168  
169 # If requested, derive a logging IO from the provided one.
170 0 ▶ if ($VCS::LibCVS::Client::DebugLevel & VCS::LibCVS::Client::DEBUG_PROTOCOL) {
Branch: 1 branch
BranchTrueFalseTotal
if ($VCS::LibCVS::Client::DebugLevel & 1) { } 0 0 0
171 $self->{ToServer} =
172 0 VCS::LibCVS::Client::LoggingIOHandle->new($self->{SubToServer});
173 0 $self->{ToServer}->prefix("C: ");
174 0 $self->{ToServer}->logfile($VCS::LibCVS::Client::DebugOut);
175 $self->{FromServer} =
176 0 VCS::LibCVS::Client::LoggingIOHandle->new($self->{SubFromServer});
177 0 $self->{FromServer}->prefix("S: ");
178 0 $self->{FromServer}->logfile($VCS::LibCVS::Client::DebugOut);
179 } else {
180 0 $self->{ToServer} = $self->{SubToServer};
181 0 $self->{FromServer} = $self->{SubFromServer};
182 }
183 }
184  
185 =pod
186  
187 =head2 B<disconnect()>
188  
189 $connection->disconnect()
190  
191 =over 4
192  
193 =item return type: undef
194  
195 =back
196  
197 Closes this connection to the server. IO::Handles for communicating with the
198 server will no longer work.
199  
200 =cut
201  
202 0 ▶sub disconnect {
Subroutine disconnect: not called CC=2 SCAR=17.9
Pod documented
203 0 my $self = shift;
204 0 ▶ return if (!$self->{Connected});
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"Connected"} 0 0 0
205  
206 0 $self->{Connected} = 0;
207  
208 0 delete $self->{ToServer};
209 0 delete $self->{FromServer};
210 }
211  
212 =pod
213  
214 =head2 B<get_ioh_to_server()>
215  
216 $out_ioh = $connection->get_ioh_to_server();
217  
218 =over 4
219  
220 =item return type: IO::Handle
221  
222 =back
223  
224 Returns an open writeable IO::Handle. Stuff written to it is sent to the
225 server.
226  
227 The connection must be open to call this routine.
228  
229 =cut
230  
231 0 ▶sub get_ioh_to_server {
Subroutine get_ioh_to_server: not called CC=3 SCAR=24.8
Pod documented
232 0 my $self = shift;
233  
234 0 ▶ confess "Not connected" unless $self->connected();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->connected 0 0 0
235 0 ▶ confess "Stream to server not found" unless defined ($self->{ToServer});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"ToServer"} 0 0 0
236 0 return $self->{ToServer};
237 }
238  
239 =pod
240  
241 =head2 B<get_ioh_from_server()>
242  
243 $in_ioh = $connection->get_ioh_from_server();
244  
245 =over 4
246  
247 =item return type: IO::Handle
248  
249 =back
250  
251 Returns an open readable IO::Handle. Responses generated by the server are
252 read from this IO::Handle.
253  
254 The connection must be open to call this routine.
255  
256 =cut
257  
258 0 ▶sub get_ioh_from_server {
Subroutine get_ioh_from_server: not called CC=3 SCAR=24.8
Pod documented
259 0 my $self = shift;
260  
261 0 ▶ confess "Not connected" unless $self->connected();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->connected 0 0 0
262 0 ▶ confess "Stream from server not found" unless defined ($self->{FromServer});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"FromServer"} 0 0 0
263 0 return $self->{FromServer};
264 }
265  
266 =pod
267  
268 =head2 B<connected()>
269  
270 $is_connected = $connection->connected();
271  
272 =over 4
273  
274 =item return type: boolean scalar
275  
276 =back
277  
278 Returns a scalar with a true value if the connection is open, false otherwise.
279  
280 =cut
281  
282 0 ▶sub connected {
Subroutine connected: not called CC=1 SCAR=6.9
Pod documented
283 0 my $self = shift;
284 0 return $self->{Connected};
285 }
286  
287  
288 =pod
289  
290 =head2 B<get_root()>
291  
292 $cvsroot = $connection->get_root();
293  
294 =over 4
295  
296 =item return type: VCS::LibCVS::Datum::Root
297  
298 =back
299  
300 The root of the server that this is a connection to.
301  
302 =cut
303  
304 0 ▶sub get_root {
Subroutine get_root: not called CC=1 SCAR=6.9
Pod documented
305 0 my $self = shift;
306 0 return $self->{Root};
307 }
308  
309  
310 ###############################################################################
311 # Private routines
312 ###############################################################################
313  
314 #
315 # DESTROY
316 #
317 # Clean up any connection
318 #
319  
320 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=3 SCAR=24.8
321 0 my $self = shift;
322  
323 0 ▶ $self->{SubToServer}->close() if defined $self->{SubToServer};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"SubToServer"} 0 0 0
324 0 ▶ $self->{SubFromServer}->close() if defined $self->{SubFromServer};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"SubFromServer"} 0 0 0
325 }
326  
327 =pod
328  
329 =head1 SEE ALSO
330  
331 VCS::LibCVS::Client
332 VCS::LibCVS::Client::Connection::Local
333  
334 =cut
335  
336 1 1;
« blib/lib/VCS/LibCVS/FileRevision.pm ↑ Summary blib/lib/VCS/LibCVS/WorkingDirectory.pm »