#! /usr/bin/perl -w
#
# Sample CORBA client -- Perl version
#
# Roland Mas <99.roland.mas@gna.org>

use strict ;
use diagnostics ;

use vars qw/ $orb $ior $f $p $i / ;

use Error qw(:try) ;
use CORBA::ORBit ;

$orb = CORBA::ORB_init("orbit-local-orb");
$orb->load_idl_file("sample.idl");

open IOR, "factory.ior"
    or die $! ;
$ior = <IOR> ;
close IOR ;
$f = $orb->string_to_object($ior) ;

open IOR, "stack.ior"
    or die $! ;
$ior = <IOR> ;
close IOR ;
$p = $orb->string_to_object($ior) ;

$i = $f->new_sample (1, "Bla") ;
print $i->_get_int (), "\n" ;
$i->_set_int (17) ;
print $i->_get_int (), "\n" ;
$i->incr_int () ;
print $i->_get_int (), "\n" ;

print $i->_get_str (), "\n" ;
try {
    $i->_set_str ("bla") ;	# We know this will fail
} otherwise {
    print "Attribute str readonly\n" ;
}; 

$i->change_str ("1234567890") ;
print $i->_get_str (), "\n" ;
try {
    $i->change_str ("1234567890123456789012345") ; # We know this will fail
} catch Module_1::Sample_exception with {
    print "String too long\n" ;
} ;
print $i->_get_str (), "\n" ;
print $i->str_length (), "\n" ;

$p->push (1) ;
$p->push (2) ;
$p->push (3) ;
$p->push (4) ;
$p->push (5) ;
$p->push (6) ;

try {
    while (1) {
	print "Depth = ", $p->_get_depth (), ", pop = ", $p->pop (), "\n" ;
    }
} catch Module_1::Sample_exception with {
    print "Nothing left.\n" ;
} ;
