NAME

POEx::Role::TCPClient - A Moose Role that provides TCPClient behavior

VERSION

version 0.100170

REQUIRES

METHODS

handle_inbound_data($data, WheelID $id) is Event

This required method will be passed the data received, and from which wheel it came.

ATTRIBUTES

socket_factories traits: ['Hash'], isa: HashRef[Object]

The POE::Wheel::SocketFactory objects created in connect are stored here and managed via the following provides:

handles     =>
{
    'get_socket_factory'       => 'get',
    'set_socket_factory'       => 'set',
    'delete_socket_factory'    => 'delete',
    'has_socket_factories'     => 'count',
    'has_socket_factory'       => 'exists',
}

wheels traits: ['Hash'], isa: HashRef, clearer: clear_wheels

When connections are finished, a POE::Wheel::ReadWrite object is created and stored in this attribute, keyed by WheelID. Wheels may be accessed via the following provided methods.

handles    =>
{
    'get_wheel'    => 'get',
    'set_wheel'    => 'set',
    'delete_wheel' => 'delete',
    'count_wheels' => 'count',
    'has_wheel'    => 'exists',
}

last_wheel is: rw, isa: WheelID

This holds the last ID created from the handle_on_connect method. Handy if the protocol requires client initiation.

filter is: rw, isa: Filter

This stores the filter that is used when constructing wheels. It will be cloned for each connection completed.

connection_tags metaclass: Collection::Hash, is: ro, isa: HashRef[Ref]

This stores any arbitrary user data passed to connect keyed by the socket factory ID. Handy to match up multiple connects for composers.

METHODS

connect(Str :$remote_address, Int :$remote_port, Ref :$tag?) is Event

connect is used to initiate a connection to a remote source. It accepts two named arguments that both required, remote_address and remote_port. They are passed directly to SocketFactory. If tag is provided, it will be stored in connection_tags and keyed by the socket factory's ID.

handle_on_connect(GlobRef $socket, Str $address, Int $port, WheelID $id) is Event

handle_on_connect is the SuccessEvent of the SocketFactory instantiated in _start.

handle_connect_error(Str $action, Int $code, Str $message, WheelID $id) is Event

handle_connect_error is the FailureEvent of the SocketFactory

handle_socket_error(Str $action, Int $code, Str $message, WheelID $id) is Event

handle_socket_error is the ErrorEvent of each POE::Wheel::ReadWrite instantiated.

shutdown() is Event

shutdown unequivically terminates the TCPClient by clearing all wheels and aliases, forcing POE to garbage collect the session.

DESCRIPTION

POEx::Role::TCPClient bundles up the lower level SocketFactory/ReadWrite combination of wheels into a simple Moose::Role. It builds upon other POEx modules such as POEx::Role::SessionInstantiation and POEx::Types.

The events for SocketFactory and for each ReadWrite instantiated are methods that can be advised in any way deemed fit. Advising these methods is actually encouraged and can simplify code for the consumer.

The only method that must be provided by the consuming class is handle_inbound_data.

The connect event must be invoked to initiate a connection.

AUTHOR

Nicholas Perez <nperez@cpan.org>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2010 by Nicholas Perez.

This is free software, licensed under:

The GNU General Public License, Version 3, June 2007