<<

NAME

Inca::Net::Client - Base client library for reading/writing Inca protocol

SYNOPSIS

  use Inca::Net::Client;
  my $client = new Inca::Net::Client( $uri, %credentials );
  $client->connect();
  my $ping_stmt = new Inca::Net::Protocol::Statement( 
    cmd => "PING",
    data => "ME"
  );
  $client->writeStatement( $ping_stmt );
  # or 
  $client->writeStatement( "PING", "ME" );
  $response = $client->readStatement();
  print $response->getCmd(), $response->getData();
  # or 
  my ($cmd, $data) = $client->readStatement();
  # or
  my $success = $client->hasReadStatement( "OK", "ME" );
  # or
  my $success = $client->writeAndReadStatement( "PING", "ME", "OK", "ME" );
  $client->close();

DESCRIPTION

A base class for creating Inca clients. Provides convenience methods for connecting to an Inca server and reading/writing the Inca protocol.

CLASS METHODS

new( $uri, %Options )

Class constructor which returns a new Inca::Net::Client object. The constructor must be called with a $uri to the server. The constructor may be called with any of the following attributes.

Arguments:

uri

A string containing the uri of the Inca server in the format of <scheme>://<path> where

scheme

The type of URI being represented by the string (either file, inca, or incas)

path

The location of the URI being represented (e.g., localhost:7070)

args

A list of follow on arguments for the stream type (e.g., cert, key, and trusted certificate directory for the SSL connection).

close( )

Close the client connection to the server.

hasReadStatement( $cmdRegex, $dataRegex )

Read an Inca statement from the open stream and compare it to the expected command and data regular expressions.

Arguments:

cmdRegex

The expected command regular expression that should be read from the stream.

dataRegex

The expected data regular expression that should be read from the stream.

Returns:

Returns true if the read statement matches the expected statement; false otherwise.

readStatement( )

Read an Inca statement from the open stream.

Returns:

If called from a scalar context, returns an object of Inca::Net::Protocol::Statement which contains the content of the read Inca statement. If called from an array context, will return an array of 2 elements: (command, data).

writeAndReadStatement( $cmd, $data, $expectedCmd, $expectedData )

Writes an Inca statement to the open stream, wait for a response, and compare the response to the expected command and data.

Arguments:

cmd

A string containing the command to write to the open stream.

data

A string containing the data to write to the open stream.

expectedCmd

The expected command that should be read from the stream.

expectedData

The expected data that should be read from the stream.

writeError( $msg )

Writes an Inca error message statement to the open stream.

Arguments:

msg

A string containing the error message to pass back to the server.

writeStatement( $stmt ) or writeStatement( $cmd, $data )

Writes an Inca statement to the open stream.

Arguments:

stmt

An object of Inca::Net::Protocol::Statement that should be written to the open stream.

cmd

A string containing the command to write to the open stream.

data

A string containing the data to write to the open stream.

AUTHOR

Shava Smallen <ssmallen@sdsc.edu>

CAVEATS/WARNINGS

No known problems.

<<