| 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::Argument; | ||||||||||||||
| 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::Argument - an Argument request | ||||||||||||||
| 16 | |||||||||||||||
| 17 | =head1 SYNOPSIS | ||||||||||||||
| 18 | |||||||||||||||
| 19 | $switch = VCS::LibCVS::Client::Request::Argument->new("-m"); | ||||||||||||||
| 20 | $msg = VCS::LibCVS::Client::Request::Argument->new("2 line\nmessage"); | ||||||||||||||
| 21 | $msg = VCS::LibCVS::Client::Request::Argument->new( ["2 line","msg"] ); | ||||||||||||||
| 22 | $client->submit_request($switch); | ||||||||||||||
| 23 | $client->submit_request($msg); | ||||||||||||||
| 24 | |||||||||||||||
| 25 | =head1 DESCRIPTION | ||||||||||||||
| 26 | |||||||||||||||
| 27 | Used for sending arguments to the server. These are similar to the cvs | ||||||||||||||
| 28 | command-line switches. | ||||||||||||||
| 29 | |||||||||||||||
| 30 | The only difference from a regular request is the constructor. | ||||||||||||||
| 31 | |||||||||||||||
| 32 | An Argument can contain arbitrary characters, including newlines. In order to | ||||||||||||||
| 33 | support this the CVS client protocol has a request called Argumentx that | ||||||||||||||
| 34 | appends a line to a previous Argument request. This library rolls these two | ||||||||||||||
| 35 | requests into one object which can handle arguments with multiple lines. | ||||||||||||||
| 36 | |||||||||||||||
| 37 | =head1 SUPERCLASS | ||||||||||||||
| 38 | |||||||||||||||
| 39 | VCS::LibCVS::Client::Request | ||||||||||||||
| 40 | |||||||||||||||
| 41 | =cut | ||||||||||||||
| 42 | |||||||||||||||
| 43 | ############################################################################### | ||||||||||||||
| 44 | # Class constants | ||||||||||||||
| 45 | ############################################################################### | ||||||||||||||
| 46 | |||||||||||||||
| 47 | 1 | ▶ | use constant REVISION => '$Header: /cvsroot/libcvs-perl/libcvs-perl/VCS/LibCVS/Client/Request/Argument.pm,v 1.12 2005/10/10 12:52:11 dissent Exp $ '; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 48 | |||||||||||||||
| 49 | 1 | ▶ | use vars ('@ISA'); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 50 | 1 | @ISA =("VCS::LibCVS::Client::Request"); | |||||||||||||
| 51 | |||||||||||||||
| 52 | 1 | ▶ | sub BEGIN { push @VCS::LibCVS::Client::Request::Valid_requests, "Argument"; } | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 53 | |||||||||||||||
| 54 | ############################################################################### | ||||||||||||||
| 55 | # Private variables | ||||||||||||||
| 56 | ############################################################################### | ||||||||||||||
| 57 | |||||||||||||||
| 58 | ############################################################################### | ||||||||||||||
| 59 | # Class routines | ||||||||||||||
| 60 | ############################################################################### | ||||||||||||||
| 61 | |||||||||||||||
| 62 | # Override the constructor, since it must handle a variable number of Datum. In | ||||||||||||||
| 63 | # addition we give it the flexibility of allowing newlines in its args_data. | ||||||||||||||
| 64 | # | ||||||||||||||
| 65 | # Request::Argument CLASS->new($args_data) | ||||||||||||||
| 66 | # | ||||||||||||||
| 67 | # $args_data may be a scalar, or an array ref whose contents are join("\n")ed. | ||||||||||||||
| 68 | |||||||||||||||
| 69 | =head1 CLASS ROUTINES | ||||||||||||||
| 70 | |||||||||||||||
| 71 | =head2 B<new()> | ||||||||||||||
| 72 | |||||||||||||||
| 73 | $request = Client::Request::Argument->new($args_data) | ||||||||||||||
| 74 | |||||||||||||||
| 75 | =over 4 | ||||||||||||||
| 76 | |||||||||||||||
| 77 | =item return type: Client::Request::Argument | ||||||||||||||
| 78 | |||||||||||||||
| 79 | =item argument 1 type: . . . | ||||||||||||||
| 80 | |||||||||||||||
| 81 | =over 2 | ||||||||||||||
| 82 | |||||||||||||||
| 83 | =item E<32>E<32>option 1: scalar | ||||||||||||||
| 84 | |||||||||||||||
| 85 | All of the argument data, across any number of lines. | ||||||||||||||
| 86 | |||||||||||||||
| 87 | =item E<32>E<32>option 2: array ref | ||||||||||||||
| 88 | |||||||||||||||
| 89 | The elements of the array are joined with newlines between them to form a | ||||||||||||||
| 90 | scalar which is used as the data. | ||||||||||||||
| 91 | |||||||||||||||
| 92 | =back | ||||||||||||||
| 93 | |||||||||||||||
| 94 | =back | ||||||||||||||
| 95 | |||||||||||||||
| 96 | Constructs and returns a new Argument Request. | ||||||||||||||
| 97 | |||||||||||||||
| 98 | =cut | ||||||||||||||
| 99 | |||||||||||||||
| 100 | 0 | ▶ | sub new { | ||||||||||||
|
Subroutine
new: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||
| 101 | 0 | my ($class, $args_data) = @_; | |||||||||||||
| 102 | |||||||||||||||
| 103 | 0 | my $that = bless {}, $class; | |||||||||||||
| 104 | |||||||||||||||
| 105 | # Request name is always argument. Change this if you subclass. | ||||||||||||||
| 106 | 0 | $that->{RequestName} = "Argument"; | |||||||||||||
| 107 | |||||||||||||||
| 108 | # Turn the $args_data into a big long string, split that into an array of | ||||||||||||||
| 109 | # lines and store it that way, for easy writing to the server. | ||||||||||||||
| 110 | 0 | ▶ | if (!ref($args_data)) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 111 | 0 | ▶ | $args_data = "" if !defined($args_data); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 112 | } elsif (ref($args_data) eq "ARRAY") { | ||||||||||||||
| 113 | 0 | $args_data = join "\n", @$args_data; | |||||||||||||
| 114 | } else { | ||||||||||||||
| 115 | 0 | confess "Wrong type of args_data: " . ref($args_data); | |||||||||||||
| 116 | } | ||||||||||||||
| 117 | |||||||||||||||
| 118 | 0 | my @args_data = split /\n/, $args_data; | |||||||||||||
| 119 | |||||||||||||||
| 120 | # As a hacky way of emulating Argumentx, prepend that string to all but the | ||||||||||||||
| 121 | # first Argument. | ||||||||||||||
| 122 | 0 | ▶ | for (my $i=1; $i < @args_data; $i++) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 123 | 0 | $args_data[$i] = "Argumentx ".$args_data[$i]; | |||||||||||||
| 124 | } | ||||||||||||||
| 125 | 0 | my @args = map { "VCS::LibCVS::Datum::String"->new($_); } @args_data; | |||||||||||||
| 126 | |||||||||||||||
| 127 | 0 | $that->{Args} = \@args; | |||||||||||||
| 128 | |||||||||||||||
| 129 | 0 | return $that; | |||||||||||||
| 130 | } | ||||||||||||||
| 131 | |||||||||||||||
| 132 | ############################################################################### | ||||||||||||||
| 133 | # Instance routines | ||||||||||||||
| 134 | ############################################################################### | ||||||||||||||
| 135 | |||||||||||||||
| 136 | ############################################################################### | ||||||||||||||
| 137 | # Private routines | ||||||||||||||
| 138 | ############################################################################### | ||||||||||||||
| 139 | |||||||||||||||
| 140 | =head1 SEE ALSO | ||||||||||||||
| 141 | |||||||||||||||
| 142 | VCS::LibCVS::Client::Request | ||||||||||||||
| 143 | |||||||||||||||
| 144 | =cut | ||||||||||||||
| 145 | |||||||||||||||
| 146 | 1 | 1; | |||||||||||||