43824e19cf3398a9283d3166294232d1267675e7
[clearscm.git] / lib / Clearcase / UCM / Stream.pm
1 =pod
2
3 =head1 NAME $RCSfile: Stream.pm,v $
4
5 Object oriented interface to UCM Streams
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.8 $
18
19 =item Created
20
21 Fri May 14 18:16:16 PDT 2010
22
23 =item Modified
24
25 $Date: 2011/11/15 02:00:58 $
26
27 =back
28
29 =head1 SYNOPSIS
30
31 Provides access to information about Clearcase Elements.
32
33   my $stream= new Clearcase::UCM::Stream ($name, $pvob);
34
35 =head1 DESCRIPTION
36
37 This module implements a UCM Stream object
38
39 =head1 ROUTINES
40
41 The following routines are exported:
42
43 =cut
44
45 package Clearcase::UCM::Stream;
46
47 use strict;
48 use warnings;
49
50 use Clearcase;
51 use Clearcase::UCM::Baseline;
52
53 sub new ($$) {
54   my ($class, $stream, $pvob) = @_;
55
56 =pod
57
58 =head2 new
59
60 Construct a new Clearcase Stream object.
61
62 Parameters:
63
64 =for html <blockquote>
65
66 =over
67
68 =item stream name
69
70 Name of stream
71
72 =back
73
74 =for html </blockquote>
75
76 Returns:
77
78 =for html <blockquote>
79
80 =over
81
82 =item Clearcase Stream object
83
84 =back
85
86 =for html </blockquote>
87
88 =cut
89
90   my $self = bless {
91     name => $stream,
92     pvob => Clearcase::vobtag $pvob,
93   }, $class; # bless
94     
95   return $self; 
96 } # new
97   
98 sub name () {
99   my ($self) = @_;
100     
101 =pod
102
103 =head2 name
104
105 Returns the name of the stream
106
107 Parameters:
108
109 =for html <blockquote>
110
111 =over
112
113 =item none
114
115 =back
116
117 =for html </blockquote>
118
119 Returns:
120
121 =for html <blockquote>
122
123 =over
124
125 =item stream's name
126
127 =back
128
129 =for html </blockquote>
130
131 =cut
132
133   return $self->{name};
134 } # name
135
136 sub pvob () {
137   my ($self) = @_;
138   
139 =pod
140
141 =head2 pvob
142
143 Returns the pvob of the stream
144
145 Parameters:
146
147 =for html <blockquote>
148
149 =over
150
151 =item none
152
153 =back
154
155 =for html </blockquote>
156
157 Returns:
158
159 =for html <blockquote>
160
161 =over
162
163 =item stream's pvob
164
165 =back
166
167 =for html </blockquote>
168
169 =cut
170
171   return $self->{pvob};
172 } # pvob
173   
174 sub create ($$;$$) {
175   my ($self, $project, $pvob, $baseline, $opts) = @_;
176
177 =pod
178
179 =head2 create
180
181 Creates a new UCM Stream Object
182
183 Parameters:
184
185 =for html <blockquote>
186
187 =over
188
189 =item UCM Project (required)
190
191 UCM Project this stream belongs to
192
193 =item PVOB (Required)
194
195 Project Vob
196
197 =item baseline
198
199 Baseline to set this stream to
200
201 =item opts
202
203 Options: Additional options to use (e.g. -readonly)
204
205 =back
206
207 =for html </blockquote>
208
209 Returns:
210
211 =for html <blockquote>
212
213 =over
214
215 =item $status
216
217 Status from cleartool
218
219 =item @output
220
221 Ouput from cleartool
222
223 =back
224
225 =for html </blockquote>
226
227 =cut
228
229   # Fill in object members
230   $self->{project}  = $project;
231   $self->{pvob}     = $pvob;
232     
233   # Fill in opts   
234   $opts ||= '';
235   $opts .= " -baseline $baseline"
236     if $baseline;  
237       
238   $self->{readonly} = $opts =~ /-readonly/;
239   
240   # TODO: This should call the exists function
241   # Return the stream name if the stream already exists
242   my ($status, @output) = 
243     $Clearcase::CC->execute ('lsstream -short ' . $self->{name}); 
244
245   return ($status, @output)
246     unless $status;
247     
248   # Need to create the stream
249   return $Clearcase::CC->execute 
250     ("mkstream $opts -in " . $self->{project} .
251      "\@"                  . $self->{pvob}    .
252      ' '                   . $self->{name});
253 } # create
254
255 sub remove () {
256   my ($self) = @_;
257
258 =pod
259
260 =head2 remove
261
262 Removes UCM Stream
263
264 Parameters:
265
266 =for html <blockquote>
267
268 =over
269
270 =item UCM Project (required)
271
272 UCM Project this stream belongs to
273
274 =item PVOB (Required)
275
276 Project Vob
277
278 =item baseline
279
280 Baseline to set this stream to
281
282 =item opts
283
284 Options: Additional options to use (e.g. -readonly)
285
286 =back
287
288 =for html </blockquote>
289
290 Returns:
291
292 =for html <blockquote>
293
294 =over
295
296 =item $status
297
298 Status from cleartool
299
300 =item @output
301
302 Ouput from cleartool
303
304 =back
305
306 =for html </blockquote>
307
308 =cut
309
310   return $Clearcase::CC->execute 
311     ('rmstream -f ' . $self->{name} . "\@" . $self->{pvob});
312 } # rmStream
313
314 sub baselines () {
315   my ($self) = @_;
316
317 =pod
318
319 =head2 baselines
320
321 Returns baseline objects associated with the stream
322
323 Parameters:
324
325 =for html <blockquote>
326
327 =over
328
329 =item none
330
331 =back
332
333 =for html </blockquote>
334
335 Returns:
336
337 =for html <blockquote>
338
339 =over
340
341 =item @baselines
342
343 An array of baseline objects for this stream
344
345 =back
346
347 =for html </blockquote>
348
349 =cut
350
351   my $cmd = "lsbl -short -stream $self->{name}\@$self->{pvob}";
352   
353   $Clearcase::CC->execute ($cmd); 
354
355   return if $Clearcase::CC->status;
356
357   my @baselines;
358   
359   foreach ($Clearcase::CC->output) {
360     my $baseline = Clearcase::UCM::Baseline->new ($_, $self->{pvob});
361     
362     push @baselines, $baseline;
363   } # foreach
364   
365   return @baselines;
366 } # baselines
367
368 1;
369
370 =head1 DEPENDENCIES
371
372 =head2 ClearSCM Perl Modules
373
374 =for html <p><a href="/php/cvs_man.php?file=lib/Clearcase.pm">Clearcase</a></p>
375
376 =for html <p><a href="/php/cvs_man.php?file=lib/Clearcase/UCM/Baseline.pm">Clearcase::UCM::Baseline</a></p>
377
378 =head1 INCOMPATABILITIES
379
380 None
381
382 =head1 BUGS AND LIMITATIONS
383
384 There are no known bugs in this module.
385
386 Please report problems to Andrew DeFaria <Andrew@ClearSCM.com>.
387
388 =head1 LICENSE AND COPYRIGHT
389
390 Copyright (c) 2007, ClearSCM, Inc. All rights reserved.
391
392 =cut