NAME
POEx::Role::TCPClient - A Moose Role that provides TCPClient behavior
VERSION
version 0.092280
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.
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.
ATTRIBUTES
socket_factories metaclass: Collection::Hash, isa: HashRef[Object]
The POE::Wheel::SocketFactory objects created in connect are stored here and managed via the following provides:
provides =>
{
get => 'get_socket_factory',
set => 'set_socket_factory',
delete => 'delete_socket_factory',
count => 'has_socket_factories',
exists => 'has_socket_factory',
}
wheels metaclass: Collection::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. See MooseX::AttributeHelpers::Collection::Hash for more details.
provides =>
{
get => 'get_wheel',
set => 'set_wheel',
delete => 'delete_wheel',
count => 'has_wheels',
}
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.
provides =>
{
get => 'get_connection_tag',
set => 'set_connection_tag',
delete => 'delete_connection_tag',
count => 'has_connection_tags',
exists => 'has_connection_tag',
}
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.
AUTHOR
Nicholas Perez <nperez@cpan.org>
COPYRIGHT AND LICENSE
This software is Copyright (c) 2009 by Nicholas Perez.
This is free software, licensed under:
The GNU General Public License, Version 3, June 2007