#! /usr/local/bin/perl -w # Client program for COPE object implementation examples # Assumes it will get the stringified IOR for the server's Supervisor # object on the command line use lib '.'; use COPE::CORBA::ORB; use Copex::Supervisor; use Copex::Persistent; use Copex::Temp; use Copex::OneServant; use Copex::OnDemand; use Experimental::Exception; my $orb = CORBA::ORB_init(); $ARGV[0] or die "Usage: $0 "; my $super = $orb->string_to_object($ARGV[0]); $super = Copex::Supervisor->_narrow($super); # Get the list of persistent objects my $persist_list = $super->get_persistent(); my $yellow_obj; print "Persistent Objects:\n"; foreach (@$persist_list) { my $pprops = $_->GetProps(); if ($pprops->{hue} == Copex::colour::Yellow) { $yellow_obj = $_; print "The yellow object is a ", $pprops->{shape}, "\n"; } } print "\nNow make a few Temp objects and list them\n"; $yellow_obj->new_temp({size => ($$ * 31) % 101, name => "fred"}); $yellow_obj->new_temp({size => ($$ * 7) % 101, name => "george"}); # The server will take exception to this one... try { $yellow_obj->new_temp({size => 5000, name => "mothra"}); } catch 'Copex::InvalidInput' => sub {print "new_temp {size => 5000, name => 'mothra'} failed:\n", $_[0]->{message}, "\n";} ; my $temp_list = $super->get_temp(); foreach(@$temp_list) { my $tprops = $_->GetProps(); printf "%s\t%d\n", $tprops->{name}, $tprops->{size}; } print "\nNow for some OneServant objects\n"; $super->new_one("john"); $super->new_one("paul"); $super->new_one("gregory"); $super->new_one("clementine"); my $one_list = $super->get_one(); print join(', ', map {$_->GetId()} @$one_list), "\n"; print "\nAnd now the OnDemand objects\n"; my $loaded = $super->get_loaded(); my $unloaded = $super->get_unloaded(); printf "At the start, %d objects are loaded and %d are not\n", scalar(@$loaded), scalar(@$unloaded); my $last = scalar(@$loaded); if ($last) { printf("GetId on loaded object $last returns %s\n", $loaded->[$last - 1]->GetId()); } if (@$unloaded) { printf "GetId on unloaded object 1 returns %s\n", $unloaded->[-1]->GetId(); } $loaded = $super->get_loaded(); $unloaded = $super->get_unloaded(); printf "Now %d objects are loaded and %d are not\n", scalar(@$loaded), scalar(@$unloaded);