File Coverage

blib/lib/VCS/PVCS.pm
Criterion Covered Total %
statement 9 76 11.8
branch 0 30 0.0
condition 0 3 0.0
subroutine 3 9 33.3
pod n/a
total 12 118 10.1


line stmt bran cond sub pod time code
1             # PVCS.pm - super class for VCS::PVCS::Project
2             #
3             # Copyright (c) 1998 Bill Middleton
4             #
5             #
6              
7             require 5.003;
8             $VERSION = "0.01";
9              
10             =head1 NAME
11              
12             VCS::PVCS - Global configuration class for for VCS::PVCS::*.
13              
14             =head1 SYNOPSIS
15              
16             use VCS::PVCS::Project; # preferred
17             $project = new VCS::PVCS::Project("ProjectName");
18              
19             =head1 DESCRIPTION
20              
21             The VCS::PVCS class simply parses the PVCS global configuration files,
22             including pvcsproj.pub and MASTER.CFG, found in PVCSPROJ.
23             The resulting object is then included in the VCS::PVCS::Project
24             object as it's "CONFIG". The class members are used at various
25             times in other subclasses, as needed.
26              
27             NOTE: This module may require some configuration. If your
28             scripts wont run, you may need to hardwire some of the global
29             parameters, including $ISLVINI, $PVCSPROJ, $NFSMAP, $PVCS_BINDIR and
30             possibly others. You should inspect the module before installing
31             it, to verify the settings will work.
32              
33             This module also exports several GLOBAL variables, which are
34             used in various places throughout it's children, and can be
35             used in scripts which load the B class.
36             These variables include, but may not always be limited to:
37              
38             =over 5
39              
40             =item B<$PVCSERR>
41              
42             PVCSERR is set to the current value of B<$?> after each command.
43              
44             =item B<$PVCSDEBUG>
45              
46             PVCSDEBUG can be turned on to see copious (sometimes useful) debugging
47             output as the module is configuring itself, and running.
48              
49             =item B<$PVCSOUTPUT>
50              
51             PVCSOUTPUT is all of the output from the current method, when it
52             executes a pvcs command. If the command was executed on a folder
53             or project-wide basis, then PVCSOUTPUT contains ALL of the output
54             for all archives.
55              
56             =item B<$PVCSCURROUTPUT>
57              
58             PVCSCURROUTPUT is ONLY the output for the most recent command sent
59             to the shell.
60              
61             =item B<$PVCSSHOWMODE>
62              
63             PVCSSHOWMODE is turned on to see, and not execute, commands.
64              
65             =item B<$PVCS_BINDIR>
66              
67             PVCS_BINDIR is set in the environment or in VCS::PVCS.pm to be
68             the location of the PVCS binaries, B, B, B, B,
69             B, etc.
70              
71             =item B<$PVCSMASTERCFG>
72              
73             PVCSMASTERCFG is the path to the master configuration file. This
74             variable is not exported to the world through VCS::PVCS::Project,
75             but only intended for internal use.
76              
77             =item B<$PVCSCURRPROJCFG>
78              
79             PVCSCURRPROJCFG is the location of the current projects' Config file.
80             This variable is not exported to the world through VCS::PVCS::Project,
81             but only intended for internal use.
82              
83             =item B<$PVCSMULTIPLATFORM>
84              
85             PVCSMULTIPLATFORM tells the modules whether to make certain path
86             translations when operating on something other than WIN. Turn
87             this on if you are using PVCS in a multiplatform environment.
88              
89             B
90              
91             =item B<$PVCSPROJ>
92              
93             PVCSPROJ is the base directory for all PVCS control files.
94              
95             =back
96              
97             Ordinarily, this class wont be used directly. Rather, it
98             is in the @ISA for VCS::PVCS::Project. When creating a new
99             VCS::PVCS::Project object, this module's new() method is
100             invoked automatically.
101              
102             =head1 AUTHOR
103              
104             Bill Middleton, wjm@metronet.com
105              
106             =head1 COPYRIGHT
107              
108             The PVCS module is Copyright (c) 1998 Bill Middleton.
109             All rights reserved.
110              
111             You may distribute under the terms of either the GNU General Public
112             License or the Artistic License, as specified in the Perl README file.
113              
114             =head1 SUPPORT / WARRANTY
115              
116             The VCS::PVCS modules are free software.
117              
118             B
119              
120             Commercial support agreements for Perl can be arranged via
121             The Perl Clinic. See http://www.perl.co.uk/tpc for more details.
122              
123             =head1 SEE ALSO
124              
125             perl(1), VCS::PVCS::Project
126              
127             =cut
128              
129             package VCS::PVCS;
130 4     4   1064 use strict;
  4         7  
  4         132  
