ef07cbd8c9be3a290514b222e965e5acbfeaf251
[clearscm.git] / lib / Clearcase / Views.pm
1 =pod
2
3 =head1 NAME $RCSfile: Views.pm,v $
4
5 Object oriented interface to Clearcase Views
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.12 $
18
19 =item Created
20
21 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 Clearcase Views.
32
33  my $views = new Clearcase::Views;
34
35  my $nbr_views  = $views->views;
36  my @view_list  = $views->views;
37
38  display "Clearcase Views\n";
39
40  display "Number of views:\t\t" . $nbr_views;
41  display "View list:\n";
42
43  display "\t$_" foreach (@view_list);
44
45 =head1 DESCRIPTION
46
47 This module implements an object oriented interface to Clearcase
48 views.
49
50 =head1 ROUTINES
51
52 The following routines are exported:
53
54 =cut
55
56 package Clearcase::Views;
57
58 use strict;
59 use warnings;
60
61 use Clearcase;
62
63 sub new (;$) {
64   my ($class, $region) = @_;
65     
66 =pod
67
68 =head2 new
69
70 Construct a new Clearcase Views object. 
71
72 Parameters:
73
74 =for html <blockquote>
75
76 =over
77
78 =item none
79
80 =back
81
82 =for html </blockquote>
83
84 Returns:
85
86 =for html <blockquote>
87
88 =over
89
90 =item Clearcase Views object
91
92 =back
93
94 =for html </blockquote>
95
96 =cut
97
98   $region ||= $Clearcase::CC->region;
99
100   my ($status, @output) = 
101     $Clearcase::CC->execute ("lsview -short -region $region");
102
103   $class = bless {
104     views => \@output,
105   }, $class; # bless
106    
107   return $class;
108 } # new
109
110 sub views () {
111   my ($self) = @_;
112
113 =pod
114
115 =head2 views
116
117 Return a list of view tags in an array context or the number of views in
118 a scalar context.
119
120 Parameters:
121
122 =for html <blockquote>
123
124 =over
125
126 =item none
127
128 =back
129
130 =for html </blockquote>
131
132 Returns:
133
134 =for html <blockquote>
135
136 =over
137
138 =item List of views or number of views
139
140 Array of view tags in an array context or the number of views in a scalar context.
141
142 =back
143
144 =for html </blockquote>
145
146 =cut
147
148   if (wantarray) {
149     return $self->{views} ? sort @{$self->{views}} : ();
150   } else {
151     return $self->{views} ? scalar @{$self->{views}} : 0;
152   } #if
153 } # views
154
155 sub dynamic () {
156   my ($self) = @_;
157
158 =pod
159
160 =head2 dynamic
161
162 Return the number of dynamic views
163
164 Parameters:
165
166 =for html <blockquote>
167
168 =over
169
170 =item none
171
172 =back
173
174 =for html </blockquote>
175
176 Returns:
177
178 =for html <blockquote>
179
180 =over
181
182 =item number of dynamic views
183
184 Returns the number of dynamic views in the region
185
186 =back
187
188 =for html </blockquote>
189
190 =cut
191
192   $self->updateViewInfo if !defined $self->{dynamic};
193   return $self->{dynamic};
194 } # dynamic
195
196 sub ucm () {
197   my ($self) = @_;
198
199 =pod
200
201 =head2 ucm
202
203 Return the number of ucm views
204
205 Parameters:
206
207 =for html <blockquote>
208
209 =over
210
211 =item none
212
213 =back
214
215 =for html </blockquote>
216
217 Returns:
218
219 =for html <blockquote>
220
221 =over
222
223 =item number of ucm views
224
225 Returns the number of ucm views in the region
226
227 =back
228
229 =for html </blockquote>
230
231 =cut
232
233   $self->updateViewInfo if !defined $self->{ucm};
234   return $self->{ucm};
235 } # ucm
236
237 sub snapshot () {
238   my ($self) = @_;
239
240 =pod
241
242 =head2 snapshot
243
244 Return the number of snapshot views
245
246 Parameters:
247
248 =for html <blockquote>
249
250 =over
251
252 =item none
253
254 =back
255
256 =for html </blockquote>
257
258 Returns:
259
260 =for html <blockquote>
261
262 =over
263
264 =item number of snapshot views
265
266 Returns the number of snapshot views in the region
267
268 =back
269
270 =for html </blockquote>
271
272 =cut
273
274   $self->updateViewInfo if !defined $self->{snapshot};
275   return $self->{snapshot};
276 } # snapshot
277
278 sub web () {
279   my ($self) = @_;
280
281 =pod
282
283 =head2 web
284
285 Return the number of web views
286
287 Parameters:
288
289 =for html <blockquote>
290
291 =over
292
293 =item none
294
295 =back
296
297 =for html </blockquote>
298
299 Returns:
300
301 =for html <blockquote>
302
303 =over
304
305 =item number of web views
306
307 Returns the number of web views in the region
308
309 =back
310
311 =for html </blockquote>
312
313 =cut
314
315   $self->updateViewInfo if !defined $self->{web};
316   return $self->{web};
317 } # web
318
319 sub updateViewInfo ($) {
320   my ($self) = @_;
321
322   my ($dynamic, $web, $ucm, $snapshot) = (0, 0, 0, 0);
323
324   foreach ($self->views) {
325     my ($status, @lsview_out) = $Clearcase::CC->execute ("lsview -properties -full $_");
326
327     next
328       if $status;
329
330     foreach (@lsview_out) {
331       if (/Properties/) {
332         $dynamic++
333           if /dynamic/;
334             $snapshot++
335               if /snapshot/ and not /webview/;
336             $ucm++
337               if /ucmview/;
338             $web++
339           if /webview/;
340             last;
341       } # if
342     } # foreach
343
344     $self->{dynamic}  = $dynamic;
345     $self->{web}      = $web;
346     $self->{ucm}      = $ucm;
347     $self->{snapshot} = $snapshot;
348   } # foreach
349   
350   return
351 } # updateViewInfo
352
353 1;
354
355 =head1 DEPENDENCIES
356
357 =for html <p><a href="/php/cvs_man.php?file=lib/Clearcase.pm">Clearcase</a></p>
358
359 =head1 INCOMPATABILITIES
360
361 None
362
363 =head1 BUGS AND LIMITATIONS
364
365 There are no known bugs in this module.
366
367 Please report problems to Andrew DeFaria <Andrew@ClearSCM.com>.
368
369 =head1 LICENSE AND COPYRIGHT
370
371 Copyright (c) 2007, ClearSCM, Inc. All rights reserved.
372
373 =cut