| 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::Datum; | ||||||||||||||
| 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 | 1 | ▶ | use VCS::LibCVS::Datum::DirectoryName; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 14 | 1 | ▶ | use VCS::LibCVS::Datum::Entry; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 15 | 1 | ▶ | use VCS::LibCVS::Datum::FileContents; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 16 | 1 | ▶ | use VCS::LibCVS::Datum::FileMode; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 17 | 1 | ▶ | use VCS::LibCVS::Datum::FileName; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 18 | 1 | ▶ | use VCS::LibCVS::Datum::LogMessage; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 19 | 1 | ▶ | use VCS::LibCVS::Datum::PathName; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 20 | 1 | ▶ | use VCS::LibCVS::Datum::RevisionNumber; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 21 | 1 | ▶ | use VCS::LibCVS::Datum::Root; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 22 | 1 | ▶ | use VCS::LibCVS::Datum::String; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 23 | 1 | ▶ | use VCS::LibCVS::Datum::TagSpec; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 24 | 1 | ▶ | use VCS::LibCVS::Datum::Time; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 25 | |||||||||||||||
| 26 | =head1 NAME | ||||||||||||||
| 27 | |||||||||||||||
| 28 | VCS::LibCVS::Datum - a piece of CVS data | ||||||||||||||
| 29 | |||||||||||||||
| 30 | =head1 SYNOPSIS | ||||||||||||||
| 31 | |||||||||||||||
| 32 | $mode = VCS::LibCVS::Datum::Mode->new("u=rw,g=rw,o=r"); | ||||||||||||||
| 33 | $rq = VCS::LibCVS::Client::Request::Modified->new(["file",$mode,$file]); | ||||||||||||||
| 34 | |||||||||||||||
| 35 | =head1 DESCRIPTION | ||||||||||||||
| 36 | |||||||||||||||
| 37 | Datum represents a single piece of CVS data, such as an entries line, a file | ||||||||||||||
| 38 | mode or a tag spec. It has subclasses for each type of CVS data. Datum should | ||||||||||||||
| 39 | not to be instantiated, instead its subclasses should be instantiated. | ||||||||||||||
| 40 | |||||||||||||||
| 41 | To access the contained data see the accessors for each subclass. | ||||||||||||||
| 42 | |||||||||||||||
| 43 | =cut | ||||||||||||||
| 44 | |||||||||||||||
| 45 | # Datum provides some generic facilities to help the implementation of its | ||||||||||||||
| 46 | # simpler subclasses; those which consist of a predetermined number of lines | ||||||||||||||
| 47 | # which can be named. To use these facilities a subclass of Datum overrides | ||||||||||||||
| 48 | # the _data_names() routine, which returns a list of names used as keys into | ||||||||||||||
| 49 | # the private hash. All the routines defined in Datum use this facility. | ||||||||||||||
| 50 | |||||||||||||||
| 51 | ############################################################################### | ||||||||||||||
| 52 | # Class constants | ||||||||||||||
| 53 | ############################################################################### | ||||||||||||||
| 54 | |||||||||||||||
| 55 | 1 | ▶ | use constant REVISION => '$Header: /cvsroot/libcvs-perl/libcvs-perl/VCS/LibCVS/Datum.pm,v 1.14 2005/10/10 12:52:11 dissent Exp $ '; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 56 | |||||||||||||||
| 57 | ############################################################################### | ||||||||||||||
| 58 | # Private variables | ||||||||||||||
| 59 | ############################################################################### | ||||||||||||||
| 60 | |||||||||||||||
| 61 | # These are specified by _data_names(). | ||||||||||||||
| 62 | # Each of them is a single line of text, without a terminating newline. | ||||||||||||||
| 63 | |||||||||||||||
| 64 | ############################################################################### | ||||||||||||||
| 65 | # Class routines | ||||||||||||||
| 66 | ############################################################################### | ||||||||||||||
| 67 | |||||||||||||||
| 68 | =head1 CLASS ROUTINES | ||||||||||||||
| 69 | |||||||||||||||
| 70 | =head2 B<new()> | ||||||||||||||
| 71 | |||||||||||||||
| 72 | $data = Datum::Subclass->new($data) | ||||||||||||||
| 73 | |||||||||||||||
| 74 | Only call this on subclasses of Datum. Some subclasses override this | ||||||||||||||
| 75 | constructor. | ||||||||||||||
| 76 | |||||||||||||||
| 77 | =over 4 | ||||||||||||||
| 78 | |||||||||||||||
| 79 | =item return type: Datum::Subclass | ||||||||||||||
| 80 | |||||||||||||||
| 81 | =item argument 1 type: . . . | ||||||||||||||
| 82 | |||||||||||||||
| 83 | =over 2 | ||||||||||||||
| 84 | |||||||||||||||
| 85 | =item E<32>E<32>option 1: IO::Handle | ||||||||||||||
| 86 | |||||||||||||||
| 87 | An IO::Handle object from which the Datum will be read. Most Datum are line | ||||||||||||||
| 88 | oriented, so they will read one or more lines from the IO::handle. | ||||||||||||||
| 89 | |||||||||||||||
| 90 | =item E<32>E<32>option 2: scalar | ||||||||||||||
| 91 | |||||||||||||||
| 92 | If the Datum consists of a single line, it can be passed as a scalar. | ||||||||||||||
| 93 | |||||||||||||||
| 94 | =item E<32>E<32>option 3: \@array ref | ||||||||||||||
| 95 | |||||||||||||||
| 96 | If the Datum consists of one or more lines, they can be passed as an array ref. | ||||||||||||||
| 97 | |||||||||||||||
| 98 | =item E<32>E<32>option 4: Datum::Subclass | ||||||||||||||
| 99 | |||||||||||||||
| 100 | If the argument is an object of the type which is being constructed, the | ||||||||||||||
| 101 | argument itself will be returned. It will I<not> be copied. | ||||||||||||||
| 102 | |||||||||||||||
| 103 | This is used by the Client::Request constructor which blindly passes its | ||||||||||||||
| 104 | args to the Datum constructor. That way the user has the freedom to | ||||||||||||||
| 105 | construct their own Datum and pass it to the Client::Request constructor. | ||||||||||||||
| 106 | |||||||||||||||
| 107 | =back | ||||||||||||||
| 108 | |||||||||||||||
| 109 | =back | ||||||||||||||
| 110 | |||||||||||||||
| 111 | Construct a new Datum. The IO::Handle option is used for reading a Datum | ||||||||||||||
| 112 | from the server, the others when constructing it locally. | ||||||||||||||
| 113 | |||||||||||||||
| 114 | =cut | ||||||||||||||
| 115 | |||||||||||||||
| 116 | 0 | ▶ | sub new { | ||||||||||||
|
Subroutine
new: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||
| 117 | 0 | my ($class, $arg_data) = @_; | |||||||||||||
| 118 | |||||||||||||||
| 119 | # if the argument is already an object of the right type, just return it | ||||||||||||||
| 120 | 0 | ▶ | return $arg_data if (UNIVERSAL::isa($arg_data, $class)); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 121 | |||||||||||||||
| 122 | 0 | my $that = bless {}, $class; | |||||||||||||
| 123 | |||||||||||||||
| 124 | # if the argument is an iohandle, read in the right number of lines, and | ||||||||||||||
| 125 | # overwrite $arg_data with that. | ||||||||||||||
| 126 | 0 | ▶ | if (UNIVERSAL::isa($arg_data, "IO::Handle")) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 127 | 0 | my @arg_data = map { $arg_data->getline(); } $that->_data_names(); | |||||||||||||
| 128 | 0 | $arg_data = \@arg_data; | |||||||||||||
| 129 | } | ||||||||||||||
| 130 | |||||||||||||||
| 131 | # a scalar is good if one line is needed, otherwise expect an array ref | ||||||||||||||
| 132 | 0 | ▶ | if (!ref($arg_data)) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 133 | 0 | ▶ | confess "Datum needs multiple lines" if (@{[$that->_data_names]} != 1); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 134 | 0 | $that->_add_line(($that->_data_names)[0], $arg_data); | |||||||||||||
| 135 | |||||||||||||||
| 136 | } elsif (ref($arg_data) eq "ARRAY") { | ||||||||||||||
| 137 | 0 | ▶ | confess "Wrong number of lines" if (@{[$that->_data_names]} != @$arg_data); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 138 | 0 | foreach my $n ($that->_data_names) {$that->_add_line($n, shift @$arg_data)} | |||||||||||||
| 139 | |||||||||||||||
| 140 | } else { | ||||||||||||||
| 141 | 0 | confess "Wrong type for data of Arg:" . ref($arg_data); | |||||||||||||
| 142 | } | ||||||||||||||
| 143 | |||||||||||||||
| 144 | 0 | return $that; | |||||||||||||
| 145 | } | ||||||||||||||
| 146 | |||||||||||||||
| 147 | ############################################################################### | ||||||||||||||
| 148 | # Instance routines | ||||||||||||||
| 149 | ############################################################################### | ||||||||||||||
| 150 | |||||||||||||||
| 151 | =head1 INSTANCE ROUTINES | ||||||||||||||
| 152 | |||||||||||||||
| 153 | =head2 B<as_string()> | ||||||||||||||
| 154 | |||||||||||||||
| 155 | $datum_string = $datum->as_string() | ||||||||||||||
| 156 | |||||||||||||||
| 157 | =over 4 | ||||||||||||||
| 158 | |||||||||||||||
| 159 | =item return type: string scalar | ||||||||||||||
| 160 | |||||||||||||||
| 161 | =back | ||||||||||||||
| 162 | |||||||||||||||
| 163 | Returns the Datum as a string. | ||||||||||||||
| 164 | |||||||||||||||
| 165 | =cut | ||||||||||||||
| 166 | |||||||||||||||
| 167 | 0 | ▶ | sub as_string { | ||||||||||||
|
Subroutine
as_string: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 168 | 0 | my $self = shift; | |||||||||||||
| 169 | 0 | my $as_string = $self->as_protocol_string(); | |||||||||||||
| 170 | 0 | chomp $as_string; | |||||||||||||
| 171 | 0 | return $as_string; | |||||||||||||
| 172 | } | ||||||||||||||
| 173 | |||||||||||||||
| 174 | =head2 B<protocol_print()> | ||||||||||||||
| 175 | |||||||||||||||
| 176 | $datum->protocol_print($file_handle) | ||||||||||||||
| 177 | |||||||||||||||
| 178 | =over 4 | ||||||||||||||
| 179 | |||||||||||||||
| 180 | =item return type: undef | ||||||||||||||
| 181 | |||||||||||||||
| 182 | =item argument 1 type: IO::Handle | ||||||||||||||
| 183 | |||||||||||||||
| 184 | =back | ||||||||||||||
| 185 | |||||||||||||||
| 186 | Prints the Datum to the IO::Handle. The output will be formatted for | ||||||||||||||
| 187 | sending to the cvs server, including the placement of newlines. | ||||||||||||||
| 188 | |||||||||||||||
| 189 | =cut | ||||||||||||||
| 190 | |||||||||||||||
| 191 | 0 | ▶ | sub protocol_print { | ||||||||||||
|
Subroutine
protocol_print: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 192 | 0 | my ($self, $ioh) = @_; | |||||||||||||
| 193 | 0 | $ioh->print($self->as_protocol_string()); | |||||||||||||
| 194 | } | ||||||||||||||
| 195 | |||||||||||||||
| 196 | =head2 B<as_protocol_string()> | ||||||||||||||
| 197 | |||||||||||||||
| 198 | $datum_string = $datum->as_protocol_string() | ||||||||||||||
| 199 | |||||||||||||||
| 200 | =over 4 | ||||||||||||||
| 201 | |||||||||||||||
| 202 | =item return type: string scalar | ||||||||||||||
| 203 | |||||||||||||||
| 204 | =back | ||||||||||||||
| 205 | |||||||||||||||
| 206 | Returns the Datum as a string suitable for being sent to the server, | ||||||||||||||
| 207 | including the placement of newlines. | ||||||||||||||
| 208 | |||||||||||||||
| 209 | =cut | ||||||||||||||
| 210 | |||||||||||||||
| 211 | 0 | ▶ | sub as_protocol_string { | ||||||||||||
|
Subroutine
as_protocol_string: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||
| 212 | 0 | my $self = shift; | |||||||||||||
| 213 | 0 | my $p_string = ""; | |||||||||||||
| 214 | 0 | foreach my $name ($self->_data_names) { $p_string .= $self->{$name} . "\n"; } | |||||||||||||
| 215 | 0 | return $p_string; | |||||||||||||
| 216 | } | ||||||||||||||
| 217 | |||||||||||||||
| 218 | =head2 B<equals()> | ||||||||||||||
| 219 | |||||||||||||||
| 220 | if ($datum1->equals($datum2)) { | ||||||||||||||
| 221 | |||||||||||||||
| 222 | =over 4 | ||||||||||||||
| 223 | |||||||||||||||
| 224 | =item return type: boolean | ||||||||||||||
| 225 | |||||||||||||||
| 226 | =item argument 1 type: VCS::LibCVS::Datum | ||||||||||||||
| 227 | |||||||||||||||
| 228 | =back | ||||||||||||||
| 229 | |||||||||||||||
| 230 | Returns true if the data contain the same information (and are of the same | ||||||||||||||
| 231 | type) | ||||||||||||||
| 232 | |||||||||||||||
| 233 | =cut | ||||||||||||||
| 234 | |||||||||||||||
| 235 | 0 | ▶ | sub equals { | ||||||||||||
|
Subroutine
equals: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||
| 236 | 0 | my $self = shift; | |||||||||||||
| 237 | 0 | my $other = shift; | |||||||||||||
| 238 | 0 | ▶ | return 0 if ref($self) ne ref($other); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 239 | 0 | foreach my $key ($self->_data_names()) { | |||||||||||||
| 240 | 0 | ▶ | return 0 if $self->{$key} ne $other->{$key}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 241 | } | ||||||||||||||
| 242 | 0 | return 1; | |||||||||||||
| 243 | } | ||||||||||||||
| 244 | |||||||||||||||
| 245 | ############################################################################### | ||||||||||||||
| 246 | # Private routines | ||||||||||||||
| 247 | ############################################################################### | ||||||||||||||
| 248 | |||||||||||||||
| 249 | # Returns a list of strings, which are names of the keys in the $self hash | ||||||||||||||
| 250 | # which hold the lines of the Datum. If the Datum is something other than a | ||||||||||||||
| 251 | # list of lines, the empty list will be returned. | ||||||||||||||
| 252 | 0 | ▶ | sub _data_names { | ||||||||||||
|
Subroutine
_data_names: not called CC=1 SCAR=6.9
| |||||||||||||||
| 253 | 0 | return (); | |||||||||||||
| 254 | } | ||||||||||||||
| 255 | |||||||||||||||
| 256 | # Add a single named line to the internal hash, ensuring that it contains no | ||||||||||||||
| 257 | # newlines | ||||||||||||||
| 258 | 0 | ▶ | sub _add_line { | ||||||||||||
|
Subroutine
_add_line: not called CC=2 SCAR=17.9
| |||||||||||||||
| 259 | 0 | my ($self, $name, $line) = @_; | |||||||||||||
| 260 | 0 | chomp($line); | |||||||||||||
| 261 | 0 | ▶ | confess "Embedded newline in Datum line: $name: $line" if $line =~ /\n/; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 262 | 0 | return $self->{$name} = $line; | |||||||||||||
| 263 | } | ||||||||||||||
| 264 | |||||||||||||||
| 265 | =head1 SEE ALSO | ||||||||||||||
| 266 | |||||||||||||||
| 267 | VCS::LibCVS::Datum::DirectoryName | ||||||||||||||
| 268 | VCS::LibCVS::Datum::Entry | ||||||||||||||
| 269 | VCS::LibCVS::Datum::FileContents | ||||||||||||||
| 270 | VCS::LibCVS::Datum::FileMode | ||||||||||||||
| 271 | VCS::LibCVS::Datum::FileName | ||||||||||||||
| 272 | VCS::LibCVS::Datum::PathName | ||||||||||||||
| 273 | VCS::LibCVS::Datum::Root | ||||||||||||||
| 274 | VCS::LibCVS::Datum::String | ||||||||||||||
| 275 | VCS::LibCVS::Datum::TagSpec | ||||||||||||||
| 276 | VCS::LibCVS::Datum::Time | ||||||||||||||
| 277 | |||||||||||||||
| 278 | =cut | ||||||||||||||
| 279 | |||||||||||||||
| 280 | 1 | 1; | |||||||||||||