Various changes and additions for UCM and testing things
[clearscm.git] / lib / Clearcase / UCM / Component.pm
1 =pod
2
3 =head1 NAME $RCSfile: Component.pm,v $
4
5 Object oriented interface to UCM Component
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 Components.
32
33   my $stream = new Clearcase::UCM::Component($name, $pvob);
34
35 =head1 DESCRIPTION
36
37 This module implements a UCM Component object
38
39 =head1 ROUTINES
40
41 The following routines are exported:
42
43 =cut
44
45 package Clearcase::UCM::Component;
46
47 use strict;
48 use warnings;
49
50 use Carp;
51
52 sub new ($$) {
53   my ($class, $name, $pvob) = @_;
54
55 =pod
56
57 =head2 new
58
59 Construct a new Clearcase Component object.
60
61 Parameters:
62
63 =for html <blockquote>
64
65 =over
66
67 =item name
68
69 Name of Component
70
71 =item pvob
72
73 Associated pvob
74
75 =back
76
77 =for html </blockquote>
78
79 Returns:
80
81 =for html <blockquote>
82
83 =over
84
85 =item Clearcase Component object
86
87 =back
88
89 =for html </blockquote>
90
91 =cut
92
93   $class = bless {
94     name => $name,
95     pvob => $pvob,
96   }, $class; # bless
97     
98   return $class; 
99 } # new
100   
101 sub name () {
102   my ($self) = @_;
103     
104 =pod
105
106 =head2 name
107
108 Returns the name of the component
109
110 Parameters:
111
112 =for html <blockquote>
113
114 =over
115
116 =item none
117
118 =back
119
120 =for html </blockquote>
121
122 Returns:
123
124 =for html <blockquote>
125
126 =over
127
128 =item name
129
130 =back
131
132 =for html </blockquote>
133
134 =cut
135
136   return $self->{name};
137 } # name
138
139 sub pvob () {
140   my ($self) = @_;
141   
142 =pod
143
144 =head2 pvob
145
146 Returns the pvob of the component
147
148 Parameters:
149
150 =for html <blockquote>
151
152 =over
153
154 =item none
155
156 =back
157
158 =for html </blockquote>
159
160 Returns:
161
162 =for html <blockquote>
163
164 =over
165
166 =item pvob
167
168 =back
169
170 =for html </blockquote>
171
172 =cut
173
174   return $self->{pvob};
175 } # pvob
176   
177 sub create (;$$) {
178   my ($self, $root, $comment) = @_;
179
180 =pod
181
182 =head2 create
183
184 Creates a new UCM Component Object
185
186 Parameters:
187
188 =for html <blockquote>
189
190 =over
191
192 =item none
193
194 =back
195
196 =for html </blockquote>
197
198 Returns:
199
200 =for html <blockquote>
201
202 =over
203
204 =item $status
205
206 Status from cleartool
207
208 =item @output
209
210 Ouput from cleartool
211
212 =back
213
214 =for html </blockquote>
215
216 =cut
217
218   return (0, ()) if $self->exists;
219   
220   $comment = Clearcase::_setComment $comment;
221
222   my $rootOpt;
223
224   if ($root) {
225     if (-d $root) {
226       $self->{root} = $root;
227
228       $rootOpt = "-root $root";
229     } else {
230       carp "Root $root not found";
231     } # if
232   } else {
233     $self->{root} = undef;
234
235     $rootOpt = '-nroot';
236   } # if
237
238   return $Clearcase::CC->execute(
239     "mkcomp $comment $rootOpt " . $self->{name} . '@' . $self->{pvob}->tag
240   );
241 } # create
242
243 sub remove () {
244   my ($self) = @_;
245
246 =pod
247
248 =head2 remove
249
250 Removes UCM Component
251
252 Parameters:
253
254 =for html <blockquote>
255
256 =over
257
258 =back
259
260 =for html </blockquote>
261
262 Returns:
263
264 =for html <blockquote>
265
266 =over
267
268 =item $status
269
270 Status from cleartool
271
272 =item @output
273
274 Ouput from cleartool
275
276 =back
277
278 =for html </blockquote>
279
280 =cut
281
282   return $Clearcase::CC->execute 
283     ('rmcomp -f ' . $self->{name} . '@' . $self->{pvob}->name);
284 } # remove
285
286 sub exists() {
287   my ($self) = @_;
288
289 =pod
290
291 =head3 exists
292
293 Returns true if the component exists - false otherwise.
294
295 Parameters:
296
297 =for html <blockquote>
298
299 =over
300
301 =item none
302
303 =back
304
305 =for html </blockquote>
306
307 Returns:
308
309 =for html <blockquote>
310
311 =over
312
313 =item boolean
314
315 =back
316
317 =for html </blockquote>
318
319 =cut
320
321   my ($status, @output) = $Clearcase::CC->execute(
322     'lscomp ' . $self->{name} . '@' . $self->{pvob}->name
323   );
324
325   return !$status;
326 } # exists
327
328 1;
329
330 =head1 DEPENDENCIES
331
332 =head2 ClearSCM Perl Modules
333
334 =for html <p><a href="/php/scm_man.php?file=lib/Clearcase.pm">Clearcase</a></p>
335
336 =for html <p><a href="/php/scm_man.php?file=lib/Clearcase/UCM/Baseline.pm">Clearcase::UCM::Baseline</a></p>
337 =for html <p><a href="/php/scm_man.php?file=lib/Clearcase/UCM/Project.pm">Clearcase::UCM::Project</a></p>
338
339 =head1 INCOMPATABILITIES
340
341 None
342
343 =head1 BUGS AND LIMITATIONS
344
345 There are no known bugs in this module.
346
347 Please report problems to Andrew DeFaria <Andrew@ClearSCM.com>.
348
349 =head1 LICENSE AND COPYRIGHT
350
351 Copyright (c) 2007, ClearSCM, Inc. All rights reserved.
352
353 =cut