#!/usr/local/bin/perl

## This is an example of how to set the child process into a view
## and control it. Note that although this will work on both UNIX
## and Windows, it will give errors on Windows because that's
## what the CC developers chose to do for some reason.

use ClearCase::Argv qw(ctsystem ctqx);

## Setting a view requires that you be in IPC::ClearTool mode.
ClearCase::Argv->ipc_cleartool;

# Print out each command before executing it (like sh -x).
ClearCase::Argv->dbglevel(1);

my $ct = ClearCase::Argv->new;
$ct->autochomp;

# Get a list of the local views.
my @views = $ct->argv('lsview -s')->qx;

print "\n*Show that we can set the coprocess into a view and keep it there.\n";
$ct->argv('pwv -s')->system;
$ct->argv('setview', [], $views[0])->system;
$ct->argv('pwv -s')->system;
# ... from here you could cd into a vob and do whatever you want.

print "\n*Similar to above but using the functional interface ...\n";
ClearCase::Argv->dbglevel(0);
for my $view (reverse @views) {
    ctsystem('setview', $view);
    my $cwv = ctqx('pwv -s');
    chomp $cwv;
    print "Setting cleartool process into view '$cwv'\n";
}
