26661a5bc0a3c2492fa60b0324461fea9eea997d
[clearscm.git] / lib / Clearcase / UCM / Folder.pm
1 =pod
2
3 =head1 NAME $RCSfile: Folder.pm,v $
4
5 Object oriented interface to UCM Folders
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 Folders.
32
33   my $folder = new Clearcase::UCM::Folder ($name, $pvob);
34
35 =head1 DESCRIPTION
36
37 This module implements a UCM Folder object
38
39 =head1 ROUTINES
40
41 The following routines are exported:
42
43 =cut
44
45 package Clearcase::UCM::Folder;
46
47 use strict;
48 use warnings;
49
50 sub new ($$;$$) {
51   my ($class, $name, $pvob, $parent, $comment) = @_;
52
53 =pod
54
55 =head2 new
56
57 Construct a new Clearcase Folder object.
58
59 Parameters:
60
61 =for html <blockquote>
62
63 =over
64
65 =item folder
66
67 Name of folder
68
69 =back
70
71 =for html </blockquote>
72
73 Returns:
74
75 =for html <blockquote>
76
77 =over
78
79 =item Clearcase Folder object
80
81 =back
82
83 =for html </blockquote>
84
85 =cut
86
87   $class = bless {
88     name   => $name,
89     pvob   => $pvob,
90     parent => $parent || 'RootFolder',
91   }, $class; # bless
92    
93   $comment = Clearcase::_setComment ($comment);
94
95   my ($status, @output) = $Clearcase::CC->execute (
96     "mkfolder $comment -in " . $class->{parent} . ' ' . $name . '@' . $pvob->tag
97   );
98
99   return $class->updateFolderInfo;
100 } # new
101   
102 sub name () {
103   my ($self) = @_;
104     
105 =pod
106
107 =head2 name
108
109 Returns the name of the folder
110
111 Parameters:
112
113 =for html <blockquote>
114
115 =over
116
117 =item none
118
119 =back
120
121 =for html </blockquote>
122
123 Returns:
124
125 =for html <blockquote>
126
127 =over
128
129 =item folder's name
130
131 =back
132
133 =for html </blockquote>
134
135 =cut
136
137   return $self->{name};
138 } # name
139
140 sub owner () {
141   my ($self) = @_;
142     
143 =pod
144
145 =head2 owner
146
147 Returns the owner of the folder
148
149 Parameters:
150
151 =for html <blockquote>
152
153 =over
154
155 =item none
156
157 =back
158
159 =for html </blockquote>
160
161 Returns:
162
163 =for html <blockquote>
164
165 =over
166
167 =item folder's owner
168
169 =back
170
171 =for html </blockquote>
172
173 =cut
174
175   return $self->{owner};
176 } # owner
177
178 sub group () {
179   my ($self) = @_;
180     
181 =pod
182
183 =head2 group
184
185 Returns the group of the folder
186
187 Parameters:
188
189 =for html <blockquote>
190
191 =over
192
193 =item none
194
195 =back
196
197 =for html </blockquote>
198
199 Returns:
200
201 =for html <blockquote>
202
203 =over
204
205 =item folder's group
206
207 =back
208
209 =for html </blockquote>
210
211 =cut
212
213   return $self->{group};
214 } # group
215
216 sub pvob () {
217   my ($self) = @_;
218     
219 =pod
220
221 =head2 pvob
222
223 Returns the pvob of the folder
224
225 Parameters:
226
227 =for html <blockquote>
228
229 =over
230
231 =item none
232
233 =back
234
235 =for html </blockquote>
236
237 Returns:
238
239 =for html <blockquote>
240
241 =over
242
243 =item folder's pvob
244
245 =back
246
247 =for html </blockquote>
248
249 =cut
250
251   return $self->{pvob};
252 } # pvob
253
254 sub title () {
255   my ($self) = @_;
256     
257 =pod
258
259 =head2 title
260
261 Returns the title of the folder
262
263 Parameters:
264
265 =for html <blockquote>
266
267 =over
268
269 =item none
270
271 =back
272
273 =for html </blockquote>
274
275 Returns:
276
277 =for html <blockquote>
278
279 =over
280
281 =item folder's title
282
283 =back
284
285 =for html </blockquote>
286
287 =cut
288
289   return $self->{title};
290 } # title
291
292 sub create ($;$) {
293   my ($self, $name, $parentFolder) = @_;
294
295 =pod
296
297 =head2 create
298
299 Creates a new UCM Folder Object
300
301 Parameters:
302
303 =for html <blockquote>
304
305 =over
306
307 =item name
308
309 UCM Folder name
310
311 =item parentFolder
312
313 Name of parentFolder (Default: RootFolder)
314
315 =back
316
317 =for html </blockquote>
318
319 Returns:
320
321 =for html <blockquote>
322
323 =over
324
325 =item $status
326
327 Status from cleartool
328
329 =item @output
330
331 Ouput from cleartool
332
333 =back
334
335 =for html </blockquote>
336
337 =cut
338
339   # Fill in object members
340   $self->{parentFolder} = $parentFolder;
341
342   $parentFolder ||= 'RootFolder';
343
344   # Need to create the folder
345   return $Clearcase::CC->execute( 
346     "mkfolder $self->{comment} -in " . $parentFolder . '@' . $self->{pvob} .
347     ' '                   . $self->{name}
348   );
349 } # create
350
351 sub remove () {
352   my ($self) = @_;
353
354 =pod
355
356 =head2 remove
357
358 Removes UCM Folder
359
360 Parameters:
361
362 =for html <blockquote>
363
364 =over
365
366 =item name
367
368 UCM Folder name
369
370 =back
371
372 =for html </blockquote>
373
374 Returns:
375
376 =for html <blockquote>
377
378 =over
379
380 =item $status
381
382 Status from cleartool
383
384 =item @output
385
386 Output from cleartool
387
388 =back
389
390 =for html </blockquote>
391
392 =cut
393
394   return $Clearcase::CC->execute(
395     'rmfolder -f ' . $self->{name} . "\@" . $self->{pvob});
396 } # rmfolder
397
398 sub updateFolderInfo () {
399   my ($self) = @_;
400
401   my ($status, @output) = $Clearcase::CC->execute(
402     "lsfolder -long $self->{name}" . '@'. $self->{pvob}->tag);
403
404   return if $status;
405
406   for (@output) {
407     if (/owner: (.*)/) {
408       $self->{owner} = $1;
409     } elsif (/group: (.*)/) {
410       $self->{group} = $1;
411     } elsif (/title: (.*)/) {
412       $self->{title} = $1;
413     # TODO: Get containing folders and containing projects
414     } # if
415   } # for
416
417   return $self;
418 } # updateFolderInfo
419 1;
420
421 =head1 DEPENDENCIES
422
423 =head2 ClearSCM Perl Modules
424
425 =for html <p><a href="/php/scm_man.php?file=lib/Clearcase.pm">Clearcase</a></p>
426
427 =for html <p><a href="/php/scm_man.php?file=lib/Clearcase/UCM/Baseline.pm">Clearcase::UCM::Baseline</a></p>
428
429 =head1 INCOMPATABILITIES
430
431 None
432
433 =head1 BUGS AND LIMITATIONS
434
435 There are no known bugs in this module.
436
437 Please report problems to Andrew DeFaria <Andrew@ClearSCM.com>.
438
439 =head1 LICENSE AND COPYRIGHT
440
441 Copyright (c) 2007, ClearSCM, Inc. All rights reserved.
442
443 =cut