More changes from GD development
[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 Streams.
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 sub new ($$) {
51   my ($class, $name, $pvob) = @_;
52
53 =pod
54
55 =head2 new
56
57 Construct a new Clearcase Stream object.
58
59 Parameters:
60
61 =for html <blockquote>
62
63 =over
64
65 =item name
66
67 Name of stream
68
69 =item pvob
70
71 Associated pvob
72
73 =back
74
75 =for html </blockquote>
76
77 Returns:
78
79 =for html <blockquote>
80
81 =over
82
83 =item Clearcase Stream object
84
85 =back
86
87 =for html </blockquote>
88
89 =cut
90
91   $class = bless {
92     name => $name,
93     pvob => $pvob,
94   }, $class; # bless
95
96   return $class; 
97 } # new
98
99 sub name () {
100   my ($self) = @_;
101
102 =pod
103
104 =head2 name
105
106 Returns the name of the stream
107
108 Parameters:
109
110 =for html <blockquote>
111
112 =over
113
114 =item none
115
116 =back
117
118 =for html </blockquote>
119
120 Returns:
121
122 =for html <blockquote>
123
124 =over
125
126 =item stream's name
127
128 =back
129
130 =for html </blockquote>
131
132 =cut
133
134   return $self->{name};
135 } # name
136
137 sub pvob () {
138   my ($self) = @_;
139
140 =pod
141
142 =head2 pvob
143
144 Returns the pvob of the stream
145
146 Parameters:
147
148 =for html <blockquote>
149
150 =over
151
152 =item none
153
154 =back
155
156 =for html </blockquote>
157
158 Returns:
159
160 =for html <blockquote>
161
162 =over
163
164 =item stream's pvob
165
166 =back
167
168 =for html </blockquote>
169
170 =cut
171
172   return $self->{pvob};
173 } # pvob
174
175 sub create ($;$) {
176   my ($self, $project, $opts) = @_;
177
178 =pod
179
180 =head2 create
181
182 Creates a new UCM Stream Object
183
184 Parameters:
185
186 =for html <blockquote>
187
188 =over
189
190 =item project
191
192 Project that this stream will be created in
193
194 =item opts
195
196 Options: Additional options to use (e.g. -baseline/-readonly)
197
198 =back
199
200 =for html </blockquote>
201
202 Returns:
203
204 =for html <blockquote>
205
206 =over
207
208 =item $status
209
210 Status from cleartool
211
212 =item @output
213
214 Ouput from cleartool
215
216 =back
217
218 =for html </blockquote>
219
220 =cut
221
222   return (0, ()) if $self->exists;
223
224   $opts ||= '';
225
226   $self->{readonly} = $opts =~ /-readonly/;
227
228   return $Clearcase::CC->execute(
229     "mkstream $opts -in "
230        . $project->name . '@' . $self->{pvob}->tag . ' '
231        . $self->name    . '@' . $self->{pvob}->tag
232   );
233 } # create
234
235 sub remove () {
236   my ($self) = @_;
237
238 =pod
239
240 =head2 remove
241
242 Removes UCM Stream
243
244 Parameters:
245
246 =for html <blockquote>
247
248 =over
249
250 =back
251
252 =for html </blockquote>
253
254 Returns:
255
256 =for html <blockquote>
257
258 =over
259
260 =item $status
261
262 Status from cleartool
263
264 =item @output
265
266 Ouput from cleartool
267
268 =back
269
270 =for html </blockquote>
271
272 =cut
273
274   return $Clearcase::CC->execute 
275     ('rmstream -f ' . $self->{name} . '@' . $self->{pvob}->name);
276 } # rmStream
277
278 sub rebase($;$) {
279   my ($self, $opts) = @_;
280
281 =pod
282
283 =head2 rebase
284
285 Rebases a UCM Stream
286
287 Parameters:
288
289 =for html <blockquote>
290
291 =over
292
293 =item baseline
294
295 Baseline to rebase to
296
297 =item opts
298
299 Any additional opts
300
301 =back
302
303 =for html </blockquote>
304
305 Returns:
306
307 =for html <blockquote>
308
309 =over
310
311 =item $status
312
313 Status from cleartool
314
315 =item @output
316
317 Ouput from cleartool
318
319 =back
320
321 =for html </blockquote>
322
323 =cut
324
325   $opts ||= '';
326
327   $opts .= ' -stream '   . $self->name . '@' . $self->{pvob}->name;
328
329   return $Clearcase::CC->execute("rebase $opts");
330 } # rebase
331
332 sub recommend($) {
333   my ($self, $baseline) = @_;
334
335 =pod
336
337 =head2 recommend
338
339 Recommends a baseline in a UCM Stream
340
341 Parameters:
342
343 =for html <blockquote>
344
345 =over
346
347 =item baseline
348
349 Baseline to recommend
350
351 =back
352
353 =for html </blockquote>
354
355 Returns:
356
357 =for html <blockquote>
358
359 =over
360
361 =item $status
362
363 Status from cleartool
364
365 =item @output
366
367 Ouput from cleartool
368
369 =back
370
371 =for html </blockquote>
372
373 =cut
374
375   return $Clearcase::CC->execute(
376     "chstream -recommended $baseline " . $self->name . '@' . $self->{pvob}->tag
377   );
378 } # recommend
379
380 sub nrecommended() {
381   my ($self) = @_;
382
383 =pod
384
385 =head2 nrecommend
386
387 Changes stream to not have a recommended baseline
388
389 Parameters:
390
391 =for html <blockquote>
392
393 =over
394
395 =item none
396
397 =back
398
399 =for html </blockquote>
400
401 Returns:
402
403 =for html <blockquote>
404
405 =over
406
407 =item $status
408
409 Status from cleartool
410
411 =item @output
412
413 Ouput from cleartool
414
415 =back
416
417 =for html </blockquote>
418
419 =cut
420
421   return $Clearcase::CC->execute(
422     'chstream -nrecommended ' . $self->name . '@' . $self->{pvob}->tag
423   );
424 } # nrecommended
425
426 sub baselines () {
427   my ($self) = @_;
428
429 =pod
430
431 =head2 baselines
432
433 Returns baseline objects associated with the stream
434
435 Parameters:
436
437 =for html <blockquote>
438
439 =over
440
441 =item none
442
443 =back
444
445 =for html </blockquote>
446
447 Returns:
448
449 =for html <blockquote>
450
451 =over
452
453 =item @baselines
454
455 An array of baseline objects for this stream
456
457 =back
458
459 =for html </blockquote>
460
461 =cut
462
463   my $cmd = "lsbl -short -stream $self->{name}\@$self->{pvob}";
464
465   $Clearcase::CC->execute ($cmd); 
466
467   return if $Clearcase::CC->status;
468
469   my @baselines;
470
471   for ($Clearcase::CC->output) {
472     my $baseline = Clearcase::UCM::Baseline->new ($_, $self->{pvob});
473
474     push @baselines, $baseline;
475   } # for
476
477   return @baselines;
478 } # baselines
479
480 sub exists() {
481   my ($self) = @_;
482
483 =pod
484
485 =head3 exists
486
487 Return true if the stream exists - false otherwise
488
489 Paramters:
490
491 =for html <blockquote>
492
493 =over 
494
495 =item none
496
497 =back
498
499 =for html </blockquote>
500
501 Returns:
502
503 =for html <blockquote>
504
505 =over
506
507 =item boolean
508
509 =back
510
511 =for html </blockquote>
512
513 =cut
514
515   my ($status, @output) = $Clearcase::CC->execute(
516     'lsstream ' . $self->{name} . '@' . $self->{pvob}->name
517   );
518
519   return !$status;
520 } # exists
521
522 1;
523
524 =head1 DEPENDENCIES
525
526 =head2 ClearSCM Perl Modules
527
528 =for html <p><a href="/php/scm_man.php?file=lib/Clearcase.pm">Clearcase</a></p>
529
530 =for html <p><a href="/php/scm_man.php?file=lib/Clearcase/UCM/Baseline.pm">Clearcase::UCM::Baseline</a></p>
531 =for html <p><a href="/php/scm_man.php?file=lib/Clearcase/UCM/Project.pm">Clearcase::UCM::Project</a></p>
532
533 =head1 INCOMPATABILITIES
534
535 None
536
537 =head1 BUGS AND LIMITATIONS
538
539 There are no known bugs in this module.
540
541 Please report problems to Andrew DeFaria <Andrew@ClearSCM.com>.
542
543 =head1 LICENSE AND COPYRIGHT
544
545 Copyright (c) 2007, ClearSCM, Inc. All rights reserved.
546
547 =cut