3 =head1 NAME $RCSfile: View.pm,v $
5 Object oriented interface to a Clearcase View
13 Andrew DeFaria <Andrew@ClearSCM.com>
21 Thu Dec 29 12:07:59 PST 2005
25 $Date: 2011/11/16 19:46:13 $
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.
38 my $view = new Clearcase::View (tag => 'test');
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;
47 display_nolf MAGENTA . "Additional groups:\t";
49 foreach ($view->additional_groups) {
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;
75 display_nolf "Type:\t\t\t";
77 if ($view->snapshot) {
78 display_nolf 'snapshot';
80 display_nolf 'dynamic';
90 my $new_view = new Clearcase::View ($ENV{USER} . '_testview');
103 # Stop view server process
107 if ($new_view->exists) {
113 This module implements an object oriented interface to a Clearcase
118 The following routines are exported:
122 package Clearcase::View;
131 my ($class, $tag, $region) = @_;
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.
143 =for html <blockquote>
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.
157 =for html </blockquote>
161 =for html <blockquote>
165 =item Clearcase View object
169 =for html </blockquote>
173 my $self = bless { tag => $tag }, $class;
175 $self->updateViewInfo ($region);
187 Returns the user name of the last user to access the view.
191 =for html <blockquote>
199 =for html </blockquote>
203 =for html <blockquote>
211 =for html </blockquote>
215 return $self->{accessed_by};
218 sub accessed_date () {
225 Returns the date the view was last accessed.
229 =for html <blockquote>
237 =for html </blockquote>
241 =for html <blockquote>
249 =for html </blockquote>
253 return $self->{accessed_date};
263 Returns the access path of the view.
267 =for html <blockquote>
275 =for html </blockquote>
279 =for html <blockquote>
287 =for html </blockquote>
291 return $self->{access_path};
301 Returns true if the view is active
305 =for html <blockquote>
313 =for html </blockquote>
317 =for html <blockquote>
325 =for html </blockquote>
329 return $self->{active};
332 sub additional_groups () {
337 =head2 additional_groups
339 Returns the additional groups that have permission to access this
344 =for html <blockquote>
352 =for html </blockquote>
356 =for html <blockquote>
360 =item An array of additional groups
364 =for html </blockquote>
368 if ($self->{additional_groups}) {
369 return @{$self->{additional_groups}};
373 } # additional_groups
382 Returns the user name who created the view
386 =for html <blockquote>
394 =for html </blockquote>
398 =for html <blockquote>
406 =for html </blockquote>
410 return $self->{created_by};
413 sub created_date () {
420 Returns the date the view was created.
424 =for html <blockquote>
432 =for html </blockquote>
436 =for html <blockquote>
444 =for html </blockquote>
448 return $self->{created_date};
451 sub cs_updated_by () {
456 =head2 cs_updated_date
458 Returns the user name of the last user to access the view.
462 =for html <blockquote>
470 =for html </blockquote>
474 =for html <blockquote>
482 =for html </blockquote>
486 return $self->{cs_updated_by};
489 sub cs_updated_date () {
496 Returns the date the config spec for this view was updated.
500 =for html <blockquote>
508 =for html </blockquote>
512 =for html <blockquote>
520 =for html </blockquote>
524 return $self->{cs_updated_date};
534 Returns true if the view is a dynamic view - false otherwise.
538 =for html <blockquote>
546 =for html </blockquote>
550 =for html <blockquote>
558 =for html </blockquote>
562 return $self->type eq 'dynamic';
572 Returns the global path to the view
576 =for html <blockquote>
584 =for html </blockquote>
588 =for html <blockquote>
596 =for html </blockquote>
600 return $self->{gpath};
610 Returns the group of the user who created the view.
614 =for html <blockquote>
622 =for html </blockquote>
626 =for html <blockquote>
634 =for html </blockquote>
638 return $self->{group};
648 Returns the group mode of the view.
652 =for html <blockquote>
660 =for html </blockquote>
664 =for html <blockquote>
668 =item A string representing the group mode
672 =for html </blockquote>
676 return $self->{group_mode};
686 Returns the host that the view resides on
690 =for html <blockquote>
698 =for html </blockquote>
702 =for html <blockquote>
710 =for html </blockquote>
714 return $self->{host};
724 Returns the numeric mode representing the view's access mode
728 =for html <blockquote>
736 =for html </blockquote>
740 =for html <blockquote>
748 =for html </blockquote>
752 return $self->{mode};
762 Returns the user name of the last user to modify the view.
766 =for html <blockquote>
774 =for html </blockquote>
778 =for html <blockquote>
786 =for html </blockquote>
790 return $self->{modified_by};
793 sub modified_date () {
800 Returns the date the view was last modified.
804 =for html <blockquote>
812 =for html </blockquote>
816 =for html <blockquote>
824 =for html </blockquote>
828 return $self->{modified_date};
838 Returns the mode for other for the view.
842 =for html <blockquote>
850 =for html </blockquote>
854 =for html <blockquote>
858 =item A string repesenting the other mode
862 =for html </blockquote>
866 return $self->{other_mode};
876 Returns the user name of the owner of the view.
880 =for html <blockquote>
888 =for html </blockquote>
892 =for html <blockquote>
900 =for html </blockquote>
904 return $self->{owner}
914 Returns the mode for the owner for the view.
918 =for html <blockquote>
926 =for html </blockquote>
930 =for html <blockquote>
934 =item A string repesenting the other mode
938 =for html </blockquote>
942 return $self->{owner_mode}
952 Returns the properties of the view.
956 =for html <blockquote>
964 =for html </blockquote>
968 =for html <blockquote>
976 =for html </blockquote>
980 return $self->{properties};
990 Returns the region of the view
994 =for html <blockquote>
1002 =for html </blockquote>
1006 =for html <blockquote>
1014 =for html </blockquote>
1018 return $self->{region};
1028 Returns the server host of the view
1032 =for html <blockquote>
1040 =for html </blockquote>
1044 =for html <blockquote>
1052 =for html </blockquote>
1056 return $self->{shost};
1066 Returns true if the view is a snapshot view - false otherwise.
1070 =for html <blockquote>
1078 =for html </blockquote>
1082 =for html <blockquote>
1090 =for html </blockquote>
1094 return $self->type eq 'snapshot';
1104 Returns true if the view is a webview - false otherwise.
1108 =for html <blockquote>
1116 =for html </blockquote>
1120 =for html <blockquote>
1128 =for html </blockquote>
1132 return $self->type eq 'webview';
1142 Returns the tag for this view.
1146 =for html <blockquote>
1154 =for html </blockquote>
1158 =for html <blockquote>
1166 =for html </blockquote>
1170 return $self->{tag};
1180 Returns the text_mode of the view
1184 =for html <blockquote>
1192 =for html </blockquote>
1196 =for html <blockquote>
1204 =for html </blockquote>
1208 return $self->{text_mode};
1218 Returns the type of the view.
1222 =for html <blockquote>
1230 =for html </blockquote>
1234 =for html <blockquote>
1242 =for html </blockquote>
1246 return $self->{type} ? $self->{type} : 'Unknown';
1256 Returns true if the view is a UCM view.
1260 =for html <blockquote>
1268 =for html </blockquote>
1272 =for html <blockquote>
1280 =for html </blockquote>
1284 return $self->{ucm};
1294 Returns the uuid for the view.
1298 =for html <blockquote>
1306 =for html </blockquote>
1310 =for html <blockquote>
1318 =for html </blockquote>
1322 return $self->{uuid};
1332 Returns true if the view exists - false otherwise.
1336 =for html <blockquote>
1344 =for html </blockquote>
1348 =for html <blockquote>
1356 =for html </blockquote>
1360 my ($status, @output) = $Clearcase::CC->execute ("lsview $self->{tag}");
1366 my ($self, $host, $vws, $region) = @_;
1376 =for html <blockquote>
1382 Host to create the view on. Default is to use -stgloc -auto.
1386 View working storage directory to use. Default is to use -stgloc -auto.
1390 =for html </blockquote>
1394 =for html <blockquote>
1400 Status from cleartool
1404 Ouput from cleartool
1408 =for html </blockquote>
1412 $region ||= $Clearcase::CC->region;
1414 if ($self->exists) {
1415 $self->updateViewInfo ($region);
1420 my ($status, @output);
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");
1427 # Note this requires that -stgloc's work and that using -auto is not a
1429 ($status, @output) =
1430 $Clearcase::CC->execute ("mkview -tag $self->{tag} -stgloc -auto");
1433 $self->updateViewInfo ($region);
1435 return ($status, @output);
1438 sub createUCM ($$) {
1439 my ($self, $stream, $pvob, $region) = @_;
1449 =for html <blockquote>
1455 Name of stream to attach new view to
1463 =for html </blockquote>
1467 =for html <blockquote>
1481 =for html </blockquote>
1485 $region ||= $Clearcase::CC->region;
1490 # Update object members
1491 $self->{stream} = $stream;
1492 $self->{pvob} = $pvob;
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");
1499 return ($status, @output)
1502 $self->updateViewInfo ($region);
1504 return ($status, @output);
1518 =for html <blockquote>
1526 =for html </blockquote>
1530 =for html <blockquote>
1536 Status from cleartool
1540 Ouput from cleartool
1544 =for html </blockquote>
1549 unless $self->exists;
1551 my ($status, @output);
1553 if ($self->dynamic) {
1554 ($status, @output) = $Clearcase::CC->execute (
1555 "rmview -force -tag $self->{tag}"
1558 error 'Removal of snapshot views not implemented yet', 1;
1559 #($status, @output) = $Clearcase::CC->execute (
1560 # "rmview -force $self->{snapshot_view_pname}"
1564 return ($status, @output);
1578 =for html <blockquote>
1586 =for html </blockquote>
1590 =for html <blockquote>
1596 Status from cleartool
1600 Ouput from cleartool
1604 =for html </blockquote>
1608 return $Clearcase::CC->execute ("startview $self->{tag}");
1622 =for html <blockquote>
1630 =for html </blockquote>
1634 =for html <blockquote>
1640 Status from cleartool
1644 Ouput from cleartool
1648 =for html </blockquote>
1652 return $Clearcase::CC->execute ("endview $self->{tag}");
1662 Stops the view at the view_server process if nobody else is accessing the view.
1666 =for html <blockquote>
1674 =for html </blockquote>
1678 =for html <blockquote>
1684 Status from cleartool
1688 Ouput from cleartool
1692 =for html </blockquote>
1696 return $Clearcase::CC->execute ("endview -server $self->{tag}");
1706 Starts the view then changes directory the to view's root.
1710 =for html <blockquote>
1718 =for html </blockquote>
1722 =for html <blockquote>
1728 Status from cleartool
1732 Ouput from cleartool
1736 =for html </blockquote>
1740 my ($status, @output) = $self->start;
1742 chdir "$Clearcase::VIEWTAG_PREFIX/$self->{tag}";
1744 return ($status, @output);
1747 sub updateViewInfo ($$) {
1748 my ($self, $region) = @_;
1750 $region ||= $Clearcase::CC->region;
1752 my ($status, @output) = $Clearcase::CC->execute (
1753 "lsview -region $region -long -properties -full $self->{tag}"
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...
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;
1763 $self->{type} = 'dynamic';
1765 $self->{additional_groups} = '';
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: (.*)/) {
1778 } elsif (/View on host: (.*)/) {
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/
1786 : $view_attributes =~ /snapshot/
1789 $self->{ucm} = $view_attributes =~ /ucmview/
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;
1822 # Change modes to numeric
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/;
1846 =for html <p><a href="/php/cvs_man.php?file=lib/Clearcase.pm">Clearcase</a></p>
1848 =head2 INCOMPATABILITIES
1852 =head2 BUGS AND LIMITATIONS
1854 There are no known bugs in this module.
1856 Please report problems to Andrew DeFaria <Andrew@ClearSCM.com>.
1858 =head2 LICENSE AND COPYRIGHT
1860 Copyright (c) 2007, ClearSCM, Inc. All rights reserved.