File Coverage

blib/lib/Clearcase.pm
Criterion Covered Total %
statement 50 196 25.5
branch 12 98 12.2
condition 4 16 25.0
subroutine 13 36 36.1
pod 25 27 92.5
total 104 373 27.8


line stmt bran cond sub pod time code
1             package Clearcase;
2              
3 7     7   1833777 use strict;
  7         16  
  7         308  
4 7     7   81 use warnings;
  7         15  
  7         889  
5              
6             our $VERSION = '1.02';
7              
8             =pod
9              
10             =head1 NAME
11              
12             Clearcase - Object oriented interface to Clearcase.
13              
14             =head1 VERSION
15              
16             =over
17              
18             =item Author
19              
20             Andrew DeFaria
21              
22             =item Revision
23              
24             $Revision: 1.43 $
25              
26             =item Created
27              
28             Tue Dec 4 17:33:43 MST 2007
29              
30             =item Modified
31              
32             $Date: 2011/11/16 18:27:37 $
33              
34             =back
35              
36             =head1 SYNOPSIS
37              
38             Provides access to global Clearcase information in an object oriented manner as
39             well as an interface to cleartool.
40              
41             # Access some compile time global settings:
42             print "View Drive: $Clearcase::VIEW_DRIVE" . "\n";
43             print "Vob Tag Prefix: $Clearcase::VOBTAG_PREFIX" . "\n";
44              
45             # Access some run time global information through the default object
46             print "Client: $Clearcase::CC->client" . "\n";
47             print "Region: $Clearcase::CC->region" . "\n";
48             print "Registry host: $Clearcase::CC->registry_host" . "\n";
49              
50             # List all vobs using execute method of the default object";
51             my ($status, @vobs) = $Clearcase::CC->execute ("lsvob -s");
52              
53             print $_ foreach (@vobs) if $status == 0 . "\n";
54              
55             =head1 DESCRIPTION
56              
57             This module, and others below the Clearcase directory, implement an object
58             oriented approach to Clearcase. In general Clearcase entities are made into
59             objects that can be manipulated easily in Perl. This module is the main or
60             global module. Contained herein are members and methods of a general or global
61             nature. Also contained here is an IPC interface to cleartool such that cleartool
62             runs in the background and commands are fed to it via the execute method. When
63             making repeated calls to cleartool this can result in a substantial savings of
64             time as most operating systems' fork/execute sequence is time consuming. Factors
65             of 8 fold improvement have been measured.
66              
67             Additionally a global variable, $CC, is implemented from this module such that
68             you should not need to instantiate another one, though you could.
69              
70             =head1 ROUTINES
71              
72             The following routines are exported:
73              
74             =cut
75              
76 7     7   104 use base 'Exporter';
  7         15  
  7         1189  
77              
78 7     7   60 use Carp;
  7         11  
  7         682  
79              
80 7     7   4103 use IPC::Open3;
  7         41263  
  7         1210  
81              
82             my ($clearpid, $clearin, $clearout, $oldHandler, $cleartool);
83              
84             # Inline OSDep constants
85             my ($ARCHITECTURE, $SEPARATOR);
86              
87             BEGIN {
88 7 50   7   70 $ARCHITECTURE = $^O =~ /MSWin/ ? 'windows' : $^O =~ /cygwin/ ? 'cygwin' : $^O;
    50          
89 7 50       2572 $SEPARATOR = $^O =~ /MSWin/ ? '\\' : '/';
90             }
91              
92             our $VIEW_DRIVE = 'M';
93             our $VOB_MOUNT = 'vob';
94             our $WIN_VOB_PREFIX = '\\';
95             our $SFX = $ENV{CLEARCASE_XN_SFX} ? $ENV{CLEARCASE_XN_SFX} : '@@';
96              
97             our $VOBTAG_PREFIX =
98             ($ARCHITECTURE eq 'windows' or $ARCHITECTURE eq 'cygwin')
99             ? $WIN_VOB_PREFIX
100             : "/$VOB_MOUNT";
101             our $VIEWTAG_PREFIX =
102             ($ARCHITECTURE eq 'windows' or $ARCHITECTURE eq 'cygwin')
103             ? "$VIEW_DRIVE:"
104             : "${SEPARATOR}view";
105              
106             our ($CCHOME, $COUNTDB);
107              
108             our $CC;
109              
110             our @EXPORT_OK = qw (
111             $CC
112             $CCHOME
113             $COUNTDB
114             $SFX
115             $VIEW_DRIVE
116             $VIEWTAG_PREFIX
117             $VOB_MOUNT
118             $VOBTAG_PREFIX
119             $WIN_VOB_PREFIX
120             );
121              
122             # Replacement for Display
123 0     0 0 0 sub display {print "@_\n"; return;}
  0         0  
