POE-Component-Client-opentick
view release on metacpan or search on metacpan
lib/POE/Component/Client/opentick/Protocol.pm view on Meta::CPAN
package POE::Component::Client::opentick::Protocol;
#
# opentick.com POE client
#
# Protocol handling (only operates on data, no socket handling)
#
# infi/2008
#
# $Id: Protocol.pm 56 2009-01-08 16:51:14Z infidel $
#
# See docs/implementation-notes.txt for a detailed explanation of how
# this module works.
#
# Full user POD documentation after __END__
#
use strict;
use warnings;
use Carp qw( croak );
use Data::Dumper;
use POE;
# Ours.
use POE::Component::Client::opentick::Constants;
use POE::Component::Client::opentick::Util;
use POE::Component::Client::opentick::Output;
use POE::Component::Client::opentick::Error;
use POE::Component::Client::opentick::ProtocolMsg;
###
### Variables
###
use vars qw( $VERSION $TRUE $FALSE $KEEP $DELETE $poe_kernel );
($VERSION) = q$Revision: 56 $ =~ /(\d+)/;
*TRUE = \1;
*FALSE = \0;
*KEEP = \0;
*DELETE = \1;
# These arguments are for this object; pass the rest on.
my %valid_args = (
alias => $KEEP,
debug => $KEEP,
rawdata => $KEEP,
);
my $state_base = 'POE::Component::Client::opentick::ProtocolMsg';
########################################################################
### Public methods ###
########################################################################
sub new
{
my( $class, @args ) = @_;
croak( "$class requires an even number of parameters" ) if( @args & 1 );
my $self = {
# User prefs
alias => OTDefault( 'alias' ),
rawdata => $FALSE, # user prefers to receive raw response
# data instead of ::Record objects
debug => $FALSE,
# Protocol settings
heartbeat => OTDefault( 'heartbeat' ), # beat delay in secs
request_timeout => OTDefault( 'request_timeout' ), # request timeout
# Protocol state
requests => {}, # outstanding requests keyed on ID
# stamp = timestamp
# cmd_id = command ID
# respcount = response count
# cancel_rqid = cancel request ID
# sender = sender POE ID
partial_data => '', # stash incomplete <Message>s
# Object containers
state_obj => undef, # object reference for ProtocolMsg
# handlers => {}, # loaded ProtocolMsg subclasses
# Statistical information
messages_sent => 0,
messages_recv => 0,
records_recv => 0,
errors_recv => 0,
};
bless( $self, $class );
my @leftovers = $self->initialize( @args );
# Create a protocol state handler object with the leftover args
$self->{state_obj} =
POE::Component::Client::opentick::ProtocolMsg->new( @leftovers );
# $self->_load_handler_subclasses();
return( $self );
}
# Initialize this object instance
sub initialize
{
my( $self, %args ) = @_;
# Keep our things...
for( keys( %args ) )
{
# grab them regardless
$self->{lc $_} = $args{$_} if( exists( $valid_args{lc $_} ) );
# delete them if true
delete( $args{ $_ } ) if( $valid_args{lc $_} );
}
# ... return the rest.
return( %args );
}
# Construct a packet, register the request, and put the data on the wire
# XXX: Should we throttle outstanding requests here?
sub prepare_packet
{
( run in 1.745 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )