More changes to Clearcase and Clearquest stuff
[clearscm.git] / lib / Clearcase / View.pm
1 =pod
2
3 =head1 NAME $RCSfile: View.pm,v $
4
5 Object oriented interface to a Clearcase View
6
7 =head1 VERSION
8
9 =over
10
11 =item Author
12
13 Andrew DeFaria <Andrew@ClearSCM.com>
14
15 =item Revision
16
17 $Revision: 1.18 $
18
19 =item Created
20
21 Thu Dec 29 12:07:59 PST 2005
22
23 =item Modified
24
25 $Date: 2011/11/16 19:46:13 $
26
27 =back
28
29 =head1 SYNOPSIS
30
31 Provides access to information about a Clearcase View. Note that some
32 information about a view is not populated into the view object at
33 object instantiation. This is because members such as labels can be
34 very long and time consuming to acquire. When the caller request such
35 fields they are expanded.
36
37  # Create View object
38  my $view = new Clearcase::View (tag => 'test');
39
40  # Access member variables...
41  display "View:\t\t \t"         . $view->tag;
42  display "Accessed by:\t\t"     . $view->accessed_by;
43  display "Accessed date:\t\t"   . $view->accessed_date;
44  display "Access path:\t\t"     . $view->access_path;
45  display "Active:\t\t\t"        . $view->active;
46
47  display_nolf MAGENTA   . "Additional groups:\t";
48
49  foreach ($view->additional_groups) {
50    display_nolf "$_ ";
51  } # foreach
52
53  display '';
54
55  display "Created by:\t\t"      . $view->created_by;
56  display "Created date:\t\t"    . $view->created_date;
57  display "CS updated by:\t\t"   . $view->cs_updated_by;
58  display "CS updated date:\t"   . $view->cs_updated_date;
59  display "Global path:\t\t"     . $view->gpath;
60  display "Group:\t\t\t"         . $view->group;
61  display "Group mode:\t\t"      . $view->group_mode;
62  display "Host:\t\t\t"          . $view->host;
63  display "Mode:\t\t\t"          . $view->mode;
64  display "Modified by:\t\t"     . $view->modified_by;
65  display "Modified date:\t\t"   . $view->modified_date;
66  display "Other mode:\t\t"      . $view->other_mode;
67  display "Owner:\t\t\t"         . $view->owner;
68  display "Owner mode:\t\t"      . $view->owner_mode;
69  display "Properties:\t\t"      . $view->properties;
70  display "Region:\t\t\t"        . $view->region;
71  display "Server host:\t\t"     . $view->shost;
72  display "Text mode:\t\t"       . $view->text_mode;
73  display "UUID:\t\t\t"          . $view->uuid;
74
75  display_nolf "Type:\t\t\t";
76
77  if ($view->snapshot) {
78    display_nolf 'snapshot';
79  } else {
80    display_nolf 'dynamic';
81  } # if
82
83  if ($view->ucm) {
84    display_nolf ',ucm';
85  } # if
86
87  display '';
88
89  # View manipulation
90  my $new_view = new Clearcase::View ($ENV{USER} . '_testview');
91
92  $new_view->create;
93
94  # Start new view
95  $new_view->start;
96
97  # Set to view
98  $new_view->set;
99
100  # Stop view
101  $new_view->stop;
102
103  # Stop view server process
104  $new_view->kill;
105
106  # Remove view
107  if ($new_view->exists) {
108    $new_view->remove;
109  } # if
110
111 =head1 DESCRIPTION
112
113 This module implements an object oriented interface to a Clearcase
114 view.
115
116 =head1 ROUTINES
117
118 The following routines are exported:
119
120 =cut
121
122 package Clearcase::View;
123
124 use strict;
125 use warnings;
126
127 use Clearcase;
128 use Display; 
129
130 sub new ($;$) {
131   my ($class, $tag, $region) = @_;
132
133 =pod
134
135 =head2 new (tag)
136
137 Construct a new Clearcase View object. Note that not all members are
138 initially populated because doing so would be time consuming. Such
139 member variables will be expanded when accessed.
140
141 Parameters:
142
143 =for html <blockquote>
144
145 =over
146
147 =item tag
148
149 View tag to be instantiated. You can use either an object oriented call
150 (i.e. my $view = new Clearcase::View (tag => 'my_new_view')) or the
151 normal call (i.e. my $vob = new Clearcase::View ('my_new_view')). You
152 can also instantiate a new view by supplying a tag and then later
153 calling the create method.
154
155 =back
156
157 =for html </blockquote>
158
159 Returns:
160
161 =for html <blockquote>
162
163 =over
164
165 =item Clearcase View object
166
167 =back
168
169 =for html </blockquote>
170
171 =cut
172
173   my $self = bless { tag => $tag }, $class;
174
175   $self->updateViewInfo ($region);
176
177   return $self;
178 } # new
179   
180 sub accessed_by () {
181   my ($self) = @_;
182    
183 =pod
184
185 =head2 accessed_by
186
187 Returns the user name of the last user to access the view.
188
189 Parameters:
190
191 =for html <blockquote>
192
193 =over
194
195 =item none
196
197 =back
198
199 =for html </blockquote>
200
201 Returns:
202
203 =for html <blockquote>
204
205 =over
206
207 =item user name
208
209 =back
210
211 =for html </blockquote>
212
213 =cut
214
215   return $self->{accessed_by};
216 } # accessed_by
217
218 sub accessed_date () {
219   my ($self) = @_;
220      
221 =pod
222
223 =head2 accessed_date
224
225 Returns the date the view was last accessed.
226
227 Parameters:
228
229 =for html <blockquote>
230
231 =over
232
233 =item none
234
235 =back
236
237 =for html </blockquote>
238
239 Returns:
240
241 =for html <blockquote>
242
243 =over
244
245 =item access date
246
247 =back
248
249 =for html </blockquote>
250
251 =cut
252
253   return $self->{accessed_date};
254 } # accessed_date
255
256 sub access_path () {
257   my ($self) = @_;
258    
259 =pod
260
261 =head2 access_path
262
263 Returns the access path of the view.
264
265 Parameters:
266
267 =for html <blockquote>
268
269 =over
270
271 =item none
272
273 =back
274
275 =for html </blockquote>
276
277 Returns:
278
279 =for html <blockquote>
280
281 =over
282
283 =item access path
284
285 =back
286
287 =for html </blockquote>
288
289 =cut
290
291   return $self->{access_path};
292 } # access_path
293
294 sub active () {
295   my ($self) = @_;
296   
297 =pod
298
299 =head2 active
300
301 Returns true if the view is active
302
303 Parameters:
304
305 =for html <blockquote>
306
307 =over
308
309 =item none
310
311 =back
312
313 =for html </blockquote>
314
315 Returns:
316
317 =for html <blockquote>
318
319 =over
320
321 =item boolean
322
323 =back
324
325 =for html </blockquote>
326
327 =cut
328
329   return $self->{active};
330 } # active
331
332 sub additional_groups () {
333   my ($self) = @_;
334   
335 =pod
336
337 =head2 additional_groups
338
339 Returns the additional groups that have permission to access this
340 view.
341
342 Parameters:
343
344 =for html <blockquote>
345
346 =over
347
348 =item none
349
350 =back
351
352 =for html </blockquote>
353
354 Returns:
355
356 =for html <blockquote>
357
358 =over
359
360 =item An array of additional groups
361
362 =back
363
364 =for html </blockquote>
365
366 =cut
367
368   if ($self->{additional_groups}) {
369     return @{$self->{additional_groups}};
370   } else {
371     return ();
372   } # if
373 } # additional_groups
374
375 sub created_by () {
376   my ($self) = @_;
377   
378 =pod
379
380 =head2 created_by
381
382 Returns the user name who created the view
383
384 Parameters:
385
386 =for html <blockquote>
387
388 =over
389
390 =item none
391
392 =back
393
394 =for html </blockquote>
395
396 Returns:
397
398 =for html <blockquote>
399
400 =over
401
402 =item user name
403
404 =back
405
406 =for html </blockquote>
407
408 =cut
409
410   return $self->{created_by};
411 } # created_by
412
413 sub created_date () {
414    my ($self) = @_;
415    
416 =pod
417
418 =head2 created_date
419
420 Returns the date the view was created.
421
422 Parameters:
423
424 =for html <blockquote>
425
426 =over
427
428 =item none
429
430 =back
431
432 =for html </blockquote>
433
434 Returns:
435
436 =for html <blockquote>
437
438 =over
439
440 =item date
441
442 =back
443
444 =for html </blockquote>
445
446 =cut
447
448   return $self->{created_date};
449 } # created_date
450
451 sub cs_updated_by () {
452   my ($self) = @_;
453   
454 =pod
455
456 =head2 cs_updated_date
457
458 Returns the user name of the last user to access the view.
459
460 Parameters:
461
462 =for html <blockquote>
463
464 =over
465
466 =item none
467
468 =back
469
470 =for html </blockquote>
471
472 Returns:
473
474 =for html <blockquote>
475
476 =over
477
478 =item date
479
480 =back
481
482 =for html </blockquote>
483
484 =cut
485
486   return $self->{cs_updated_by};
487 } # cs_updated_by
488
489 sub cs_updated_date () {
490   my ($self) = @_;
491
492 =pod
493
494 =head2 dynamic
495
496 Returns the date the config spec for this view was updated.
497
498 Parameters:
499
500 =for html <blockquote>
501
502 =over
503
504 =item none
505
506 =back
507
508 =for html </blockquote>
509
510 Returns:
511
512 =for html <blockquote>
513
514 =over
515
516 =item date
517
518 =back
519
520 =for html </blockquote>
521
522 =cut
523
524   return $self->{cs_updated_date};
525 } # cs_updated_date
526
527 sub dynamic () {
528   my ($self) = @_;
529   
530 =pod
531
532 =head2 dynamic
533
534 Returns true if the view is a dynamic view - false otherwise.
535
536 Parameters:
537
538 =for html <blockquote>
539
540 =over
541
542 =item none
543
544 =back
545
546 =for html </blockquote>
547
548 Returns:
549
550 =for html <blockquote>
551
552 =over
553
554 =item boolean
555
556 =back
557
558 =for html </blockquote>
559
560 =cut
561
562   return $self->type eq 'dynamic';
563 } # dynamic
564
565 sub gpath () {
566   my ($self) = @_;
567   
568 =pod
569
570 =head2 gpath
571
572 Returns the global path to the view
573
574 Parameters:
575
576 =for html <blockquote>
577
578 =over
579
580 =item none
581
582 =back
583
584 =for html </blockquote>
585
586 Returns:
587
588 =for html <blockquote>
589
590 =over
591
592 =item global path
593
594 =back
595
596 =for html </blockquote>
597
598 =cut
599   
600   return $self->{gpath};
601 } # gpath
602
603 sub group () {
604   my ($self) = @_;
605   
606 =pod
607
608 =head2 group
609
610 Returns the group of the user who created the view.
611
612 Parameters:
613
614 =for html <blockquote>
615
616 =over
617
618 =item none
619
620 =back
621
622 =for html </blockquote>
623
624 Returns:
625
626 =for html <blockquote>
627
628 =over
629
630 =item group name
631
632 =back
633
634 =for html </blockquote>
635
636 =cut
637
638   return $self->{group};
639 } # group
640
641 sub group_mode () {
642   my ($self) = @_;
643   
644 =pod
645
646 =head2 group_mode
647
648 Returns the group mode of the view.
649
650 Parameters:
651
652 =for html <blockquote>
653
654 =over
655
656 =item none
657
658 =back
659
660 =for html </blockquote>
661
662 Returns:
663
664 =for html <blockquote>
665
666 =over
667
668 =item A string representing the group mode
669
670 =back
671
672 =for html </blockquote>
673
674 =cut
675
676   return $self->{group_mode};
677 } # group_mode
678
679 sub host () {
680   my ($self) = @_;
681   
682 =pod
683
684 =head2 host
685
686 Returns the host that the view resides on
687
688 Parameters:
689
690 =for html <blockquote>
691
692 =over
693
694 =item none
695
696 =back
697
698 =for html </blockquote>
699
700 Returns:
701
702 =for html <blockquote>
703
704 =over
705
706 =item host
707
708 =back
709
710 =for html </blockquote>
711
712 =cut
713
714   return $self->{host};
715 } # host
716
717 sub mode () {
718   my ($self) = @_;
719   
720 =pod
721
722 =head2 mode
723
724 Returns the numeric mode representing the view's access mode
725
726 Parameters:
727
728 =for html <blockquote>
729
730 =over
731
732 =item none
733
734 =back
735
736 =for html </blockquote>
737
738 Returns:
739
740 =for html <blockquote>
741
742 =over
743
744 =item numeric mode
745
746 =back
747
748 =for html </blockquote>
749
750 =cut
751
752   return $self->{mode};
753 } # mode
754
755 sub modified_by () {
756   my ($self) = @_;
757   
758 =pod
759
760 =head2 modified_by
761
762 Returns the user name of the last user to modify the view.
763
764 Parameters:
765
766 =for html <blockquote>
767
768 =over
769
770 =item none
771
772 =back
773
774 =for html </blockquote>
775
776 Returns:
777
778 =for html <blockquote>
779
780 =over
781
782 =item user name
783
784 =back
785
786 =for html </blockquote>
787
788 =cut
789
790   return $self->{modified_by};
791 } # modified_by
792
793 sub modified_date () {
794   my ($self) = @_;
795   
796 =pod
797
798 =head2 modified_date
799
800 Returns the date the view was last modified.
801
802 Parameters:
803
804 =for html <blockquote>
805
806 =over
807
808 =item none
809
810 =back
811
812 =for html </blockquote>
813
814 Returns:
815
816 =for html <blockquote>
817
818 =over
819
820 =item date
821
822 =back
823
824 =for html </blockquote>
825
826 =cut
827
828   return $self->{modified_date};
829 } # modified_date
830
831 sub other_mode () {
832   my ($self) = @_;
833   
834 =pod
835
836 =head2 other_mode
837
838 Returns the mode for other for the view.
839
840 Parameters:
841
842 =for html <blockquote>
843
844 =over
845
846 =item none
847
848 =back
849
850 =for html </blockquote>
851
852 Returns:
853
854 =for html <blockquote>
855
856 =over
857
858 =item A string repesenting the other mode
859
860 =back
861
862 =for html </blockquote>
863
864 =cut
865
866   return $self->{other_mode};
867 } # other_mode
868
869 sub owner () {
870   my ($self) = @_;
871   
872 =pod
873
874 =head2 owner
875
876 Returns the user name of the owner of the view.
877
878 Parameters:
879
880 =for html <blockquote>
881
882 =over
883
884 =item none
885
886 =back
887
888 =for html </blockquote>
889
890 Returns:
891
892 =for html <blockquote>
893
894 =over
895
896 =item user name
897
898 =back
899
900 =for html </blockquote>
901
902 =cut
903
904   return $self->{owner}
905 } # owner
906
907 sub owner_mode () {
908   my ($self) = @_;
909   
910 =pod
911
912 =head2 owner_mode
913
914 Returns the mode for the owner for the view.
915
916 Parameters:
917
918 =for html <blockquote>
919
920 =over
921
922 =item none
923
924 =back
925
926 =for html </blockquote>
927
928 Returns:
929
930 =for html <blockquote>
931
932 =over
933
934 =item A string repesenting the other mode
935
936 =back
937
938 =for html </blockquote>
939
940 =cut
941
942   return $self->{owner_mode}
943 } # owner_mode
944
945 sub properties () {
946   my ($self) = @_;
947   
948 =pod
949
950 =head2 properties
951
952 Returns the properties of the view.
953
954 Parameters:
955
956 =for html <blockquote>
957
958 =over
959
960 =item none
961
962 =back
963
964 =for html </blockquote>
965
966 Returns:
967
968 =for html <blockquote>
969
970 =over
971
972 =item properties
973
974 =back
975
976 =for html </blockquote>
977
978 =cut
979
980   return $self->{properties};
981 } # properties
982
983 sub region () {
984   my ($self) = @_;
985   
986 =pod
987
988 =head2 region
989
990 Returns the region of the view
991
992 Parameters:
993
994 =for html <blockquote>
995
996 =over
997
998 =item none
999
1000 =back
1001
1002 =for html </blockquote>
1003
1004 Returns:
1005
1006 =for html <blockquote>
1007
1008 =over
1009
1010 =item region
1011
1012 =back
1013
1014 =for html </blockquote>
1015
1016 =cut
1017
1018   return $self->{region};
1019 } # region
1020
1021 sub shost () {
1022   my ($self) = @_;
1023   
1024 =pod
1025
1026 =head2 shost
1027
1028 Returns the server host of the view
1029
1030 Parameters:
1031
1032 =for html <blockquote>
1033
1034 =over
1035
1036 =item none
1037
1038 =back
1039
1040 =for html </blockquote>
1041
1042 Returns:
1043
1044 =for html <blockquote>
1045
1046 =over
1047
1048 =item server host
1049
1050 =back
1051
1052 =for html </blockquote>
1053
1054 =cut
1055
1056   return $self->{shost};
1057 } # shost
1058
1059 sub snapshot () {
1060   my ($self) = @_;
1061   
1062 =pod
1063
1064 =head2 snapshot
1065
1066 Returns true if the view is a snapshot view - false otherwise.
1067
1068 Parameters:
1069
1070 =for html <blockquote>
1071
1072 =over
1073
1074 =item none
1075
1076 =back
1077
1078 =for html </blockquote>
1079
1080 Returns:
1081
1082 =for html <blockquote>
1083
1084 =over
1085
1086 =item boolean
1087
1088 =back
1089
1090 =for html </blockquote>
1091
1092 =cut
1093
1094   return $self->type eq 'snapshot';
1095 } # snapshot
1096
1097 sub webview () {
1098   my ($self) = @_;
1099   
1100 =pod
1101
1102 =head2 webview
1103
1104 Returns true if the view is a webview - false otherwise.
1105
1106 Parameters:
1107
1108 =for html <blockquote>
1109
1110 =over
1111
1112 =item none
1113
1114 =back
1115
1116 =for html </blockquote>
1117
1118 Returns:
1119
1120 =for html <blockquote>
1121
1122 =over
1123
1124 =item boolean
1125
1126 =back
1127
1128 =for html </blockquote>
1129
1130 =cut
1131
1132   return $self->type eq 'webview';
1133 } # webview
1134
1135 sub tag () {
1136   my ($self) = @_;
1137   
1138 =pod
1139
1140 =head1 tag
1141
1142 Returns the tag for this view.
1143
1144 Parameters:
1145
1146 =for html <blockquote>
1147
1148 =over
1149
1150 =item none
1151
1152 =back
1153
1154 =for html </blockquote>
1155
1156 Returns:
1157
1158 =for html <blockquote>
1159
1160 =over
1161
1162 =item tag
1163
1164 =back
1165
1166 =for html </blockquote>
1167
1168 =cut
1169
1170   return $self->{tag};
1171  } # tag
1172
1173 sub text_mode () {
1174   my ($self) = @_;
1175   
1176 =pod
1177
1178 =head2 text_mode
1179
1180 Returns the text_mode of the view
1181
1182 Parameters:
1183
1184 =for html <blockquote>
1185
1186 =over
1187
1188 =item none
1189
1190 =back
1191
1192 =for html </blockquote>
1193
1194 Returns:
1195
1196 =for html <blockquote>
1197
1198 =over
1199
1200 =item text mode
1201
1202 =back
1203
1204 =for html </blockquote>
1205
1206 =cut
1207
1208   return $self->{text_mode};
1209 } # tag
1210
1211 sub type () {
1212   my ($self) = @_;
1213   
1214 =pod
1215
1216 =head2 type
1217
1218 Returns the type of the view.
1219
1220 Parameters:
1221
1222 =for html <blockquote>
1223
1224 =over
1225
1226 =item none
1227
1228 =back
1229
1230 =for html </blockquote>
1231
1232 Returns:
1233
1234 =for html <blockquote>
1235
1236 =over
1237
1238 =item type
1239
1240 =back
1241
1242 =for html </blockquote>
1243
1244 =cut
1245
1246   return $self->{type} ? $self->{type} : 'Unknown';
1247 } # type
1248
1249 sub ucm () {
1250   my ($self) = @_;
1251   
1252 =pod
1253
1254 =head2 ucm
1255
1256 Returns true if the view is a UCM view.
1257
1258 Parameters:
1259
1260 =for html <blockquote>
1261
1262 =over
1263
1264 =item none
1265
1266 =back
1267
1268 =for html </blockquote>
1269
1270 Returns:
1271
1272 =for html <blockquote>
1273
1274 =over
1275
1276 =item boolean
1277
1278 =back
1279
1280 =for html </blockquote>
1281
1282 =cut
1283
1284   return $self->{ucm};
1285 } # ucm
1286
1287 sub uuid () {
1288   my ($self) = @_;
1289   
1290 =pod
1291
1292 =head2 uuid
1293
1294 Returns the uuid for the view.
1295
1296 Parameters:
1297
1298 =for html <blockquote>
1299
1300 =over
1301
1302 =item none
1303
1304 =back
1305
1306 =for html </blockquote>
1307
1308 Returns:
1309
1310 =for html <blockquote>
1311
1312 =over
1313
1314 =item uuid
1315
1316 =back
1317
1318 =for html </blockquote>
1319
1320 =cut
1321
1322   return $self->{uuid};
1323 } # uuid
1324
1325 sub exists () {
1326   my ($self) = @_;
1327
1328 =pod
1329
1330 =head3 exists
1331
1332 Returns true if the view exists - false otherwise.
1333
1334 Parameters:
1335
1336 =for html <blockquote>
1337
1338 =over
1339
1340 =item none
1341
1342 =back
1343
1344 =for html </blockquote>
1345
1346 Returns:
1347
1348 =for html <blockquote>
1349
1350 =over
1351
1352 =item boolean
1353
1354 =back
1355
1356 =for html </blockquote>
1357
1358 =cut
1359
1360   my ($status, @output) = $Clearcase::CC->execute ("lsview $self->{tag}");
1361   
1362   return !$status;
1363 } # exists
1364
1365 sub create (;$$$) {
1366   my ($self, $host, $vws, $region) = @_;
1367     
1368 =pod
1369
1370 =head2 create
1371
1372 Creates a view
1373
1374 Parameters:
1375
1376 =for html <blockquote>
1377
1378 =over
1379
1380 =item host
1381
1382 Host to create the view on. Default is to use -stgloc -auto.
1383
1384 =item vws
1385
1386 View working storage directory to use. Default is to use -stgloc -auto.
1387
1388 =back
1389
1390 =for html </blockquote>
1391
1392 Returns:
1393
1394 =for html <blockquote>
1395
1396 =over
1397
1398 =item $status
1399
1400 Status from cleartool
1401
1402 =item @output
1403
1404 Ouput from cleartool
1405
1406 =back
1407
1408 =for html </blockquote>
1409
1410 =cut
1411
1412   $region ||= $Clearcase::CC->region;
1413
1414   if ($self->exists) {
1415     $self->updateViewInfo ($region);
1416       
1417     return (0, ())
1418   } # if
1419
1420   my ($status, @output);
1421     
1422   if ($host && $vws) {
1423     ($status, @output) = 
1424       $Clearcase::CC->execute ("mkview -tag $self->{tag} -region $region "
1425                           .    "-host $host -hpath $vws -gpath $vws $vws");
1426   } else {
1427     # Note this requires that -stgloc's work and that using -auto is not a 
1428     # problem.
1429     ($status, @output) =
1430        $Clearcase::CC->execute ("mkview -tag $self->{tag} -stgloc -auto");
1431   } # if
1432
1433   $self->updateViewInfo ($region);
1434
1435   return ($status, @output);
1436 } # create
1437   
1438 sub createUCM ($$) {
1439   my ($self, $stream, $pvob, $region) = @_;
1440
1441 =pod
1442
1443 =head2 createUCM
1444
1445 Create a UCM view
1446
1447 Parameters:
1448
1449 =for html <blockquote>
1450
1451 =over
1452
1453 =item streamName
1454
1455 Name of stream to attach new view to
1456
1457 =item pvob
1458
1459 Name of project vob
1460
1461 =back
1462
1463 =for html </blockquote>
1464
1465 Returns:
1466
1467 =for html <blockquote>
1468
1469 =over
1470
1471 =item status
1472
1473 Integer status
1474
1475 =item output
1476
1477 Array of output
1478
1479 =back
1480
1481 =for html </blockquote>
1482
1483 =cut
1484
1485   $region ||= $Clearcase::CC->region;
1486   
1487   return (0, ())
1488     if $self->exists;
1489       
1490   # Update object members
1491   $self->{stream} = $stream;
1492   $self->{pvob}   = $pvob;
1493     
1494   # Need to create the view
1495   my ($status, @output) = 
1496     $Clearcase::CC->execute ("mkview -tag $self->{tag} -stream " 
1497                            . "$self->{stream}\@$self->{pvob} -stgloc -auto");
1498  
1499   return ($status, @output)
1500     if $status;
1501       
1502   $self->updateViewInfo ($region);
1503
1504   return ($status, @output);
1505 } # createUCM
1506
1507 sub remove () {
1508   my ($self) = @_;
1509
1510 =pod
1511
1512 =head3 remove
1513
1514 Removes the view.
1515
1516 Parameters:
1517
1518 =for html <blockquote>
1519
1520 =over
1521
1522 =item none
1523
1524 =back
1525
1526 =for html </blockquote>
1527
1528 Returns:
1529
1530 =for html <blockquote>
1531
1532 =over
1533
1534 =item $status
1535
1536 Status from cleartool
1537
1538 =item @output
1539
1540 Ouput from cleartool
1541
1542 =back
1543
1544 =for html </blockquote>
1545
1546 =cut
1547
1548   return (0, ())
1549     unless $self->exists;
1550       
1551   my ($status, @output);
1552
1553   if ($self->dynamic) {
1554     ($status, @output) = $Clearcase::CC->execute (
1555        "rmview -force -tag $self->{tag}"
1556      );
1557   } else {
1558     error 'Removal of snapshot views not implemented yet', 1;
1559     #($status, @output) = $Clearcase::CC->execute (
1560     #  "rmview -force $self->{snapshot_view_pname}"
1561     #);
1562   } # if
1563
1564   return ($status, @output);
1565 } # remove
1566
1567 sub start () {
1568   my ($self) = @_;
1569
1570 =pod
1571
1572 =head2 start
1573
1574 Starts the view.
1575
1576 Parameters:
1577
1578 =for html <blockquote>
1579
1580 =over
1581
1582 =item none
1583
1584 =back
1585
1586 =for html </blockquote>
1587
1588 Returns:
1589
1590 =for html <blockquote>
1591
1592 =over
1593
1594 =item $status
1595
1596 Status from cleartool
1597
1598 =item @output
1599
1600 Ouput from cleartool
1601
1602 =back
1603
1604 =for html </blockquote>
1605
1606 =cut
1607
1608   return $Clearcase::CC->execute ("startview $self->{tag}");
1609 } # start
1610
1611 sub stop () {
1612   my ($self) = @_;
1613
1614 =pod
1615
1616 =head2 stop
1617
1618 Stops the view.
1619
1620 Parameters:
1621
1622 =for html <blockquote>
1623
1624 =over
1625
1626 =item none
1627
1628 =back
1629
1630 =for html </blockquote>
1631
1632 Returns:
1633
1634 =for html <blockquote>
1635
1636 =over
1637
1638 =item $status
1639
1640 Status from cleartool
1641
1642 =item @output
1643
1644 Ouput from cleartool
1645
1646 =back
1647
1648 =for html </blockquote>
1649
1650 =cut
1651
1652   return $Clearcase::CC->execute ("endview $self->{tag}");
1653 } # stop
1654
1655 sub kill () {
1656   my ($self) = @_;
1657
1658 =pod
1659
1660 =head2 kill
1661
1662 Stops the view at the view_server process if nobody else is accessing the view.
1663
1664 Parameters:
1665
1666 =for html <blockquote>
1667
1668 =over
1669
1670 =item none
1671
1672 =back
1673
1674 =for html </blockquote>
1675
1676 Returns:
1677
1678 =for html <blockquote>
1679
1680 =over
1681
1682 =item $status
1683
1684 Status from cleartool
1685
1686 =item @output
1687
1688 Ouput from cleartool
1689
1690 =back
1691
1692 =for html </blockquote>
1693
1694 =cut
1695
1696   return $Clearcase::CC->execute ("endview -server $self->{tag}");
1697 } # kill
1698
1699 sub set () {
1700   my ($self) = @_;
1701
1702 =pod
1703
1704 =head3 set
1705
1706 Starts the view then changes directory the to view's root.
1707
1708 Parameters:
1709
1710 =for html <blockquote>
1711
1712 =over
1713
1714 =item none
1715
1716 =back
1717
1718 =for html </blockquote>
1719
1720 Returns:
1721
1722 =for html <blockquote>
1723
1724 =over
1725
1726 =item $status
1727
1728 Status from cleartool
1729
1730 =item @output
1731
1732 Ouput from cleartool
1733
1734 =back
1735
1736 =for html </blockquote>
1737
1738 =cut
1739
1740   my ($status, @output) = $self->start;
1741
1742   chdir "$Clearcase::VIEWTAG_PREFIX/$self->{tag}";
1743
1744   return ($status, @output);
1745 } # set
1746
1747 sub updateViewInfo ($$) {
1748   my ($self, $region) = @_;
1749
1750   $region ||= $Clearcase::CC->region;
1751
1752   my ($status, @output) = $Clearcase::CC->execute (
1753     "lsview -region $region -long -properties -full $self->{tag}"
1754   );
1755
1756   # Assuming this view is an empty shell of an object that the user may possibly
1757   # use the create method on, return our blessings...
1758
1759   # No longer assume that. Could equally be the case where the view server
1760   # failed to respond. Carry on then...return if $status != 0;
1761
1762   # Defaults
1763   $self->{type}               = 'dynamic';
1764   $self->{ucm}                = 0;
1765   $self->{additional_groups}  = '';
1766
1767   foreach (@output) {
1768     if (/Global path: (.*)/) {
1769       $self->{gpath} = $1;
1770     } elsif (/Server host: (.*)/) {
1771       $self->{shost} = $1;
1772     } elsif (/Region: (.*)/) {
1773       $self->{region} = $1;
1774     } elsif (/Active: (.*)/) {
1775       $self->{active} = ($1 eq 'YES') ? 1 : 0;
1776     } elsif (/View uuid: (.*)/) {
1777       $self->{uuid} = $1;
1778     } elsif (/View on host: (.*)/) {
1779       $self->{host} = $1;
1780     } elsif (/View server access path: (.*)/) {
1781       $self->{access_path} = $1;
1782     } elsif (/View attributes: (.*)/) {
1783       my $view_attributes = $1;
1784       $self->{type}   = $view_attributes =~ /webview/
1785                       ? 'webview'
1786                       : $view_attributes =~ /snapshot/
1787                       ? 'snapshot'
1788                       : 'dynamic';
1789       $self->{ucm}    = $view_attributes =~ /ucmview/  
1790                                          ? 1
1791                                          : 0;
1792     } elsif (/Created (\S+) by (.+)/) {
1793       $self->{created_date}   = $1;
1794       $self->{created_by}     = $2;
1795     } elsif (/Last modified (\S+) by (.+)/) {
1796       $self->{modified_date}  = $1;
1797       $self->{modified_by}    = $2;
1798     } elsif (/Last accessed (\S+) by (.+)/) {
1799       $self->{accessed_date}  = $1;
1800       $self->{accessed_by}    = $2;
1801     } elsif (/Last config spec update (\S+) by (.+)/) {
1802       $self->{cs_updated_date}        = $1;
1803       $self->{cs_updated_by}          = $2;
1804     } elsif (/Text mode: (\S+)/) {
1805       $self->{text_mode} = $1;
1806     } elsif (/Properties: (.*)/) {
1807       $self->{properties} = $1;
1808     } elsif (/Owner: (\S+)\s+: (\S+) /) {
1809       $self->{owner}          = $1;
1810       $self->{owner_mode}     = $2;
1811     } elsif (/Group: (.+)\s+:\s+(\S+)\s+/) {
1812       $self->{group}          = $1;
1813        $self->{group_mode}     = $2;
1814     } elsif (/Other:\s+: (\S+) /) {
1815       $self->{other_mode}     = $1;
1816     } elsif (/Additional groups: (.*)/) {
1817       my @additional_groups = split /\s+/, $1;
1818       $self->{additional_groups} = \@additional_groups;
1819     } # if
1820   } # foreach
1821
1822   # Change modes to numeric
1823   $self->{mode} = 0;
1824
1825   if ($self->{owner_mode}) {
1826     $self->{mode} += 400 if $self->{owner_mode} =~ /r/;
1827     $self->{mode} += 200 if $self->{owner_mode} =~ /w/;
1828     $self->{mode} += 100 if $self->{owner_mode} =~ /x/;
1829     $self->{mode} += 40  if $self->{group_mode} =~ /r/;
1830     $self->{mode} += 20  if $self->{group_mode} =~ /w/;
1831     $self->{mode} += 10  if $self->{group_mode} =~ /x/;
1832     $self->{mode} += 4   if $self->{other_mode} =~ /r/;
1833     $self->{mode} += 2   if $self->{other_mode} =~ /w/;
1834     $self->{mode} += 1   if $self->{other_mode} =~ /x/;
1835   } # if
1836   
1837   return;
1838 } # updateViewInfo
1839
1840 1;
1841
1842 =pod
1843
1844 =head2 DEPENDENCIES
1845
1846 =for html <p><a href="/php/scm_man.php?file=lib/Clearcase.pm">Clearcase</a></p>
1847
1848 =head2 INCOMPATABILITIES
1849
1850 None
1851
1852 =head2 BUGS AND LIMITATIONS
1853
1854 There are no known bugs in this module.
1855
1856 Please report problems to Andrew DeFaria <Andrew@ClearSCM.com>.
1857
1858 =head2 LICENSE AND COPYRIGHT
1859
1860 Copyright (c) 2007, ClearSCM, Inc. All rights reserved.
1861
1862 =cut