From: erickson Date: Wed, 10 May 2006 13:43:26 +0000 (+0000) Subject: the code in these examples is way too old. best to delete. X-Git-Tag: osrf_rel_2_0_1~1159 X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=a705b52dcba7ad5935214825e70aeaaee961452c;p=OpenSRF.git the code in these examples is way too old. best to delete. git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@714 9efc2488-bf62-4759-914b-345cdb29e865 --- diff --git a/examples/math_shell.pl b/examples/math_shell.pl deleted file mode 100755 index b61157b..0000000 --- a/examples/math_shell.pl +++ /dev/null @@ -1,139 +0,0 @@ -#!/usr/bin/perl -w -use strict;use warnings; -use OpenILS::System; -use OpenILS::Utils::Config; -use OpenILS::DomainObject::oilsMethod; -use OpenILS::DomainObject::oilsPrimitive; -use OpenILS::EX qw/:try/; -$| = 1; - -# ---------------------------------------------------------------------------------------- -# Simple math shell where you can test the transport system. -# Enter simple, binary equations ony using +, -, *, and / -# Example: # 1+1 -# Usage: % perl math_shell.pl -# ---------------------------------------------------------------------------------------- - -# load the config -my $config = OpenILS::Utils::Config->current; - -# connect to the transport (jabber) server -OpenILS::System->bootstrap_client(); - -# build the AppSession object. -my $session = OpenILS::AppSession->create( - "math", username => 'math_bench', secret => '12345' ); - -# launch the shell -print "type 'exit' or 'quit' to leave the shell\n"; -print "# "; -while( my $request = <> ) { - - chomp $request ; - - # exit loop if user enters 'exit' or 'quit' - if( $request =~ /exit/i or $request =~ /quit/i ) { last; } - - # figure out what the user entered - my( $a, $mname, $b ) = parse_request( $request ); - - if( $a =~ /error/ ) { - print "Parse Error. Try again. \nExample # 1+1\n"; - next; - } - - - try { - - # Connect to the MATH server - if( ! ($session->connect()) ) { die "Connect timed out\n"; } - - } catch OpenILS::EX with { - my $e = shift; - die "* * Connection Failed with:\n$e"; - }; - - my $method = OpenILS::DomainObject::oilsMethod->new( method => $mname ); - $method->params( $a, $b ); - - my $req; - my $resp; - - try { - $req = $session->request( $method ); - - # we know that this request only has a single reply - # if your expecting a 'stream' of results, you can - # do: while( $resp = $req->recv( timeout => 10 ) ) {} - $resp = $req->recv( timeout => 10 ); - - } catch OpenILS::EX with { - - # Any transport layer or server problems will launch an exception - my $e = shift; - die "ERROR Receiving\n $e"; - - } catch Error with { - - # something just died somethere - my $e = shift; - die "Caught unknown error: $e"; - }; - - if ( $resp ) { - # ---------------------------------------------------------------------------------------- - # $resp is an OpenILS::DomainObject::oilsResponse object. $resp->content() returns whatever - # data the object has. If the server returns an exception that we're meant to see, then - # the data will be an exception object. In this case, barring any exception, we know that - # the data is an OpenILS::DomainObject::oilsScalar object which has a value() method - # that returns a perl scalar. For us, that scalar is just a number. - # ---------------------------------------------------------------------------------------- - - if( UNIVERSAL::isa( $resp, "OpenILS::EX" ) ) { - throw $resp; - } - - my $ret = $resp->content(); - print $ret->value(); - } - - $req->finish(); - - print "\n# "; - -} - -# disconnect from the MATH server -$session->kill_me(); -exit; - -# ------------------------------------------------------------------------------------ -# parse the user input string -# returns a list of the form (first param, operation, second param) -# These operations are what the MATH server recognizes as method names -# ------------------------------------------------------------------------------------ -sub parse_request { - my $string = shift; - my $op; - my @ops; - - while( 1 ) { - - @ops = split( /\+/, $string ); - if( @ops > 1 ) { $op = "add"; last; } - - @ops = split( /\-/, $string ); - if( @ops > 1 ) { $op = "sub"; last; } - - @ops = split( /\*/, $string ); - if( @ops > 1 ) { $op = "mult", last; } - - @ops = split( /\//, $string ); - if( @ops > 1 ) { $op = "div"; last; } - - return ("error"); - } - - return ($ops[0], $op, $ops[1]); -} - diff --git a/examples/math_simple.pl b/examples/math_simple.pl deleted file mode 100755 index 73b015e..0000000 --- a/examples/math_simple.pl +++ /dev/null @@ -1,86 +0,0 @@ -#!/usr/bin/perl -w -use strict;use warnings; -use OpenILS::System; -use OpenILS::Utils::Config; -use OpenILS::DomainObject::oilsMethod; -use OpenILS::DomainObject::oilsPrimitive; -use OpenILS::EX qw/:try/; -$| = 1; - - -# ---------------------------------------------------------------------------------------- -# This script makes a single query, 1 + 2, to the the MATH test app and prints the result -# Usage: % perl math_simple.pl -# ---------------------------------------------------------------------------------------- - - -# connect to the transport (jabber) server -OpenILS::System->bootstrap_client(); - -# build the AppSession object. -my $session = OpenILS::AppSession->create( - "math", username => 'math_bench', secret => '12345' ); - -try { - - # Connect to the MATH server - if( ! ($session->connect()) ) { die "Connect timed out\n"; } - -} catch OpenILS::EX with { - my $e = shift; - die "* * Connection Failed with:\n$e"; -}; - -my $method = OpenILS::DomainObject::oilsMethod->new( method => "add" ); -$method->params( 1, 2 ); - -my $req; -my $resp; - -try { - $req = $session->request( $method ); - - # we know that this request only has a single reply - # if your expecting a 'stream' of results, you can - # do: while( $resp = $req->recv( timeout => 10 ) ) {} - $resp = $req->recv( timeout => 10 ); - -} catch OpenILS::EX with { - - # Any transport layer or server problems will launch an exception - my $e = shift; - die "ERROR Receiving\n $e"; - -} catch Error with { - - # something just died somethere - my $e = shift; - die "Caught unknown error: $e"; -}; - -if ( $resp ) { - # ---------------------------------------------------------------------------------------- - # $resp is an OpenILS::DomainObject::oilsResponse object. $resp->content() returns whatever - # data the object has. If the server returns an exception that we're meant to see, then - # the data will be an exception object. In this case, barring any exception, we know that - # the data is an OpenILS::DomainObject::oilsScalar object which has a value() method - # that returns a perl scalar. For us, that scalar is just a number. - # ---------------------------------------------------------------------------------------- - - if( UNIVERSAL::isa( $resp, "OpenILS::EX" ) ) { - throw $resp; - } - - my $ret = $resp->content(); - print "Should print 3 => " . $ret->value() . "\n"; - -} else { - die "No Response from Server!\n"; -} - -$req->finish(); - -# disconnect from the MATH server -$session->kill_me(); -exit; -