Business-OCV
view release on metacpan or search on metacpan
# connect and disconnect to the OCV server at will. For a given client
# (account), some of the required information will be constant (e.g.
# account number, client id). This module is intended to be used as one
# OCV object instance per client/acount: it "wraps" the protocol such
# that the client ID, account number (and transaction ID as required) are
# automatically supplied for each request and the application only need
# supply the 'per-transaction' date (e.g. card details, amount).
#
# The OCV protocol is STREAM based (i.e. TCP/IP). Thus this client
# conceivably may not send nor receive messages atomically - messages
# may be fragmented across reads (and writes). At present, this is not
# accounted for, and will result in an error.
# TODO There is some guarantee regarding minimum block sizes, around 8k
# as I recall. I need to check this. The implications are that under
# high load (when buffers back up), we may start getting incomplete
# messages.
#
# Future Work:
# - determine message fragmentation issue
# - split out networking into a separate object, so objects for
# multiple clients/accounts can share connections to the server
#
# THIS OCV MODULE
#
# This module provides an object-oriented means of transacting with the
# OCV server. An 'OCV' object is used to converse with the server, it
# provides a method corresponding to each of the OCV message types.
# Transaction results (RESPONSEs) are returned as OCV::Message objects.
# The OCV::Message object is simply a blessed array reference, so you can
my $self = shift;
my $buf;
while ($self->{'sel'}->can_read(0) and $self->{'io'}->sysread($buf, 8192))
{
$self->logdebug("flush: discarding [$buf]");
}
"\000"; # true, but "silent" (mainly for the ocv command line util)
}
sub _send
# assumes data is not fragmented
{
my $self = shift;
$@ = "send: not connected", return undef unless $self->{'io'}->connected;
$@ = "send: timeout", return undef
unless $self->{'sel'}->can_write($self->{'timeout'});
# see logdebug() re. logging of sensitive data
$self->logdebug(sprintf("send: %3d [%s]", length($_[0]), $_[0]));
chomp ($@), $@ = "send: syswrite: $@", return undef if $@;
$@ = "send: error: $!", return undef unless defined($r);
return $r;
}
sub _recv
# arguments (buf, len): reads len bytes into buf
# assumes data is not fragmented - i.e. if we ask for N bytes, we get N bytes,
# or an error
# - I don't do a dual-read (i.e. read header, extract message length, read
# the rest of the message). I couldn't see the point: once the message
# exchange sequence is messed up, I can no longer trust it.
{
my $self = shift;
$@ = "recv: not connected", return undef unless $self->{'io'}->connected;
$@ = "recv: timeout", return undef
( run in 2.150 seconds using v1.01-cache-2.11-cpan-b16cb0d3907 )