124 0     0 0 0 sub error {die "ERROR: @_\n";}
125              
126             BEGIN {
127             # Find executables that we rely on
128 7 50 33 7   90 if ($ARCHITECTURE eq 'windows' or $ARCHITECTURE eq 'cygwin') {
129              
130             # Should really go to the registry for this...
131              
132             # We can go to the registry pretty easy in Cygwin but I'm not sure how to do
133             # that in plain old Windows. Most people either have Clearcase installed on
134             # the C drive or commonly on the D drive on servers. So we'll look at both.
135 0         0 $CCHOME = 'C:\\IBMRational\\RationalSDLC\\Clearcase';
136              
137 0 0       0 $CCHOME = 'D:\\IBMRational\\RationalSDLC\\Clearcase'
138             unless -d $CCHOME;
139              
140 0 0       0 error 'Unable to figure out where Clearcase is installed', 1
141             unless -d $CCHOME;
142              
143 0         0 $COUNTDB = "$CCHOME\\etc\\utils\\countdb.exe";
144             } else {
145 7         23 $CCHOME = '/opt/rational/clearcase';
146 7         10447 $COUNTDB = "$CCHOME/etc/utils/countdb";
147             } # if
148              
149             #error "Unable to find countdb ($COUNTDB)", 2
150             #if ! -f $COUNTDB;
151             } # BEGIN
152              
153             sub DESTROY {
154 3     3   10755 my $exitStatus = $?;
155              
156 3 50       21 if ($clearpid) {
157              
158             # Exit cleartool process
159 0         0 print $clearin "exit\n";
160              
161 0         0 waitpid $clearpid, 0;
162             } # if
163              
164 3         16 local $? = $exitStatus;
165              
166             # Call old signal handler (if any)
167 3 50       15 &$oldHandler if $oldHandler;
168              
169 3         207 return;
170             } # DESTROY
171              
172             # Save old interrupt handler
173             $oldHandler = $SIG{INT};
174              
175             # Set interrupt handler
176             local $SIG{INT} = \&Clearcase::DESTROY;
177              
178             =pod
179              
180             =head2 formatOpts (%opts)
181              
182             Format a hash of options into a string
183              
184             Parameters:
185              
186             =for html
187              
188             =over
189              
190             =item %opts
191              
192             Hash of options
193              
194             =back
195              
196             =for html
197              
198             Returns:
199              
200             =for html
201              
202             =over
203              
204             =item $opts
205              
206             String of formatted options
207              
208             =back
209              
210             =for html
211              
212             =cut
213              
214             =pod
215              
216             =head2 formatOpts (%opts)
217              
218             Format a hash of options into a string
219              
220             Parameters:
221              
222             =for html
223              
224             =over
225              
226             =item %opts
227              
228             Hash of options
229              
230             =back
231              
232             =for html
233              
234             Returns:
235              
236             =for html
237              
238             =over
239              
240             =item $opts
241              
242             String of formatted options
243              
244             =back
245              
246             =for html
247              
248             =cut
249              
250             sub formatOpts {
251 0     0 1 0 my (%opts) = @_;
252              
253 0         0 my $opts = '';
254              
255 0         0 foreach (keys %opts) {
256 0         0 $opts .= "$_ ";
257             $opts .= "$opts{$_} "
258 0 0       0 if $opts{$_} ne '';
259             } # foreach
260              
261 0         0 return $opts;
262             } # formatOpts
263              
264             =pod
265              
266             =head2 setComment ($comment)
267              
268             Format a comment string for cleartool or return -nc
269              
270             Parameters:
271              
272             =for html
273              
274             =over
275              
276             =item $comment
277              
278             The comment string
279              
280             =back
281              
282             =for html
283              
284             Returns:
285              
286             =for html
287              
288             =over
289              
290             =item $comment_opt
291              
292             Formatted comment option (e.g. -c "foo" or -nc)
293              
294             =back
295              
296             =for html
297              
298             =cut
299              
300             =pod
301              
302             =head2 setComment ($comment)
303              
304             Format a comment string for cleartool or return -nc
305              
306             Parameters:
307              
308             =for html
309              
310             =over
311              
312             =item $comment
313              
314             The comment string
315              
316             =back
317              
318             =for html
319              
320             Returns:
321              
322             =for html
323              
324             =over
325              
326             =item $comment_opt
327              
328             Formatted comment option (e.g. -c "foo" or -nc)
329              
330             =back
331              
332             =for html
333              
334             =cut
335              
336             sub setComment ($) {
337 0     0 1 0 my ($comment) = @_;
338              
339 0 0       0 return !$comment ? '-nc' : '-c "' . quotemeta $comment . '"';
340             } # setComment
341              
342             sub vobname ($) {
343 0     0 1 0 my ($tag) = @_;
344              
345             =pod
346              
347             =head2 vobname ($tag)
348              
349             Given a vob tag, return the vob name by stripping of the VOBTAG_PREFIX properly
350             such that you return just the unique vob name. This is tricky because Windows
351             uses '\' as a VOBTAG_PREFIX. With '\' in there regex's like
352             /$Clearcase::VOBTAG_PREFIX(.+)/ to capture the vob's name minus the
353             VOBTAG_PREFIX fail because Perl evaluates this as just a single '\', which
354             escapes the '(' of the '(.+)'!
355              
356             Parameters:
357              
358             =for html
359              
360             =over
361              
362             =over
363              
364             =item $tag
365              
366             Vob tag to convert
367              
368             =back
369              
370             =back
371              
372             =for html
373              
374             Returns:
375              
376             =for html
377              
378             =over
379              
380             =over
381              
382             =item $name
383              
384             The unique part of the vob name
385              
386             =back
387              
388             =back
389              
390             =for html
391              
392             =cut
393              
394 0         0 my $name = $tag;
395              
396             # Special code because Windows $VOBTAG prefix (a \) is such a pain!
397 0 0       0 if (substr ($tag, 0, 1) eq '\\') {
    0          
398 0         0 $name = substr $tag, 1;
399             } elsif (substr ($tag, 0, 1) eq '/') {
400 0 0       0 if ($tag =~ /${Clearcase::VOBTAG_PREFIX}\/(.+)/) {
401 0         0 $name = $1;
402             } # if
403             } # if
404              
405 0         0 return $name;
406             } # vobname
407              
408             sub vobtag ($) {
409 0     0 1 0 my ($name) = @_;
410              
411             =pod
412              
413             =head2 vobtag ($name)
414              
415             Given a vob name, add the VOBTAG_PREFIX based on the current OS.
416              
417             Parameters:
418              
419             =for html
420              
421             =over
422              
423             =over
424              
425             =item $name
426              
427             Vob name to convert
428              
429             =back
430              
431             =back
432              
433             =for html
434              
435             Returns:
436              
437             =for html
438              
439             =over
440              
441             =over
442              
443             =item $tag
444              
445             Vob tag
446              
447             =back
448              
449             =back
450              
451             =for html
452              
453             =cut
454              
455             # If the $VOBTAG_PREFIX is already there then do nothing
456 0 0       0 if (substr ($name, 0, length $VOBTAG_PREFIX) eq $VOBTAG_PREFIX) {
457 0         0 return $name;
458             } else {
459 0         0 return "$VOBTAG_PREFIX$name";
460             } # if
461             } # vobtag
462              
463             sub attributes ($$;%) {
464              
465             # TODO: Need to handle other options too
466 0     0 1 0 my ($self, $type, $name, %newAttribs) = @_;
467              
468             =pod
469              
470             =head2 attributes ($type, $name)
471              
472             Get any attributes attached to the $type:$name
473              
474             Parameters:
475              
476             =for html
477              
478             =over
479              
480             =over
481              
482             =item $type
483              
484             Type of object to look for attributes. For example, activity, baseline, etc.
485              
486             =item $name
487              
488             Object name to look for attributes.
489              
490             =back
491              
492             =back
493              
494             =for html
495              
496             Returns:
497              
498             =for html
499              
500             =over
501              
502             =over
503              
504             =item %attributes
505              
506             Hash of attribute name/values
507              
508             =back
509              
510             =back
511              
512             =for html
513              
514             =cut
515              
516 0         0 my $cmd = "describe -fmt \"%Na\" $type:$name";
517              
518 0         0 my ($status, @output) = $CC->execute ($cmd);
519              
520 0 0       0 return if $status;
521              
522 0         0 my %attributes;
523              
524 0 0       0 if ($output[0]) {
525              
526             # Parse output
527 0         0 my $attributes = $output[0];
528 0         0 my $attr_name;
529              
530 0         0 while ($attributes ne '') {
531 0 0       0 if ($attributes =~ /^=(\"*)(.*)/) {
    0          
532 0 0       0 if ($2 =~ /(.*?)$1(\s|$)(.*)/) {
533 0         0 $attributes{$attr_name} = $1;
534 0         0 $attributes = $3;
535             } else {
536 0         0 $attributes{$attr_name} = $2;
537 0         0 $attributes = '';
538             } # if
539             } elsif ($attributes =~ /^(\w+)=(.*)/) {
540 0         0 $attr_name = $1;
541 0         0 $attributes = "=$2";
542             } else {
543 0         0 croak "Parsing error while parsing " . ref ($self) . " attributes";
544             } # if
545             } # while
546             } # if
547              
548             # Set any %newAttribs
549 0         0 foreach (keys %newAttribs) {
550              
551             # TODO: What about other options like -comment?
552 0         0 $cmd = "mkattr -replace -nc $_ \"";
553 0         0 $cmd .= quotemeta $newAttribs{$_};
554 0         0 $cmd .= "\" $type:$name";
555              
556 0         0 $CC->execute ($cmd);
557              
558 0 0       0 if ($CC->status) {
559 0         0 croak "Unable to execute $cmd (Status: "
560             . $CC->status . ")\n"
561             . join ("\n", $CC->output);
562             } else {
563 0         0 $attributes{$_} = $newAttribs{$_};
564             } # if
565             } # foreach
566              
567 0         0 return %attributes;
568             } # attributes
569              
570             sub status () {
571 0     0 1 0 my ($self) = @_;
572              
573             =pod
574              
575             =head2 status ()
576              
577             Returns the status of the last executed command.
578              
579             Parameters:
580              
581             =for html
582              
583             =over
584              
585             =over
586              
587             =item none
588              
589             =back
590              
591             =back
592              
593             =for html
594              
595             Returns:
596              
597             =for html
598              
599             =over
600              
601             =over
602              
603             =item $status
604              
605             Status of the command last executed.
606              
607             =back
608              
609             =back
610              
611             =for html
612              
613             =cut
614              
615 0         0 return $self->{status};
616             } # status
617              
618             sub output () {
619 0     0 1 0 my ($self) = @_;
620              
621             =pod
622              
623             =head2 output ()
624              
625             Returns the output of the last executed command.
626              
627             Parameters:
628              
629             =for html
630              
631             =over
632              
633             =over
634              
635             =item none
636              
637             =back
638              
639             =back
640              
641             =for html
642              
643             Returns:
644              
645             =for html
646              
647             =over
648              
649             =over
650              
651             =item @output or $output
652              
653             If called in a list context, returns @output, otherwise returns $output.
654              
655             =back
656              
657             =back
658              
659             =for html
660              
661             =cut
662              
663 0 0       0 if (wantarray) {
664 0         0 return split /\n/, $self->{output};
665             } else {
666 0         0 return $self->{output};
667             } # if
668             } # output
669              
670             # TODO: Should implement a pipe call that essentially does a cleartool command
671             # to a pipe allowing the user to read from the pipe. This will help with such
672             # cleartool command that may give back huge output or where the user wishes to
673             # start processing the output as it comes instead of waiting until the cleartool
674             # command is completely finished. Would like to do something like execute does
675             # with cleartool running in the background but we need to handle the buffering
676             # of output sending only whole lines.
677              
678             sub execute {
679 7     7 1 23 my ($self, $cmd) = @_;
680              
681             =pod
682              
683             =head2 execute ($cmd)
684              
685             Sends a command to the cleartool coprocess. If not running a cleartool coprocess
686             is started and managed. The coprocess is implemented as a coprocess using IPC
687             for communication that will exist until the object is destroyed. Stdin and
688             stdout/stderr are therefore pipes and can be fed. The execute method feeds the
689             input pipe and returns status and output from the output pipe.
690              
691             Using execute can speed up execution of repeative cleartool invocations
692             substantially.
693              
694             Parameters:
695              
696             =for html
697              
698             =over
699              
700             =over
701              
702             =item $cmd
703              
704             Cleartool command to execute.
705              
706             =back
707              
708             =back
709              
710             =for html
711              
712             Returns:
713              
714             =for html
715              
716             =over
717              
718             =over
719              
720             =item $status
721              
722             Status of the command last executed.
723              
724             =item @output
725              
726             Array of output lines from the cleartool command execution.
727              
728             =back
729              
730             =back
731              
732             =for html
733              
734             =cut
735              
736 7         15 my ($status, @output);
737              
738             # This seems to be how most people locate cleartool. On Windows (this
739             # includes Cygwin) we assume it's in our path. On Unix/Linux we assume it's
740             # installed under /opt/rational/clearcase/bin. This is needed in case we wish
741             # to use these Clearcase objects say in a web page where the server is often
742             # run as a plain user who does not have cleartool in their path.
743 7 50       30 unless ($cleartool) {
744 7 50 33     369 if ($ARCHITECTURE =~ /Win/ or $ARCHITECTURE eq 'cygwin') {
    50          
745 0         0 $cleartool = 'cleartool';
746             } elsif (-x '/opt/rational/clearcase/bin/cleartool') {
747 0         0 $cleartool = '/opt/rational/clearcase/bin/cleartool';
748             } # if
749             } # unless
750              
751 7   50     57 $cleartool ||= 'cleartool';
752              
753             # TODO: Need to catch SIGCHILD here in case the user does something like hit
754             # Ctrl-C. Such an action may interrupt the underlying cleartool process and
755             # kill it. But we would be unaware (i.e. $clearpid would still be set). So
756             # when SIGCHILD is caught we need to undef $clearpid.
757 7 50       32 if (!$clearpid) {
758              
759             # Simple check to see if we can execute cleartool
760 7         15 eval {
761 7     7   67 no warnings 'exec';
  7         35  
  7         15256  
762 7         55089 @output = `$cleartool -ver 2>&1`;
763             };
764              
765 7 50 33     519 if ($@ or $? != 0) {
766 7         152 @output = ();
767 7         2337 warn "Warning: Clearcase not found on this system\n";
768 7         222 return (-1, 'Clearcase not installed');
769             } # if
770              
771 0         0 @output = ();
772              
773 0         0 $clearpid = open3 ($clearin, $clearout, $clearout, $cleartool, "-status");
774              
775 0 0       0 return (-1, ('Clearcase not installed')) unless $clearpid;
776             } # if
777              
778             # Execute command
779 0         0 print $clearin "$cmd\n";
780              
781             # Now read output from $clearout and format the lines in to an array. Also
782             # capture the status code to return it.
783 0         0 while (my $line = <$clearout>) {
784 0 0       0 if ($line !~ /(.*)Command \d+ returned status (\d+)/sm) {
785 0         0 push @output, $line;
786             } else {
787 0         0 push @output, $1;
788 0         0 $status = $2;
789 0         0 last;
790             } # if
791             } # while
792              
793 0 0       0 if (@output) {
794 0         0 chomp @output;
795 0 0       0 chop @output if $output[0] =~ /\r$/;
796             } # if
797              
798             # We're getting extra blank lines at the bottom of @output. Not sure why
799             # but we need to remove it
800             pop @output
801 0 0 0     0 if @output and $output[-1] eq '';
802              
803 0         0 $self->{lastcmd} = 'cleartool ' . $cmd;
804 0         0 $self->{status} = $status;
805 0         0 $self->{output} = join "\n", @output;
806              
807 0         0 return ($status, @output);
808             } # execute
809              
810             sub lastcmd() {
811 0     0 1 0 my ($self) = @_;
812              
813             =pod
814              
815             =head2 lastcmd()
816              
817             Return last command attempted by execute
818              
819             Parameters:
820              
821             =for html
822              
823             =over
824              
825             =item none
826              
827             =back
828              
829             =for html
830              
831             Returns:
832              
833             =for html
834              
835             =over
836              
837             =item Last command attempted by execute
838              
839             =back
840              
841             =for html
842              
843             =cut
844              
845 0   0     0 $self->{lastcmd} ||= '';
846              
847 0         0 return $self->{lastcmd};
848             } # lastcmd
849              
850             sub new {
851 7     7 1 18 my ($class) = @_;
852              
853             =pod
854              
855             =head2 new ()
856              
857             Construct a new Clearcase object. Note there is already a default
858             Clearcase object created named $cc. You should use that unless you
859             have good reason to instantiate another Clearcase object.
860              
861             Parameters:
862              
863             =for html
864              
865             =over
866              
867             =item none
868              
869             =back
870              
871             =for html
872              
873             Returns:
874              
875             =for html
876              
877             =over
878              
879             =item Clearcase object
880              
881             =back
882              
883             =for html
884              
885             =cut
886              
887             # Attributes
888 7         14 my ($registry_host, $version, @regions,);
889              
890 7         48 my $self = bless {
891             registry_host => $registry_host,
892             version => $version,
893             verbose_level => 0,
894             vobtag_prefix => $VOBTAG_PREFIX,
895             viewtag_prefix => $VIEWTAG_PREFIX,
896             regions => \@regions,
897             }, $class;
898              
899             # Get list of regions
900 7         15 my ($status, @output);
901              
902 7         24 ($status, @regions) = $self->execute ('lsregion');
903              
904 7 50       147 return $self
905             if $status;
906              
907             # Get hostinfo attributes
908 0         0 ($status, @output) = $self->execute ('hostinfo -long');
909              
910 0 0       0 return $self
911             if $status;
912              
913 0         0 foreach (@output) {
914 0 0       0 if (/Client: (.*)/) {
    0          
    0          
    0          
    0          
    0          
    0          
915 0         0 $self->{client} = lc $1;
916             } elsif (/Product: (.*)/) {
917 0         0 $self->{version} = $1;
918             } elsif (/Operating system: (.*)/) {
919 0         0 $self->{os} = $1;
920             } elsif (/Hardware type: (.*)/) {
921 0         0 $self->{hardware_type} = $1;
922             } elsif (/Registry host: (.*)/) {
923 0         0 $self->{registry_host} = $1;
924             } elsif (/Registry region: (.*)/) {
925 0         0 $self->{region} = $1;
926 0         0 $self->{sitename} = $1;
927              
928 0 0       0 if ($self->{region} =~ /(\S*)(NT|UNIX)$/) {
929 0         0 $self->{sitename} = $1;
930             } # if
931             } elsif (/License host: (.*)/) {
932 0         0 $self->{license_host} = $1;
933             } # if
934             } # foreach
935              
936 0         0 return $self;
937             } # new
938              
939             # Member access methods...
940              
941             sub client {
942 1     1 1 4 my ($self) = @_;
943              
944             =pod
945              
946             =head2 client
947              
948             Returns the client
949              
950             Parameters:
951              
952             =for html
953              
954             =over
955              
956             =item none
957              
958             =back
959              
960             =for html
961              
962             Returns:
963              
964             =for html
965              
966             =over
967              
968             =item client
969              
970             =back
971              
972             =for html
973              
974             =cut
975              
976 1         4 return $self->{client};
977             } # client
978              
979             sub hardware_type {
980 0     0 1 0 my ($self) = @_;
981              
982             =pod
983              
984             =head2 hardware_type
985              
986             Returns the hardware_type
987              
988             Parameters:
989              
990             =for html
991              
992             =over
993              
994             =item none
995              
996             =back
997              
998             =for html
999              
1000             Returns:
1001              
1002             =for html
1003              
1004             =over
1005              
1006             =item hardware_type
1007              
1008             =back
1009              
1010             =for html
1011              
1012             =cut
1013              
1014 0         0 return $self->{hardware_type};
1015             } # hardware_type
1016              
1017             sub license_host {
1018 0     0 1 0 my ($self) = @_;
1019              
1020             =pod
1021              
1022             =head2 license_host
1023              
1024             Returns the license_host
1025              
1026             Parameters:
1027              
1028             =for html
1029              
1030             =over
1031              
1032             =item none
1033              
1034             =back
1035              
1036             =for html
1037              
1038             Returns:
1039              
1040             =for html
1041              
1042             =over
1043              
1044             =item license_host
1045              
1046             =back
1047              
1048             =for html
1049              
1050             =cut
1051              
1052 0         0 return $self->{license_host};
1053             } # license_host
1054              
1055             sub os {
1056 0     0 1 0 my ($self) = @_;
1057              
1058             =pod
1059              
1060             =head2 os
1061              
1062             Returns the os
1063              
1064             Parameters:
1065              
1066             =for html
1067              
1068             =over
1069              
1070             =item none
1071              
1072             =back
1073              
1074             =for html
1075              
1076             Returns:
1077              
1078             =for html
1079              
1080             =over
1081              
1082             =item os
1083              
1084             =back
1085              
1086             =for html
1087              
1088             =cut
1089              
1090 0         0 return $self->{os};
1091             } # os
1092              
1093             sub region {
1094 5     5 1 413431 my ($self) = @_;
1095              
1096             =pod
1097              
1098             =head2 region
1099              
1100             Returns the region
1101              
1102             Parameters:
1103              
1104             =for html
1105              
1106             =over
1107              
1108             =item none
1109              
1110             =back
1111              
1112             =for html
1113              
1114             Returns:
1115              
1116             =for html
1117              
1118             =over
1119              
1120             =item region
1121              
1122             =back
1123              
1124             =for html
1125              
1126             =cut
1127              
1128 5         38 return $self->{region};
1129             } # region
1130              
1131             sub registry_host {
1132 0     0 1   my ($self) = @_;
1133              
1134             =pod
1135              
1136             =head2 registry_host
1137              
1138             Returns the registry_host
1139              
1140             Parameters:
1141              
1142             =for html
1143              
1144             =over
1145              
1146             =item none
1147              
1148             =back
1149              
1150             =for html
1151              
1152             Returns:
1153              
1154             =for html
1155              
1156             =over
1157              
1158             =item client string
1159              
1160             =back
1161              
1162             =for html
1163              
1164             =cut
1165              
1166 0           return $self->{registry_host};
1167             } # registry_host
1168              
1169             sub sitename {
1170 0     0 1   my ($self) = @_;
1171              
1172             =pod
1173              
1174             =head2 sitename
1175              
1176             Returns the sitename
1177              
1178             Parameters:
1179              
1180             =for html
1181              
1182             =over
1183              
1184             =item none
1185              
1186             =back
1187              
1188             =for html
1189              
1190             Returns:
1191              
1192             =for html
1193              
1194             =over
1195              
1196             =item sitename
1197              
1198             =back
1199              
1200             =for html
1201              
1202             =cut
1203              
1204 0           return $self->{sitename};
1205             } # sitename
1206              
1207             sub version {
1208 0     0 1   my ($self) = @_;
1209              
1210             =pod
1211              
1212             =head2 version
1213              
1214             Returns the version
1215              
1216             Parameters:
1217              
1218             =for html
1219              
1220             =over
1221              
1222             =item none
1223              
1224             =back
1225              
1226             =for html
1227              
1228             Returns:
1229              
1230             =for html
1231              
1232             =over
1233              
1234             =item version
1235              
1236             =back
1237              
1238             =for html
1239              
1240             =cut
1241              
1242 0           return $self->{version};
1243             } # version
1244              
1245             sub regions {
1246 0     0 1   my ($self) = @_;
1247              
1248             =pod
1249              
1250             =head2 regions
1251              
1252             Returns an array of regions in an array context or the number of
1253             regions in a scalar context
1254              
1255             Parameters:
1256              
1257             =for html
1258              
1259             =over
1260              
1261             =item none
1262              
1263             =back
1264              
1265             =for html
1266              
1267             Returns:
1268              
1269             =for html
1270              
1271             =over
1272              
1273             =item array of regions or number of regions
1274              
1275             =back
1276              
1277             =for html
1278              
1279             =cut
1280              
1281 0 0         if (wantarray) {
1282 0           my @returnArray = sort @{$self->{regions}};
  0            
1283              
1284 0           return @returnArray;
1285             } else {
1286 0           return scalar @{$self->{regions}};
  0            
1287             } # if
1288             } # regions
1289              
1290             sub pwv () {
1291 0     0 1   my ($self) = @_;
1292              
1293             =pod
1294              
1295             =head2 pwv
1296              
1297             Returns the current working view or undef if not in a view
1298              
1299             Parameters:
1300              
1301             =for html
1302              
1303             =over
1304              
1305             =item none
1306              
1307             =back
1308              
1309             =for html
1310              
1311             Returns:
1312              
1313             =for html
1314              
1315             =over
1316              
1317             =item Current working view or undef if none
1318              
1319             =back
1320              
1321             =for html
1322              
1323             =cut
1324              
1325 0           my ($status, @output) = $self->execute ('pwv -short');
1326              
1327 0 0         return if $status;
1328 0 0         return $output[0] eq '** NONE **' ? undef : $output[0];
1329             } # pwv
1330              
1331             sub name2oid ($;$) {
1332 0     0 1   my ($self, $name, $vob) = @_;
1333              
1334             =pod
1335              
1336             =head2 name2oid
1337              
1338             Returns the oid for a given name
1339              
1340             Parameters:
1341              
1342             =for html
1343              
1344             =over
1345              
1346             =item name
1347              
1348             The name to convert (unless filesystem object it should contain a type:)
1349              
1350             =item vob
1351              
1352             The vob the name belongs to
1353              
1354             =back
1355              
1356             =for html
1357              
1358             Returns:
1359              
1360             =for html
1361              
1362             =over
1363              
1364             =item OID
1365              
1366             =back
1367              
1368             =for html
1369              
1370             =cut
1371              
1372 0 0         if ($vob) {
1373 0           $vob = '@' . vobtag $vob;
1374             } else {
1375 0           $vob = '';
1376             } # if
1377              
1378 0           my ($status, @output) = $self->execute ("dump $name$vob");
1379              
1380 0 0         return if $status;
1381              
1382 0           @output = grep {/^oid=/} @output;
  0            
1383              
1384 0 0         if ($output[0] =~ /oid=(\S+)\s+/) {
1385 0           return $1;
1386             } else {
1387 0           return;
1388             } # if
1389             } # name2oid
1390              
1391             sub oid2name ($$) {
1392 0     0 1   my ($self, $oid, $vob) = @_;
1393              
1394             =pod
1395              
1396             =head2 oid2name
1397              
1398             Returns the object name for the given oid
1399              
1400             Parameters:
1401              
1402             =for html
1403              
1404             =over
1405              
1406             =item oid
1407              
1408             The OID to convert
1409              
1410             =item vob
1411              
1412             The vob the OID belongs to
1413              
1414             =back
1415              
1416             =for html
1417              
1418             Returns:
1419              
1420             =for html
1421              
1422             =over
1423              
1424             =item String representing the OID's textual name/value
1425              
1426             =back
1427              
1428             =for html
1429              
1430             =cut
1431              
1432 0 0         $vob = vobtag $vob
1433             unless $vob =~ /^vobuuid:/;
1434              
1435 0           my ($status, @output) =
1436             $self->execute ("describe -fmt \"%n\" oid:$oid\@$vob");
1437              
1438 0 0         return if $status;
1439 0           return $output[0];
1440             } # oid2name
1441              
1442             sub verbose_level {
1443 0     0 1   my ($self) = @_;
1444              
1445             =pod
1446              
1447             =head2 verbose_level
1448              
1449             Returns the verbose_level
1450              
1451             Parameters:
1452              
1453             =for html
1454              
1455             =over
1456              
1457             =item none
1458              
1459             =back
1460              
1461             =for html
1462              
1463             Returns:
1464              
1465             =for html
1466              
1467             =over
1468              
1469             =item verbose_level
1470              
1471             =back
1472              
1473             =for html
1474              
1475             =cut
1476              
1477 0           return $self->{verbose_level};
1478             } # verbose_level
1479              
1480             sub quiet {
1481 0     0 1   my ($self) = @_;
1482              
1483             =pod
1484              
1485             =head2 quiet
1486              
1487             Sets verbose_level to quiet
1488              
1489             Parameters:
1490              
1491             =for html
1492              
1493             =over
1494              
1495             =item none
1496              
1497             =back
1498              
1499             =for html
1500              
1501             Returns:
1502              
1503             =for html
1504              
1505             =over
1506              
1507             =item none
1508              
1509             =back
1510              
1511             =for html
1512              
1513             =cut
1514              
1515 0           $self->{verbose_level} = 0;
1516              
1517 0           return;
1518             } # quiet
1519              
1520             sub noisy {
1521 0     0 1   my ($self) = @_;
1522              
1523             =pod
1524              
1525             =head2 noisy
1526              
1527             Sets verbose_level to noisy
1528              
1529             Parameters:
1530              
1531             =for html
1532              
1533             =over
1534              
1535             =item none
1536              
1537             =back
1538              
1539             =for html
1540              
1541             Returns:
1542              
1543             =for html
1544              
1545             =over
1546              
1547             =item none
1548              
1549             =back
1550              
1551             =for html
1552              
1553             =cut
1554              
1555 0           $self->{verbose_level} = 1;
1556              
1557 0           return;
1558             } # noisy
1559              
1560             $CC = Clearcase->new;
1561              
1562             1;
1563              
1564             =pod
1565              
1566             =head1 DEPENDENCIES
1567              
1568             =head2 Perl Modules
1569              
1570             =head1 DEPENDENCIES
1571              
1572             =head2 Modules
1573              
1574             =over
1575              
1576             =item L
1577              
1578             =item L
1579              
1580             =back
1581              
1582             =head1 BUGS AND LIMITATIONS
1583              
1584             There are no known bugs in this module
1585              
1586             Please report problems to Andrew DeFaria .
1587              
1588             =head1 COPYRIGHT AND LICENSE
1589              
1590             Copyright (C) 2007-2026 by Andrew DeFaria
1591              
1592             This library is free software; you can redistribute it and/or modify
1593             it under the same terms as Perl itself, either Perl version 5.38.0 or,
1594             at your option, any later version of Perl 5 you may have available.
1595              
1596             =cut