131 4     4   20 use Carp;
  4         8  
  4         394  
132             require Exporter;
133 4         9519 use vars qw($PVCSDEBUG $USESQL @ISA @EXPORT $VERSION $PVCSPROJ $PVCSDONTSAVE
134             $PVCSPRIV $NFSMAP $PVCSERR $PVCSOUTPUT $PVCSCURROUTPUT $ISLVINI $PVCS_BINDIR
135 4     4   29 $PVCSMASTERCFG $PVCSSHOWMODE $PVCSCURRPROJCFG %NFSMAP $PVCSMULTIPLATFORM);
  4         6  
136             @ISA = qw(Exporter);
137             @EXPORT = qw(translatePath2Win translatePath2Unix );
138             $VERSION = "0.01";
139             $PVCSDEBUG= 0;
140             $PVCSSHOWMODE = 0;
141              
142              
143             ####################################################################
144             # Configuration Defaults extracted from ISLVINI
145             ####################################################################
146              
147             $USESQL =0;
148             $PVCSDEBUG = 0; # Set this to get debug output for all PVCS modules
149              
150             $PVCSDONTSAVE = 1; # Save config files when VCSDIR changes.
151             # change this if you dont use conditional directives
152             # in your config files for pvcs
153             if($ENV{'ISLVINI'}){
154             $ISLVINI = $ENV{'ISLVINI'};
155             }
156             elsif($^O eq "MSWin32"){
157             if(-e "$ENV{'WINDIR'}/islv.ini"){
158             $ISLVINI = $ENV{'WINDIR'}.'/islv.ini';
159             }
160             }
161             elsif(-e "$ENV{'HOME'}/.islvrc"){
162             $ISLVINI = $ENV{'HOME'}.'/.islvrc';
163             }
164             else{
165             print "$ENV{'HOME'}/.islvrc\n";
166             croak "Cannot find the ISLVINI file\n";
167             }
168              
169             # Better change these!
170              
171             if($ENV{'PVCS_BINDIR'}){
172             $PVCS_BINDIR = $ENV{'PVCS_BINDIR'};
173             if(! ((-e "$PVCS_BINDIR/vcs") or (-e "$PVCS_BINDIR/vcs.exe"))){
174             croak "Cant find PVCS Binaries. Set PVCS_BINDIR in PVCS.pm or ENV.\n";
175             }
176             }
177             elsif($^O eq "MSWin32"){ # There is probably a better way to do this on WIN
178             $PVCS_BINDIR = "N:\\pvcs6.0\\nt";
179             if(! (-e "$PVCS_BINDIR/vcs.exe")){
180             croak "Cant find PVCS Binaries. Set PVCS_BINDIR in PVCS.pm or ENV.\n";
181             }
182             $ENV{'PVCS_BINDIR'} = $PVCS_BINDIR;
183             }
184             else{ # unix
185             $PVCS_BINDIR = "/usr/pvcs";
186             if(! (-e "$PVCS_BINDIR/vcs")){
187             croak "Cant find PVCS Binaries. Set PVCS_BINDIR in PVCS.pm or ENV.\n";
188             }
189             $ENV{'PVCS_BINDIR'} = $PVCS_BINDIR;
190             }
191             $PVCSERR = $PVCSOUTPUT= $PVCSCURROUTPUT = $PVCSPROJ = "";
192             $PVCSMULTIPLATFORM = 0; # Assume were in a heterogeneous environment
193             # unless we find an nfsmap
194              
195             push(@EXPORT,"\$PVCSERR");
196             push(@EXPORT,"\$PVCSDEBUG");
197             push(@EXPORT,"\$PVCSOUTPUT");
198             push(@EXPORT,"\$PVCSCURROUTPUT");
199             push(@EXPORT,"\$PVCSSHOWMODE");
200             push(@EXPORT,"\$PVCS_BINDIR");
201             push(@EXPORT,"\$PVCSMASTERCFG");
202             push(@EXPORT,"\$PVCSCURRPROJCFG");
203             push(@EXPORT,"\$PVCSMULTIPLATFORM");
204             push(@EXPORT,"\$PVCSPROJ");
205              
206             ####################################################################
207             sub new{
208 0     0     my $proto = shift;
209 0           my $self = {};
210 0 0         open(ISLVINI,$ISLVINI) || croak "Cant open ISLVINI: $ISLVINI\n";
211 0           while(){
212 0           chomp;
213 0 0         next unless (/^(PVCSPROJ|PVCSPRIV|NFSMAP)=(.*)/);
214 0           eval "\${$1}= \$2";
215             }
216 0 0 0       (croak "Your PVCSPROJ AND PVCSPRIV directories are not defined in $ISLVINI\n")
217             unless (length($PVCSPROJ) && length($PVCSPRIV));
218              
219 0           readMasterProjFile($self);
220 0 0         if(-e "$PVCSPROJ/MASTER.CFG"){ # Um, you may need to change this too.
221 0           $PVCSMASTERCFG = "$PVCSPROJ/MASTER.CFG";
222 0           readMasterConfigFile($self);
223             }
224             else{
225 0           croak "No MASTER.CFG config file found in $PVCSPROJ\n";
226             }
227 0 0         if(-e "$NFSMAP/nfsmap"){
228 0           readNFSMap($self);
229             }
230 0           bless($self,"VCS::PVCS");
231             }
232              
233             sub readMasterConfigFile{
234 0     0     my($self) = shift;
235 0           my($key,$value)=();
236 0           my(@tmp);
237             # Eventually, this'll be replaced with API call
238             # Right now the only thing we're interested in is VCSDIR,
239             # since the command line tools will read them for themselves.
240              
241 0 0         (croak "Cant find your Master Config file, $PVCSMASTERCFG")
242             unless (-e "$PVCSMASTERCFG");
243 0 0         open(MASTER, "$PVCSMASTERCFG") ||
244             croak "cant open $PVCSMASTERCFG";
245 0           while(){
246 0           chop;chop; # icky but ok
  0            
247 0           ($key,$value) = split(/\s+[= ]+\s*/,$_);
248 0 0         next unless (defined($key));
249 0 0         next unless ($key =~ s/.*(VCSDIR).*/$1/);
250 0           $value =~s/^\s*\"//;
251 0           $value =~s/\"\s*$//;
252 0           @{$self->{'VCSDIR'}} = split(/\"\;\"/,$value);
  0            
253 0           last;
254             }
255             }
256              
257              
258             sub readMasterProjFile{
259 0     0     my($self) = shift;
260 0           my($nextline,$project);
261 0 0         (croak "Cant find your Master Project file, $PVCSPROJ/pvcsproj.pub")
262             unless (-e "$PVCSPROJ/pvcsproj.pub");
263 0 0         open(MASTER, $PVCSPROJ."/pvcsproj.pub") || croak "cant open ";
264 0           while(){
265 0           chomp;
266 0 0         next unless (/^\[Project=(.*)\]/);
267 0           $project = $1;
268 0           for(1 .. 4){
269 0           chomp($nextline = scalar());
270 0           $nextline =~ /^(CFG|DIR|ARDIR|WKDIR)=([^\015]*)/;
271 0           $self->{'projects'}->{$project}->{$1} = $2;
272             }
273 0           $self->{'projects'}->{$project}->{'NAME'} = $project;
274             }
275             }
276              
277             sub readNFSMap{
278 0     0     my($self) = shift;
279 0           my($key,$value);
280 0           open(MASTER,"$NFSMAP/nfsmap");
281 0           $PVCSMULTIPLATFORM = 1;
282 0           while(){
283 0           chomp;
284 0 0         next if /^[\s#]/;
285 0           ($key,$value) = split(' ',$_);
286 0           $NFSMAP{$key} = $value;
287             }
288             }
289              
290             sub translatePath2Unix{
291 0     0     my($pathref) = shift;
292 0           my($key,$path);
293 0           foreach $key (keys %NFSMAP){
294 0 0         if($$pathref =~ s#$key:\\#$NFSMAP{$key}/#){
295 0           last;
296             }
297             }
298 0           $$pathref =~ s/\\/\//g;
299             }
300              
301             sub translatePath2Win{
302 0     0     my($pathref) = shift;
303 0           my($key,$value,$path);
304 0           foreach $key (keys %NFSMAP){
305 0           $value = $NFSMAP{$key};
306 0 0         if($$pathref =~ s#$value/#$key:\\#){
307 0           last;
308             }
309             }
310 0           $$pathref =~ s/\//\\/g;
311             }
312              
313              
314             1;
315             __END__