CORBA-MICO

 view release on metacpan or  search on metacpan

client  view on Meta::CPAN

#!/usr/bin/perl -w

use CORBA::MICO ids => [ 'IDL:Bank:1.0' => undef, 'IDL:BGLN:1.0' => undef ];
use Error qw(:try);

use strict;

my $orb = CORBA::ORB_init("mico-local-orb");
my ($ids,$id);
$ids = $orb->list_initial_services();
print "initial services:\n";
foreach $id (@{$ids}) {
  print "\t$id\n";
}
my $ir = $orb->resolve_initial_references("InterfaceRepository");
if( CORBA::is_nil($ir) ) {
  print "Can't connect to InterfaceRepository service\n";
  exit 1;
}

print "BGLN=", ::BGLN(), "\n";

open IOR, "account.ref";
my $ior = <IOR>;
close IOR;

my $account = $orb->string_to_object($ior);

#$account->_set_prefs ( { favorite_color => 'taupe',
#		         lottery_numbers => [ 21, 63, 83, 96 ],
#		         nickname => 'Dopey' });

#print "$$\n";
#sleep 5;
#read STDIN,$a,1;

for (my $i=0;$i<0;$i++) {
    $account->deposit( 1 );
}
my $fixed_100 = new CORBA::Fixed("+00000000000100", 0);
my $fixed_123 = new CORBA::Fixed("123000", 3);
print "100=$fixed_100\n";
print "100 as digits(16,2)=",$fixed_100->to_digits(16,2),"\n";
print "123=$fixed_123\n";
my $fixed_223 = CORBA::Fixed::add( $fixed_123, $fixed_100 );
print "223=$fixed_223\n";
print "223 as digits(16,2)=",$fixed_223->to_digits(16,2),"\n";

print "Balance is ".$account->balance."\n";
$account->deposit( $fixed_100 );
print "Balance is ".$account->balance."\n";
$account->deposit( 100 );
print "Balance is ".$account->balance."\n";
$account->deposit( 100 );
print "Balance is ".$account->balance."\n";
$account->deposit( 100 );
print "Balance is ".$account->balance."\n";
$account->deposit( 100 );
print "Balance is ".$account->balance."\n";
$account->withdraw( 240 );
print "Balance is ".$account->balance."\n";
$account->withdraw( 10 );

print "Balance is ".$account->balance."\n";

my $prefs = $account->_get_prefs;
print "Favorite color is ",$prefs->{favorite_color},"\n";
print "Lottery numbers are ",
    join(" ", @{$prefs->{lottery_numbers}}),"\n";
print "Nickname is ",$prefs->{nickname},"\n";
$account->set_pref ( [ 'pt_color', 'chartreuse', ] );
$account->set_pref ( [ 'pt_nickname', 'Grumpy', ] );

$account->_set_appearance ( [ map { [ split // ] } split /\n/, <<'FACE' ] );
  /****\  
 ;     	; 
 [ O  O ] 
 l   \ 	l 
  ; -- ;  
   ;;;;	  
FACE

for (@{$account->_get_appearance}) {
    print join("",@$_),"\n";
}

print "Favorite color is now ",$account->get_pref('pt_color')->[1],"\n";
print "As an any: favorite color is now ",
          $account->get_pref_any('pt_color')->value,
	  "(", $account->get_pref_any('pt_color')->type->kind,")","\n";
print "As an any: nickname is now ",
          $account->get_pref_any('pt_nickname')->value,
	  "(", $account->get_pref_any('pt_nickname')->type->kind,")","\n";
my $ln = $account->get_pref_any('pt_lotnum')->value;
print "As an any: lottery_numbers are now ",
	  join(" ", @{$ln}),
	  "(", $account->get_pref_any('pt_lotnum')->type->kind,")","\n";

print "2 * 1,000,000,000,0000 pennies = ", 
    $account->add ('1 000 000 000 000', '1 000 000 000 000'),
    " pennies\n";

print "Withdrawing \$100,000\n";
try {
    $account->withdraw (100_000);
} catch Bank::Account::InsufficientFunds with {
    my $e = shift;
    print STDERR "Oops. I don't have that much money\n";
    print STDERR "    (I need $e->{overdraft} more)\n";
};

my $counter = $account->counter();
print join(" ", map { $counter->next } (1..10)), "\n";

$counter->destroy();
try {
    $counter->next;
} catch CORBA::Exception with {
    print "Caught $_[0], while counting with a destroyed counter\n";
};

# DynAny
{
  my $dafact = $orb->resolve_initial_references("DynAnyFactory");

  my $da_any = $account->get_da_struct();
  print "Any kind = ", $da_any->type->kind, "\n";
  my $da = $dafact->create_dyn_any( $da_any );
  print "DynamicAny kind ", $da->type->kind, "\n";



( run in 0.851 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )