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 for ($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 $region ||= $Clearcase::CC->region;
180 $self->updateViewInfo;
192 Returns the user name of the last user to access the view.
196 =for html <blockquote>
204 =for html </blockquote>
208 =for html <blockquote>
216 =for html </blockquote>
220 return $self->{accessed_by};
223 sub accessed_date() {
230 Returns the date the view was last accessed.
234 =for html <blockquote>
242 =for html </blockquote>
246 =for html <blockquote>
254 =for html </blockquote>
258 return $self->{accessed_date};
268 Returns the access path of the view.
272 =for html <blockquote>
280 =for html </blockquote>
284 =for html <blockquote>
292 =for html </blockquote>
296 return $self->{access_path};
306 Returns true if the view is active
310 =for html <blockquote>
318 =for html </blockquote>
322 =for html <blockquote>
330 =for html </blockquote>
334 return $self->{active};
337 sub additional_groups() {
342 =head2 additional_groups
344 Returns the additional groups that have permission to access this
349 =for html <blockquote>
357 =for html </blockquote>
361 =for html <blockquote>
365 =item An array of additional groups
369 =for html </blockquote>
373 if ($self->{additional_groups}) {
374 return @{$self->{additional_groups}};
378 } # additional_groups
387 Returns the user name who created the view
391 =for html <blockquote>
399 =for html </blockquote>
403 =for html <blockquote>
411 =for html </blockquote>
415 return $self->{created_by};
425 Returns the date the view was created.
429 =for html <blockquote>
437 =for html </blockquote>
441 =for html <blockquote>
449 =for html </blockquote>
453 return $self->{created_date};
456 sub cs_updated_by() {
461 =head2 cs_updated_date
463 Returns the user name of the last user to access the view.
467 =for html <blockquote>
475 =for html </blockquote>
479 =for html <blockquote>
487 =for html </blockquote>
491 return $self->{cs_updated_by};
494 sub cs_updated_date() {
501 Returns the date the config spec for this view was updated.
505 =for html <blockquote>
513 =for html </blockquote>
517 =for html <blockquote>
525 =for html </blockquote>
529 return $self->{cs_updated_date};
539 Returns true if the view is a dynamic view - false otherwise.
543 =for html <blockquote>
551 =for html </blockquote>
555 =for html <blockquote>
563 =for html </blockquote>
567 return unless $self->{type};
568 return $self->type eq 'dynamic';
578 Returns the global path to the view
582 =for html <blockquote>
590 =for html </blockquote>
594 =for html <blockquote>
602 =for html </blockquote>
606 return $self->{gpath};
616 Returns the group of the user who created the view.
620 =for html <blockquote>
628 =for html </blockquote>
632 =for html <blockquote>
640 =for html </blockquote>
644 return $self->{group};
654 Returns the group mode of the view.
658 =for html <blockquote>
666 =for html </blockquote>
670 =for html <blockquote>
674 =item A string representing the group mode
678 =for html </blockquote>
682 return $self->{group_mode};
692 Returns the host that the view resides on
696 =for html <blockquote>
704 =for html </blockquote>
708 =for html <blockquote>
716 =for html </blockquote>
720 return $self->{host};
730 Returns the numeric mode representing the view's access mode
734 =for html <blockquote>
742 =for html </blockquote>
746 =for html <blockquote>
754 =for html </blockquote>
758 return $self->{mode};
768 Returns the user name of the last user to modify the view.
772 =for html <blockquote>
780 =for html </blockquote>
784 =for html <blockquote>
792 =for html </blockquote>
796 return $self->{modified_by};
799 sub modified_date() {
806 Returns the date the view was last modified.
810 =for html <blockquote>
818 =for html </blockquote>
822 =for html <blockquote>
830 =for html </blockquote>
834 return $self->{modified_date};
844 Returns the mode for other for the view.
848 =for html <blockquote>
856 =for html </blockquote>
860 =for html <blockquote>
864 =item A string repesenting the other mode
868 =for html </blockquote>
872 return $self->{other_mode};
882 Returns the user name of the owner of the view.
886 =for html <blockquote>
894 =for html </blockquote>
898 =for html <blockquote>
906 =for html </blockquote>
910 return $self->{owner}
920 Returns the mode for the owner for the view.
924 =for html <blockquote>
932 =for html </blockquote>
936 =for html <blockquote>
940 =item A string repesenting the other mode
944 =for html </blockquote>
948 return $self->{owner_mode}
958 Returns the properties of the view.
962 =for html <blockquote>
970 =for html </blockquote>
974 =for html <blockquote>
982 =for html </blockquote>
986 return $self->{properties};
996 Returns the region of the view
1000 =for html <blockquote>
1008 =for html </blockquote>
1012 =for html <blockquote>
1020 =for html </blockquote>
1024 return $self->{region};
1034 Returns the server host of the view
1038 =for html <blockquote>
1046 =for html </blockquote>
1050 =for html <blockquote>
1058 =for html </blockquote>
1062 return $self->{shost};
1072 Returns true if the view is a snapshot view - false otherwise.
1076 =for html <blockquote>
1084 =for html </blockquote>
1088 =for html <blockquote>
1096 =for html </blockquote>
1100 return unless $self->{type};
1101 return $self->type eq 'snapshot';
1111 Returns true if the view is a webview - false otherwise.
1115 =for html <blockquote>
1123 =for html </blockquote>
1127 =for html <blockquote>
1135 =for html </blockquote>
1139 return unless $self->{type};
1140 return $self->{type} eq 'webview';
1150 Returns the tag for this view.
1154 =for html <blockquote>
1162 =for html </blockquote>
1166 =for html <blockquote>
1174 =for html </blockquote>
1178 return $self->{tag};
1188 Returns the text_mode of the view
1192 =for html <blockquote>
1200 =for html </blockquote>
1204 =for html <blockquote>
1212 =for html </blockquote>
1216 return $self->{text_mode};
1226 Returns the type of the view.
1230 =for html <blockquote>
1238 =for html </blockquote>
1242 =for html <blockquote>
1250 =for html </blockquote>
1254 return $self->{type};
1264 Returns true if the view is a UCM view.
1268 =for html <blockquote>
1276 =for html </blockquote>
1280 =for html <blockquote>
1288 =for html </blockquote>
1292 return $self->{ucm};
1302 Returns the uuid for the view.
1306 =for html <blockquote>
1314 =for html </blockquote>
1318 =for html <blockquote>
1326 =for html </blockquote>
1330 return $self->{uuid};
1340 Returns true if the view exists - false otherwise.
1344 =for html <blockquote>
1352 =for html </blockquote>
1356 =for html <blockquote>
1364 =for html </blockquote>
1368 my ($status, @output) = $Clearcase::CC->execute("lsview -region $self->{region} $self->{tag}");
1374 my ($self, $host, $vws, $region) = @_;
1384 =for html <blockquote>
1390 Host to create the view on. Default is to use -stgloc -auto.
1394 View working storage directory to use. Default is to use -stgloc -auto.
1398 =for html </blockquote>
1402 =for html <blockquote>
1408 Status from cleartool
1412 Ouput from cleartool
1416 =for html </blockquote>
1420 $region ||= $Clearcase::CC->region;
1422 if ($self->exists) {
1423 $self->updateViewInfo;
1428 my ($status, @output);
1430 if ($host && $vws) {
1431 ($status, @output) =
1432 $Clearcase::CC->execute("mkview -tag $self->{tag} -region $region "
1433 . "-host $host -hpath $vws -gpath $vws $vws");
1435 # Note this requires that -stgloc's work and that using -auto is not a
1437 ($status, @output) =
1438 $Clearcase::CC->execute("mkview -tag $self->{tag} -stgloc -auto");
1441 $self->updateViewInfo;
1443 return ($status, @output);
1447 my ($self, $stream, $pvob, $region) = @_;
1457 =for html <blockquote>
1463 Name of stream to attach new view to
1471 =for html </blockquote>
1475 =for html <blockquote>
1489 =for html </blockquote>
1493 $region ||= $Clearcase::CC->region;
1498 # Update object members
1499 $self->{stream} = $stream;
1500 $self->{pvob} = $pvob;
1502 # Need to create the view
1503 my ($status, @output) =
1504 $Clearcase::CC->execute("mkview -tag $self->{tag} -stream "
1505 . "$self->{stream}\@$self->{pvob} -stgloc -auto");
1507 return ($status, @output)
1510 $self->updateViewInfo;
1512 return ($status, @output);
1526 =for html <blockquote>
1534 =for html </blockquote>
1538 =for html <blockquote>
1544 Status from cleartool
1548 Ouput from cleartool
1552 =for html </blockquote>
1557 unless $self->exists;
1559 my ($status, @output);
1561 if ($self->dynamic) {
1562 ($status, @output) = $Clearcase::CC->execute(
1563 "rmview -force -tag $self->{tag}"
1566 error 'Removal of snapshot views not implemented yet', 1;
1567 #($status, @output) = $Clearcase::CC->execute(
1568 # "rmview -force $self->{snapshot_view_pname}"
1572 return ($status, @output);
1586 =for html <blockquote>
1594 =for html </blockquote>
1598 =for html <blockquote>
1604 Status from cleartool
1608 Ouput from cleartool
1612 =for html </blockquote>
1616 return $Clearcase::CC->execute("startview $self->{tag}");
1630 =for html <blockquote>
1638 =for html </blockquote>
1642 =for html <blockquote>
1648 Status from cleartool
1652 Ouput from cleartool
1656 =for html </blockquote>
1660 return $Clearcase::CC->execute("endview $self->{tag}");
1670 Stops the view at the view_server process if nobody else is accessing the view.
1674 =for html <blockquote>
1682 =for html </blockquote>
1686 =for html <blockquote>
1692 Status from cleartool
1696 Ouput from cleartool
1700 =for html </blockquote>
1704 return $Clearcase::CC->execute("endview -server $self->{tag}");
1714 Starts the view then changes directory the to view's root.
1718 =for html <blockquote>
1726 =for html </blockquote>
1730 =for html <blockquote>
1736 Status from cleartool
1740 Ouput from cleartool
1744 =for html </blockquote>
1748 my ($status, @output) = $self->start;
1750 chdir "$Clearcase::VIEWTAG_PREFIX/$self->{tag}";
1752 return ($status, @output);
1755 sub updateViewInfo($$) {
1758 my ($status, @output) = $Clearcase::CC->execute(
1759 "lsview -region $self->{region} -long -properties -full $self->{tag}"
1764 # Assuming this view is an empty shell of an object that the user may possibly
1765 # use the create method on, return our blessings...
1767 # No longer assume that. Could equally be the case where the view server
1768 # failed to respond. Carry on then...return if $status != 0;
1771 $self->{type} = 'dynamic';
1773 $self->{additional_groups} = '';
1776 if (/Global path: (.*)/) {
1777 $self->{gpath} = $1;
1778 } elsif (/Server host: (.*)/) {
1779 $self->{shost} = $1;
1780 } elsif (/Region: (.*)/) {
1781 $self->{region} = $1;
1782 } elsif (/Active: (.*)/) {
1783 $self->{active} = ($1 eq 'YES') ? 1 : 0;
1784 } elsif (/View uuid: (.*)/) {
1786 } elsif (/View on host: (.*)/) {
1788 } elsif (/View server access path: (.*)/) {
1789 $self->{access_path} = $1;
1790 } elsif (/View attributes: (.*)/) {
1791 my $view_attributes = $1;
1792 $self->{type} = $view_attributes =~ /webview/
1794 : $view_attributes =~ /snapshot/
1797 $self->{ucm} = $view_attributes =~ /ucmview/
1800 } elsif (/Created (\S+) by (.+)/) {
1801 $self->{created_date} = $1;
1802 $self->{created_by} = $2;
1803 } elsif (/Last modified (\S+) by (.+)/) {
1804 $self->{modified_date} = $1;
1805 $self->{modified_by} = $2;
1806 } elsif (/Last accessed (\S+) by (.+)/) {
1807 $self->{accessed_date} = $1;
1808 $self->{accessed_by} = $2;
1809 } elsif (/Last config spec update (\S+) by (.+)/) {
1810 $self->{cs_updated_date} = $1;
1811 $self->{cs_updated_by} = $2;
1812 } elsif (/Text mode: (\S+)/) {
1813 $self->{text_mode} = $1;
1814 } elsif (/Properties: (.*)/) {
1815 $self->{properties} = $1;
1816 } elsif (/View owner: (\S+)$/) {
1817 # It is possible that there may be problems enumerating
1818 # -properties and -full when listing views due to servers
1819 # no longer being available. Still the "View owner" line
1820 # denotes the view's owner.
1821 $self->{owner} = $1;
1822 $self->{owner_mode} = '';
1823 } elsif (/Owner: (\S+)\s+: (\S+)/) {
1824 $self->{owner} = $1;
1825 $self->{owner_mode} = $2;
1826 } elsif (/Group: (.+)\s+:\s+(\S+)\s+/) {
1827 $self->{group} = $1;
1828 $self->{group_mode} = $2;
1829 } elsif (/Other:\s+: (\S+)/) {
1830 $self->{other_mode} = $1;
1831 } elsif (/Additional groups: (.*)/) {
1832 my @additional_groups = split /\s+/, $1;
1833 $self->{additional_groups} = \@additional_groups;
1837 # Change modes to numeric
1840 if ($self->{owner_mode}) {
1841 $self->{mode} += 400 if $self->{owner_mode} =~ /r/;
1842 $self->{mode} += 200 if $self->{owner_mode} =~ /w/;
1843 $self->{mode} += 100 if $self->{owner_mode} =~ /x/;
1844 $self->{mode} += 40 if $self->{group_mode} =~ /r/;
1845 $self->{mode} += 20 if $self->{group_mode} =~ /w/;
1846 $self->{mode} += 10 if $self->{group_mode} =~ /x/;
1847 $self->{mode} += 4 if $self->{other_mode} =~ /r/;
1848 $self->{mode} += 2 if $self->{other_mode} =~ /w/;
1849 $self->{mode} += 1 if $self->{other_mode} =~ /x/;
1855 sub viewPrivateStorage() {
1860 =head1 viewPrivateStorage
1862 Returns the view private storage size for this view.
1866 =for html <blockquote>
1874 =for html </blockquote>
1878 =for html <blockquote>
1882 =item view private storage
1886 =for html </blockquote>
1890 $self->updateViewSpace unless ($self->{viewPrivateStorage});
1892 return $self->{viewPrivateStorage};
1893 } # viewPrivateStorage
1895 sub viewPrivateStoragePct() {
1900 =head1 viewPrivateStoragePct
1902 Returns the view private storage percent for this view.
1906 =for html <blockquote>
1914 =for html </blockquote>
1918 =for html <blockquote>
1922 =item view private storage
1926 =for html </blockquote>
1930 $self->updateViewSpace unless ($self->{viewPrivateStoragePct});
1932 return $self->{viewPrivateStoragePct};
1933 } # viewPrivateStoragePct
1935 sub viewDatabase() {
1942 Returns the view database size for this view.
1946 =for html <blockquote>
1954 =for html </blockquote>
1958 =for html <blockquote>
1962 =item view database size
1966 =for html </blockquote>
1970 $self->updateViewSpace unless ($self->{viewDatabase});
1972 return $self->{viewDatabase};
1975 sub viewDatabasePct() {
1980 =head1 viewDatabasePct
1982 Returns the view database percent for this view.
1986 =for html <blockquote>
1994 =for html </blockquote>
1998 =for html <blockquote>
2002 =item view database percent
2006 =for html </blockquote>
2010 $self->updateViewSpace unless ($self->{viewDatabasePct});
2012 return $self->{viewDatabasePct};
2022 Returns the view admin size for this view.
2026 =for html <blockquote>
2034 =for html </blockquote>
2038 =for html <blockquote>
2042 =item view admin size
2046 =for html </blockquote>
2050 $self->updateViewSpace unless ($self->{viewAdmin});
2052 return $self->{viewAdmin};
2055 sub viewAdminPct() {
2062 Returns the view admin percent for this view.
2066 =for html <blockquote>
2074 =for html </blockquote>
2078 =for html <blockquote>
2082 =item view admin percent
2086 =for html </blockquote>
2090 $self->updateViewSpace unless ($self->{viewAdminPct});
2092 return $self->{viewAdminPct};
2102 Returns the view total size for this view.
2106 =for html <blockquote>
2114 =for html </blockquote>
2118 =for html <blockquote>
2126 =for html </blockquote>
2130 $self->updateViewSpace unless ($self->{viewSpace});
2132 return $self->{viewSpace};
2135 sub viewSpacePct() {
2142 Returns the view database percent for this view.
2146 =for html <blockquote>
2154 =for html </blockquote>
2158 =for html <blockquote>
2162 =item view space percent
2166 =for html </blockquote>
2170 $self->updateViewSpace unless ($self->{viewSpacePct});
2172 return $self->{viewSpacePct};
2175 sub updateViewSpace() {
2178 my ($status, @output) = $Clearcase::CC->execute(
2179 "space -region $self->{region} -view $self->{tag}"
2182 $self->{viewPrivateStorage} = 0.0;
2183 $self->{viewPrivateStoragePct} = '0%';
2184 $self->{viewAdmin} = 0.0;
2185 $self->{viewAdminPct} = '0%';
2186 $self->{viewDatabase} = 0.0;
2187 $self->{viewDatabasePct} = '0%';
2188 $self->{viewSpace} = 0.0;
2189 $self->{viewSpacePct} = '0%';
2192 if (/\s*(\S+)\s*(\S+)\s*View private storage/) {
2193 $self->{viewPrivateStorage} = $1;
2194 $self->{viewPrivateStoragePct} = $2;
2195 } elsif (/\s*(\S+)\s*(\S+)\s*View database/) {
2196 $self->{viewDatabase} = $1;
2197 $self->{viewDatabasePct} = $2;
2198 } elsif (/\s*(\S+)\s*(\S+)\s*View administration/) {
2199 $self->{viewAdmin} = $1;
2200 $self->{viewAdminPct} = $2;
2201 } elsif (/\s*(\S+)\s*(\S+)\s*Subtotal/) {
2202 $self->{viewSpace} = $1;
2203 $self->{viewSpacePct} = $2;
2216 =for html <p><a href="/php/scm_man.php?file=lib/Clearcase.pm">Clearcase</a></p>
2218 =head2 INCOMPATABILITIES
2222 =head2 BUGS AND LIMITATIONS
2224 There are no known bugs in this module.
2226 Please report problems to Andrew DeFaria <Andrew@ClearSCM.com>.
2228 =head2 LICENSE AND COPYRIGHT
2230 Copyright (c) 2007, ClearSCM, Inc. All rights reserved.