« blib/lib/VCS/LibCVS/RepositoryDirectory.pm
↑ Summary
blib/lib/VCS/LibCVS/WorkingFileOrDirectory.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::Response; | ||||||||||
| 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 | =head1 NAME | ||||||||||
| 14 | |||||||||||
| 15 | VCS::LibCVS::Client::Response - a response in the CVS client protocol | ||||||||||
| 16 | |||||||||||
| 17 | =head1 SYNOPSIS | ||||||||||
| 18 | |||||||||||
| 19 | my @responses = Client::Response->read_from_server($server_conn); | ||||||||||
| 20 | if (($responses[-1]->isa("VCS::LibCVS::Client::Response::error"))) { | ||||||||||
| 21 | my $errors; | ||||||||||
| 22 | foreach my $resp (@responses) { $errors .= $resp->get_errors(); }; | ||||||||||
| 23 | confess "Request failed: $errors"; | ||||||||||
| 24 | } else { | ||||||||||
| 25 | # remove the "ok" response | ||||||||||
| 26 | pop @responses; | ||||||||||
| 27 | } | ||||||||||
| 28 | |||||||||||
| 29 | =head1 DESCRIPTION | ||||||||||
| 30 | |||||||||||
| 31 | This is a generic superclass for all of the various responses in the cvsclient | ||||||||||
| 32 | protocol. A response includes zero or more pieces of data (LibCVS::Datum), | ||||||||||
| 33 | which the server sends. Subclasses of this class should be instantiated, not | ||||||||||
| 34 | this class itself. | ||||||||||
| 35 | |||||||||||
| 36 | If a user of the library cannot handle all types of responses from the server | ||||||||||
| 37 | it can tailor which responses it can receive in the Client; but only before the | ||||||||||
| 38 | connection is established. To do this, use the valid_responses() routine of | ||||||||||
| 39 | the VCS::LibCVS::Client class. | ||||||||||
| 40 | |||||||||||
| 41 | The data types for each response are predetermined. Check its documentation to | ||||||||||
| 42 | find out what they are. Each response can be queried for its type and the data | ||||||||||
| 43 | which it contains, returned as subclasses of LibCVS::Datum. They | ||||||||||
| 44 | |||||||||||
| 45 | =cut | ||||||||||
| 46 | |||||||||||
| 47 | # There might be good reason to create a new class ResponseList which holds a | ||||||||||
| 48 | # list of responses, because that is how they are typically handled. | ||||||||||
| 49 | |||||||||||
| 50 | ############################################################################### | ||||||||||
| 51 | # Class constants | ||||||||||
| 52 | ############################################################################### | ||||||||||
| 53 | |||||||||||
| 54 | 1 | ▶ | use constant REVISION => '$Header: /cvsroot/libcvs-perl/libcvs-perl/VCS/LibCVS/Client/Response.pm,v 1.27 2005/10/10 12:52:11 dissent Exp $ '; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 55 | |||||||||||
| 56 | # Valid_responses is a list of all the responses in this implementation. | ||||||||||
| 57 | # A response registers itself here in its BEGIN block. It is needed by the | ||||||||||
| 58 | # Valid-Responses Request | ||||||||||
| 59 | 1 | ▶ | use vars ('@Valid_responses'); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 60 | 1 | @Valid_responses = (); | |||||||||
| 61 | |||||||||||
| 62 | ############################################################################### | ||||||||||
| 63 | # Private variables | ||||||||||
| 64 | ############################################################################### | ||||||||||
| 65 | |||||||||||
| 66 | # Args => an array reference of data included in the response | ||||||||||
| 67 | # set in the constructor | ||||||||||
| 68 | # ResponseName => the protocol name of this response. | ||||||||||
| 69 | # set in the constructor | ||||||||||
| 70 | |||||||||||
| 71 | ############################################################################### | ||||||||||
| 72 | # Class routines | ||||||||||
| 73 | ############################################################################### | ||||||||||
| 74 | |||||||||||
| 75 | =head1 CLASS ROUTINES | ||||||||||
| 76 | |||||||||||
| 77 | =head2 B<read_from_ioh()> | ||||||||||
| 78 | |||||||||||
| 79 | @responses = Client::Response->read_from_ioh($conn) | ||||||||||
| 80 | |||||||||||
| 81 | Read a list of responses from the server. | ||||||||||
| 82 | |||||||||||
| 83 | =over 4 | ||||||||||
| 84 | |||||||||||
| 85 | =item return type: a list of Client::Response | ||||||||||
| 86 | |||||||||||
| 87 | =item argument 1 type: IO::Handle | ||||||||||
| 88 | |||||||||||
| 89 | An IO::Handle from which the list of responses should be read. Typically this | ||||||||||
| 90 | will be a link directly from the server. | ||||||||||
| 91 | |||||||||||
| 92 | =back | ||||||||||
| 93 | |||||||||||
| 94 | Reads a list of responses from the server, stopping when it receives an "ok" or | ||||||||||
| 95 | "error". This is the typical way to get a response. The number of responses | ||||||||||
| 96 | received is unpredictable, as additional responses may be included. | ||||||||||
| 97 | |||||||||||
| 98 | It will block if there is not at least one response. | ||||||||||
| 99 | |||||||||||
| 100 | =cut | ||||||||||
| 101 | |||||||||||
| 102 | # It finds the correct class to create by converting the response name from the | ||||||||||
| 103 | # server into a classname. This means that the responses have to be named | ||||||||||
| 104 | # predictably. | ||||||||||
| 105 | # | ||||||||||
| 106 | # It could check for constructors in the subtype by calling UNIVERSAL->can() | ||||||||||
| 107 | |||||||||||
| 108 | 0 | ▶ | sub read_from_ioh { | ||||||||
|
Subroutine
read_from_ioh: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 109 | 0 | my $class = shift; | |||||||||
| 110 | 0 | my $ioh = shift; | |||||||||
| 111 | |||||||||||
| 112 | 0 | my $cur_response; | |||||||||
| 113 | my @responses; | ||||||||||
| 114 | |||||||||||
| 115 | # Loop until a terminal response is read. | ||||||||||
| 116 | 0 | ▶ | do { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 117 | |||||||||||
| 118 | # Get the name of the response | ||||||||||
| 119 | # and gobble the next character, which should be a newline or a space | ||||||||||
| 120 | 0 | my $response_name = ""; | |||||||||
| 121 | 0 | ▶ | while ((my $char = $ioh->getc()) =~ /\S/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 122 | 0 | $response_name .= $char; | |||||||||
| 123 | } | ||||||||||
| 124 | |||||||||||
| 125 | # Convert response name into a class name | ||||||||||
| 126 | 0 | my $response_class = $response_name; | |||||||||
| 127 | 0 | $response_class =~ s/-/_/g; | |||||||||
| 128 | 0 | $response_class = $class . "::" . $response_class; | |||||||||
| 129 | |||||||||||
| 130 | # Create the response of the appropriate type. If it's unknown there has | ||||||||||
| 131 | # been a protocol breakdown and we don't know how to proceed, so we just die | ||||||||||
| 132 | 0 | $cur_response = $response_class->new($response_name, $ioh); | |||||||||
| 133 | |||||||||||
| 134 | 0 | push @responses, $cur_response; | |||||||||
| 135 | |||||||||||
| 136 | } while (! $cur_response->terminal()); | ||||||||||
| 137 | |||||||||||
| 138 | 0 | return @responses; | |||||||||
| 139 | } | ||||||||||
| 140 | |||||||||||
| 141 | =head2 B<new()> | ||||||||||
| 142 | |||||||||||
| 143 | $response = Client::Response->new($name, $conn) | ||||||||||
| 144 | |||||||||||
| 145 | Read a single response of the given name from the server. | ||||||||||
| 146 | |||||||||||
| 147 | =over 4 | ||||||||||
| 148 | |||||||||||
| 149 | =item return type: a Client::Response | ||||||||||
| 150 | |||||||||||
| 151 | =item argument 1 type: scalar | ||||||||||
| 152 | |||||||||||
| 153 | The name of the response as read from the server. | ||||||||||
| 154 | |||||||||||
| 155 | =item argument 2 type: IO::Handle | ||||||||||
| 156 | |||||||||||
| 157 | A IO::Handle from which the response should be read. Typically this | ||||||||||
| 158 | will be a link directly from the server. | ||||||||||
| 159 | |||||||||||
| 160 | =back | ||||||||||
| 161 | |||||||||||
| 162 | Reads a single response from the server and creates an object for it. This | ||||||||||
| 163 | routine should only be called in read_from_server above. Users of the libary | ||||||||||
| 164 | should call that one, not this one. | ||||||||||
| 165 | |||||||||||
| 166 | The name of the response has already been read from the server. It is similar | ||||||||||
| 167 | but not identical to the class name of the response. The only issue is that | ||||||||||
| 168 | the '-' character has been replaced by '_'. | ||||||||||
| 169 | |||||||||||
| 170 | =cut | ||||||||||
| 171 | |||||||||||
| 172 | 0 | ▶ | sub new { | ||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 173 | 0 | my ($class, $name, $ioh) = @_; | |||||||||
| 174 | |||||||||||
| 175 | 0 | my $that = bless {}, $class; | |||||||||
| 176 | 0 | $that->{ResponseName} = $name; | |||||||||
| 177 | |||||||||||
| 178 | 0 | my @args = map { "VCS::LibCVS::Datum::$_"->new($ioh); } $that->included_data; | |||||||||
| 179 | 0 | $that->{Args} = \@args; | |||||||||
| 180 | |||||||||||
| 181 | 0 | return $that; | |||||||||
| 182 | } | ||||||||||
| 183 | |||||||||||
| 184 | ############################################################################### | ||||||||||
| 185 | # Instance routines | ||||||||||
| 186 | ############################################################################### | ||||||||||
| 187 | |||||||||||
| 188 | =head1 INSTANCE ROUTINES | ||||||||||
| 189 | |||||||||||
| 190 | =head2 B<terminal()> | ||||||||||
| 191 | |||||||||||
| 192 | $is_terminal = $response->terminal() | ||||||||||
| 193 | |||||||||||
| 194 | =over 4 | ||||||||||
| 195 | |||||||||||
| 196 | =item return type: boolean | ||||||||||
| 197 | |||||||||||
| 198 | Indicates if this is a terminal response. | ||||||||||
| 199 | |||||||||||
| 200 | =back | ||||||||||
| 201 | |||||||||||
| 202 | A terminal response terminates the list of responses that the server is sending | ||||||||||
| 203 | to the user. Only 'ok' and 'error' are terminal responses. | ||||||||||
| 204 | |||||||||||
| 205 | =cut | ||||||||||
| 206 | |||||||||||
| 207 | 0 | ▶ | sub terminal { | ||||||||
|
Subroutine
terminal: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 208 | 0 | my $self = shift; | |||||||||
| 209 | 0 | return 0; | |||||||||
| 210 | } | ||||||||||
| 211 | |||||||||||
| 212 | =head2 B<included_data()> | ||||||||||
| 213 | |||||||||||
| 214 | @arg_types = $response->included_data() | ||||||||||
| 215 | |||||||||||
| 216 | =over 4 | ||||||||||
| 217 | |||||||||||
| 218 | =item return type: list of scalar strings | ||||||||||
| 219 | |||||||||||
| 220 | The types of the args that this response expects | ||||||||||
| 221 | |||||||||||
| 222 | =back | ||||||||||
| 223 | |||||||||||
| 224 | Each string is the name of a subpackage of Datum. They are used to construct | ||||||||||
| 225 | the response as it is read from the server. | ||||||||||
| 226 | |||||||||||
| 227 | =cut | ||||||||||
| 228 | |||||||||||
| 229 | 0 | ▶ | sub included_data { | ||||||||
|
Subroutine
included_data: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 230 | 0 | my $self = shift; | |||||||||
| 231 | 0 | return "String"; | |||||||||
| 232 | } | ||||||||||
| 233 | |||||||||||
| 234 | =head2 B<get_errors()> | ||||||||||
| 235 | |||||||||||
| 236 | $error_message = $response->get_errors() | ||||||||||
| 237 | |||||||||||
| 238 | =over 4 | ||||||||||
| 239 | |||||||||||
| 240 | =item return type: scalar string | ||||||||||
| 241 | |||||||||||
| 242 | Returns any error messages | ||||||||||
| 243 | |||||||||||
| 244 | =back | ||||||||||
| 245 | |||||||||||
| 246 | If the response is an error message it will return its string. Otherwise it | ||||||||||
| 247 | will return undef. | ||||||||||
| 248 | |||||||||||
| 249 | =cut | ||||||||||
| 250 | |||||||||||
| 251 | 0 | ▶ | sub get_errors { | ||||||||
|
Subroutine
get_errors: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 252 | 0 | my $self = shift; | |||||||||
| 253 | 0 | return; | |||||||||
| 254 | } | ||||||||||
| 255 | |||||||||||
| 256 | =head2 B<get_message()> | ||||||||||
| 257 | |||||||||||
| 258 | $message = $response->get_message() | ||||||||||
| 259 | |||||||||||
| 260 | =over 4 | ||||||||||
| 261 | |||||||||||
| 262 | =item return type: scalar string | ||||||||||
| 263 | |||||||||||
| 264 | Returns any regular messages | ||||||||||
| 265 | |||||||||||
| 266 | =back | ||||||||||
| 267 | |||||||||||
| 268 | If the response is a message (M or MB) it will return its string. Otherwise it | ||||||||||
| 269 | will return undef. | ||||||||||
| 270 | |||||||||||
| 271 | =cut | ||||||||||
| 272 | |||||||||||
| 273 | 0 | ▶ | sub get_message { | ||||||||
|
Subroutine
get_message: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 274 | 0 | my $self = shift; | |||||||||
| 275 | 0 | return; | |||||||||
| 276 | } | ||||||||||
| 277 | |||||||||||
| 278 | =head2 B<as_protocol_string()> | ||||||||||
| 279 | |||||||||||
| 280 | $response_string = $response->as_protocol_string() | ||||||||||
| 281 | |||||||||||
| 282 | =over 4 | ||||||||||
| 283 | |||||||||||
| 284 | =item return type: scalar string | ||||||||||
| 285 | |||||||||||
| 286 | =back | ||||||||||
| 287 | |||||||||||
| 288 | Returns the Client::Response as a string as it was received from the server. | ||||||||||
| 289 | |||||||||||
| 290 | =cut | ||||||||||
| 291 | |||||||||||
| 292 | 0 | ▶ | sub as_protocol_string { | ||||||||
|
Subroutine
as_protocol_string: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 293 | 0 | my $self = shift; | |||||||||
| 294 | 0 | my $string = $self->{ResponseName} . " "; | |||||||||
| 295 | # if there are no args an extra newline is needed after the response name | ||||||||||
| 296 | 0 | ▶ | if (@{$self->{Args}}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 297 | 0 | map { $string .= $_->as_protocol_string(); } @{$self->{Args}}; | |||||||||
| 298 | } else { | ||||||||||
| 299 | 0 | $string .= "\n"; | |||||||||
| 300 | } | ||||||||||
| 301 | 0 | return $string; | |||||||||
| 302 | } | ||||||||||
| 303 | |||||||||||
| 304 | =head2 B<data()> | ||||||||||
| 305 | |||||||||||
| 306 | $response_data = $response->data() | ||||||||||
| 307 | |||||||||||
| 308 | =over 4 | ||||||||||
| 309 | |||||||||||
| 310 | =item return type: ref to array containing LibCVS::Datum objects | ||||||||||
| 311 | |||||||||||
| 312 | =back | ||||||||||
| 313 | |||||||||||
| 314 | The order of the returned data is documented for each Response. | ||||||||||
| 315 | |||||||||||
| 316 | =cut | ||||||||||
| 317 | |||||||||||
| 318 | 0 | ▶ | sub data() { | ||||||||
|
Subroutine
data: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 319 | 0 | my $self = shift; | |||||||||
| 320 | 0 | return $self->{Args}; | |||||||||
| 321 | } | ||||||||||
| 322 | |||||||||||
| 323 | ############################################################################### | ||||||||||
| 324 | # Private routines | ||||||||||
| 325 | ############################################################################### | ||||||||||
| 326 | |||||||||||
| 327 | =head1 SEE ALSO | ||||||||||
| 328 | |||||||||||
| 329 | VCS::LibCVS::Client | ||||||||||
| 330 | VCS::LibCVS::Client::Response::Responses | ||||||||||
| 331 | VCS::LibCVS::Client::Response::FileUpdatingResponses | ||||||||||
| 332 | VCS::LibCVS::Client::Response::FileUpdateModifyingResponses | ||||||||||
| 333 | |||||||||||
| 334 | =cut | ||||||||||
| 335 | |||||||||||
| 336 | 1 | 1; | |||||||||