« blib/lib/VCS/LibCVS/WorkingUnmanagedFile.pm
↑ Summary
blib/lib/VCS/LibCVS/Client/Connection/CvsPass.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::Request; | ||||||||||||||||||||||||||||||||
| 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::Request - a request in the CVS client protocol | ||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||
| 17 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||
| 19 | my $mode = VCS::LibCVS::Datum::Mode->new("u=rw,g=rw,o=r"); | ||||||||||||||||||||||||||||||||
| 20 | my $mod_request = VCS::LibCVS::Client::Request::Modified-> | ||||||||||||||||||||||||||||||||
| 21 | new( [ "afile" , $mode, "/tmp/afile" ] ); | ||||||||||||||||||||||||||||||||
| 22 | $client->submit_request($mod_request); | ||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||
| 24 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||
| 26 | This is a generic superclass for all of the various requests in the cvsclient | ||||||||||||||||||||||||||||||||
| 27 | protocol. A request includes zero or more pieces of data (LibCVS::Datum), | ||||||||||||||||||||||||||||||||
| 28 | which are specified when the request is constructed. A request is submitted to | ||||||||||||||||||||||||||||||||
| 29 | the server through a Client, which may return some responses. You should | ||||||||||||||||||||||||||||||||
| 30 | instantiate subclasses of this class, not this class itself. | ||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||
| 32 | The protocol defines which requests will elicit responses, so you can ask a | ||||||||||||||||||||||||||||||||
| 33 | request if it expects a response. A given server may not support all requests, | ||||||||||||||||||||||||||||||||
| 34 | the Client can queried to find out which ones are supported. Requests other | ||||||||||||||||||||||||||||||||
| 35 | than those must not be submitted to the server. | ||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||
| 37 | =cut | ||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||
| 39 | ############################################################################### | ||||||||||||||||||||||||||||||||
| 40 | # Class constants | ||||||||||||||||||||||||||||||||
| 41 | ############################################################################### | ||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||
| 43 | 1 | ▶ | use constant REVISION => '$Header: /cvsroot/libcvs-perl/libcvs-perl/VCS/LibCVS/Client/Request.pm,v 1.23 2005/10/10 12:52:11 dissent Exp $ '; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||
| 45 | # Valid_requests is a list of all the requests in this implementation. | ||||||||||||||||||||||||||||||||
| 46 | # A request registers itself here in its BEGIN block. It is needed to populate | ||||||||||||||||||||||||||||||||
| 47 | # the list of valid requests | ||||||||||||||||||||||||||||||||
| 48 | 1 | ▶ | use vars ('@Valid_requests'); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 49 | 1 | @Valid_requests = (); | |||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||
| 51 | ############################################################################### | ||||||||||||||||||||||||||||||||
| 52 | # Private variables | ||||||||||||||||||||||||||||||||
| 53 | ############################################################################### | ||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||
| 55 | # It's a hash and keeps these variables: | ||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||
| 57 | # RequestName => The name of this request which should be sent to the server | ||||||||||||||||||||||||||||||||
| 58 | # Set in constructor | ||||||||||||||||||||||||||||||||
| 59 | # Args => A reference to an array of objects of type LibCVS::Datum | ||||||||||||||||||||||||||||||||
| 60 | # Set in constructor | ||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||
| 62 | ############################################################################### | ||||||||||||||||||||||||||||||||
| 63 | # Class routines | ||||||||||||||||||||||||||||||||
| 64 | ############################################################################### | ||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||
| 66 | =head1 CLASS ROUTINES | ||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||
| 68 | =head2 B<new()> | ||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||
| 70 | $request = Client::Request::SubClass->new($args_data) | ||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||
| 72 | Only call this on subclasses of Client::Request. Some subclasses override this | ||||||||||||||||||||||||||||||||
| 73 | constructor. | ||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||
| 75 | =over 4 | ||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||
| 77 | =item return type: Client::Request::SubClass | ||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||
| 79 | =item argument 1 type: (optional) array ref | ||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||
| 81 | A ref to an array which contains the data for constructing the required | ||||||||||||||||||||||||||||||||
| 82 | Datum's of the Client::Request. If the Client::Request has no required | ||||||||||||||||||||||||||||||||
| 83 | Datum's, you may omit the argument (pass undef). | ||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||
| 85 | To determine the required data check the Request's documentation, or call the | ||||||||||||||||||||||||||||||||
| 86 | Request's required_data() routine. | ||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||
| 88 | =back | ||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||
| 90 | Constructs and returns a new request. | ||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||
| 92 | =cut | ||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||
| 94 | # A request maintains an internal variable which is its name as it must send to | ||||||||||||||||||||||||||||||||
| 95 | # the CVS server. This name can be derived from the name of the class, by | ||||||||||||||||||||||||||||||||
| 96 | # substituing _'s with -'s. Rather than write constructors for each subtype, I | ||||||||||||||||||||||||||||||||
| 97 | # do that substitution here, and set the variable. It's a little nasty, but it | ||||||||||||||||||||||||||||||||
| 98 | # works. | ||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 101 | 0 | my ($class, $args_data) = @_; | |||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||
| 103 | # This class shouldn't be instantiated itself | ||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | die "VCS::LibCVS::Client::Request is an abstract class" if | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 105 | $class eq "VCS::LibCVS::Client::Request"; | ||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||
| 107 | # Transform the final chunk of the classname into the protocol request name | ||||||||||||||||||||||||||||||||
| 108 | 0 | my $request_name = $class; | |||||||||||||||||||||||||||||||
| 109 | 0 | $request_name =~ s/.*::(.*)/$1/; | |||||||||||||||||||||||||||||||
| 110 | 0 | $request_name =~ s/_/-/g; | |||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||
| 112 | 0 | my $that = bless {}, $class; | |||||||||||||||||||||||||||||||
| 113 | 0 | $that->{RequestName} = $request_name; | |||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||
| 115 | # Process the provided args. | ||||||||||||||||||||||||||||||||
| 116 | # For each passed parameter, call the constructor for the expected type of | ||||||||||||||||||||||||||||||||
| 117 | # arg. | ||||||||||||||||||||||||||||||||
| 118 | 0 | ▶ | $args_data = [] if !defined($args_data); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 119 | 0 | my @required_data = $that->required_data; | |||||||||||||||||||||||||||||||
| 120 | 0 | ▶ | confess "Wrong number of args" if (@required_data != @$args_data); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 121 | my @args = map { | ||||||||||||||||||||||||||||||||
| 122 | 0 | "VCS::LibCVS::Datum::$_"->new(shift(@$args_data)); | |||||||||||||||||||||||||||||||
| 123 | } @required_data; | ||||||||||||||||||||||||||||||||
| 124 | 0 | $that->{Args} = \@args; | |||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||
| 126 | 0 | return $that; | |||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||
| 129 | =head2 B<required_data()> | ||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||
| 131 | @request_required_data = $request->required_data() | ||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||
| 133 | =over 4 | ||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||
| 135 | =item return type: list of names of subclasses of Datum | ||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||
| 137 | A list of strings which are subpackages of Datum, like ("String", | ||||||||||||||||||||||||||||||||
| 138 | "DirectoryName", "TagSpec"). | ||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||
| 140 | =back | ||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||
| 142 | The list of data which are required in this request. Each of the named classes | ||||||||||||||||||||||||||||||||
| 143 | are subpackages of "VCS::LibCVS::Datum". This list is used in the construction | ||||||||||||||||||||||||||||||||
| 144 | of the request, whose parameters must match the names in this list. | ||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||
| 146 | =cut | ||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||
| 148 | # The default is one simple Datum. Most subclasses will override this. | ||||||||||||||||||||||||||||||||
| 149 | 0 | ▶ | sub required_data { | ||||||||||||||||||||||||||||||
|
Subroutine
required_data: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 150 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 151 | 0 | return "String"; | |||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||
| 154 | ############################################################################### | ||||||||||||||||||||||||||||||||
| 155 | # Instance routines | ||||||||||||||||||||||||||||||||
| 156 | ############################################################################### | ||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||
| 158 | =head1 INSTANCE ROUTINES | ||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||
| 160 | =head2 B<protocol_print()> | ||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||
| 162 | $request->protocol_print($file_handle) | ||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||
| 164 | =over 4 | ||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||
| 166 | =item return type: undef | ||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||
| 168 | =item argument 1 type: IO::Handle | ||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||
| 170 | =back | ||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||
| 172 | Prints the Request to the IO::Handle. The output will be formatted for sending | ||||||||||||||||||||||||||||||||
| 173 | to the cvs server, including the placement of newlines. | ||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||
| 175 | =cut | ||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||
| 177 | # it doesn't use the as_string routine, because we will need to add streaming | ||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||
| 179 | 0 | ▶ | sub protocol_print { | ||||||||||||||||||||||||||||||
|
Subroutine
protocol_print: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 180 | 0 | my ($self, $ioh) = @_; | |||||||||||||||||||||||||||||||
| 181 | 0 | my $args = $self->{Args}; | |||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||
| 183 | 0 | ▶ | $ioh->print($self->{RequestName} . " ") || confess "print 1 to ioh failed"; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||
| 185 | # Each Datum ends it submit with a newline. So if there are none, add one | ||||||||||||||||||||||||||||||||
| 186 | 0 | ▶ | ($ioh->print("\n") || confess "print 2 to ioh failed") if (!@$args); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/5
@$args || ($ioh->print("\n") || confess('print 2 to ioh failed'))
$ioh->print("\n") or confess("print 2 to ioh failed")
MC/DC0%0/2
@$args || ($ioh->print("\n") || confess('print 2 to ioh failed'))
@$args
$ioh->print("\n")
Truth table0%0/3
A || B
A= @$argsB= $ioh->print("\n")
| |||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||
| 188 | 0 | ▶ | map { $_->protocol_print($ioh) || confess "print 3 to ioh failed"; } @$args; | ||||||||||||||||||||||||||||||
|
Condition0%0/2
$_->protocol_print($ioh) || confess('print 3 to ioh failed')
MC/DC0%0/1
$_->protocol_print($ioh) || confess('print 3 to ioh failed')
$_->protocol_print($ioh)
Truth table0%0/2
A
A= $_->protocol_print($ioh)
| |||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||
| 191 | =head2 B<as_protocol_string()> | ||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||
| 193 | $request_string = $request->as_protocol_string() | ||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||
| 195 | =over 4 | ||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||
| 197 | =item return type: string scalar | ||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||
| 199 | =back | ||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||
| 201 | Returns the Client::Request as a string suitable for being sent to the server, | ||||||||||||||||||||||||||||||||
| 202 | including the placement of newlines. | ||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||
| 204 | =cut | ||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||
| 206 | 0 | ▶ | sub as_protocol_string { | ||||||||||||||||||||||||||||||
|
Subroutine
as_protocol_string: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 207 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 208 | 0 | my $args = $self->{Args}; | |||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||
| 210 | 0 | my $string = $self->{RequestName} . " "; | |||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||
| 212 | # Each Datum ends its submit with a newline. So if there are none, add one | ||||||||||||||||||||||||||||||||
| 213 | 0 | ▶ | $string .= "\n" if (!@$args); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||
| 215 | 0 | map { $string .= $_->as_protocol_string; } @$args; | |||||||||||||||||||||||||||||||
| 216 | 0 | return $string; | |||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||
| 219 | =head2 B<response_expected()> | ||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||
| 221 | $response_expected = $request->response_expected() | ||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||
| 223 | =over 4 | ||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||
| 225 | =item return type: boolean scalar | ||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||
| 227 | =back | ||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||
| 229 | Indicates if the request expects to elicit a response when submitted to the | ||||||||||||||||||||||||||||||||
| 230 | server. | ||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||
| 232 | =cut | ||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||
| 234 | # generally this is based on the capitalization of the first letter of the name | ||||||||||||||||||||||||||||||||
| 235 | 0 | ▶ | sub response_expected { | ||||||||||||||||||||||||||||||
|
Subroutine
response_expected: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 236 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 237 | 0 | return ($self->{RequestName} =~ /^[a-z]/); | |||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||
| 240 | =head2 B<name()> | ||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||
| 242 | $name = $request->name() | ||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||
| 244 | =over 4 | ||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||
| 246 | =item return type: string scalar | ||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||
| 248 | =back | ||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||
| 250 | Returns the protocol name of the request. | ||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||
| 252 | =cut | ||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||
| 254 | 0 | ▶ | sub name { | ||||||||||||||||||||||||||||||
|
Subroutine
name: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 255 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 256 | 0 | return $self->{RequestName}; | |||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||
| 259 | ############################################################################### | ||||||||||||||||||||||||||||||||
| 260 | # Private routines | ||||||||||||||||||||||||||||||||
| 261 | ############################################################################### | ||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||
| 263 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||
| 265 | VCS::LibCVS::Datum | ||||||||||||||||||||||||||||||||
| 266 | VCS::LibCVS::Client | ||||||||||||||||||||||||||||||||
| 267 | VCS::LibCVS::Client::Request::Requests | ||||||||||||||||||||||||||||||||
| 268 | VCS::LibCVS::Client::Request::Argument | ||||||||||||||||||||||||||||||||
| 269 | VCS::LibCVS::Client::Request::ArgumentUsingRequests | ||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||
| 271 | =cut | ||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||
| 273 | 1 | 1; | |||||||||||||||||||||||||||||||